User prompt
When enscreen is up do not allow olayer to be move anymore
User prompt
Move endsceern 200 pixels up and 200 to the right
User prompt
Extend two seconds the endscreen
User prompt
Make sure menumusic is player on game load
User prompt
On press start also play dieknightdie
User prompt
Play menumusic on game load
User prompt
Play menumusic when game loads
User prompt
Play manu music when menu screen is up
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'text')' in or related to this line: 'LK.setScore(parseFloat(timeCounter.text));' Line Number: 263
User prompt
Please fix the bug: 'timeCounter is not defined' in or related to this line: 'LK.setScore(parseFloat(timeCounter.text));' Line Number: 263
User prompt
When player is dead, update lkscore with the value of the timer
User prompt
Creat an lk score but it should not be visible
User prompt
In main menu play menumusic
User prompt
Center end screen
User prompt
Make game background a little dim
User prompt
Add a blury cloud moving in the background if the nmain menu
User prompt
On the main menu shoot spears in the backround from one side to the othe
User prompt
Use tween for spears movement in main menu
User prompt
Make sure spears un menu spawn from outiade the screen area
User prompt
Please fix the bug: 'spearGraphics is not defined' in or related to this line: 'spear.x = Math.random() < 0.5 ? -spearGraphics.width : 2048 + spearGraphics.width; // Spawn from left or right outside the screen' Line Number: 168
User prompt
Spear in menu should spawn from outside the screne
User prompt
Spears in menu should have less y axis than other elements
User prompt
On the main menu have spears fly in different rando directions constantly
User prompt
When endsceen appears it should have a black background, on top of it show the gamevoer messae
User prompt
Stop time when knight life is zeor
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var FireTrigger = Container.expand(function () { var self = Container.call(this); var fireTriggerGraphics = self.attachAsset('fireTrigger', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { if (!self.fireWall) { self.fireWall = LK.getAsset('fireWall', { anchorX: 0.5, anchorY: 0.5 }); self.fireWall.width = 2048; // Set width to match screen width self.fireWall.x = 2048 / 2; // Start from the center of the screen self.fireWall.y = 2732 + self.fireWall.height; // Start from bottom off-screen self.fireWall.speedX = 0; // No horizontal movement self.fireWall.speedY = -15; // Move upwards self.fireWall.update = function () { this.x += this.speedX; this.y += this.speedY; // Add flickering effect this.alpha = Math.random() * 0.5 + 0.5; // Random alpha between 0.5 and 1 }; game.addChild(self.fireWall); // Play firewall sound when it spawns LK.getSound('firewall').play(); // Reposition the fire trigger to a random location self.x = Math.random() * 2048 * 0.8 + 2048 * 0.1; self.y = Math.random() * 2732 * 0.8 + 2732 * 0.1; } if (self.intersects(hero)) { self.fireWall = LK.getAsset('fireWall', { anchorX: 0.5, anchorY: 0.5 }); self.fireWall.width = 2048; // Set width to match screen width self.fireWall.x = 2048 / 2; // Start from the center of the screen self.fireWall.y = 2732 + self.fireWall.height; // Start from bottom off-screen self.fireWall.speedX = 0; // No horizontal movement self.fireWall.speedY = -15; // Move upwards self.fireWall.update = function () { this.x += this.speedX; this.y += this.speedY; // Add flickering effect this.alpha = Math.random() * 0.5 + 0.5; // Random alpha between 0.5 and 1 }; game.addChild(self.fireWall); // Play firewall sound when it spawns LK.getSound('firewall').play(); // Reposition the fire trigger to a random location self.x = Math.random() * 2048; self.y = Math.random() * 2732; } }; }); // Hero class representing the player character var Hero = Container.expand(function () { var self = Container.call(this); var heroGraphics = self.attachAsset('hero', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 10; // Add a shadow below the hero var shadow = self.attachAsset('heroShadow', { anchorX: 0.5, anchorY: 0.5 }); shadow.y = heroGraphics.height / 2 + 10; // Position the shadow slightly below the hero shadow.alpha = 0.5; // Make the shadow semi-transparent // Add hitbox for collision detection self.hitbox = new Container(); self.hitbox.width = heroGraphics.width * 1.2; // Increase size for better collision detection self.hitbox.height = heroGraphics.height * 1.2; // Increase size for better collision detection self.hitbox.x = -self.hitbox.width; self.hitbox.y = -self.hitbox.height; // Display the hitbox with a transparent asset var hitboxGraphics = LK.getAsset('transparentAsset', { anchorX: 0.5, anchorY: 0.5 }); hitboxGraphics.width = self.hitbox.width; hitboxGraphics.height = self.hitbox.height; self.hitbox.addChild(hitboxGraphics); self.addChild(self.hitbox); self.update = function () { // Update logic for hero, if needed }; }); var Lifebar = Container.expand(function () { var self = Container.call(this); var lifebarGraphics = self.attachAsset('lifebar', { anchorX: 0.5, anchorY: 0.5 }); // Removed life percentage text display self.update = function () { // Removed life percentage text display if (hero.health > 0) { lifebarGraphics.width = hero.health / 100 * 1500; // Update lifebar width based on health } else { lifebarGraphics.width = 0; // Ensure lifebar does not grow after emptying } }; }); var Spear = Container.expand(function () { var self = Container.call(this); var spearGraphics = self.attachAsset('spear', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 20; self.update = function () { self.y += self.speed; }; }); var SpearTrigger = Container.expand(function () { var self = Container.call(this); var spearTriggerGraphics = self.attachAsset('spearTrigger', { anchorX: 0.5, anchorY: 0.5 }); }); var StartScreen = Container.expand(function () { var self = Container.call(this); var gameTitle = self.attachAsset('gamename', { anchorX: 0.5, anchorY: 0.5 }); var startButton = self.attachAsset('startButton', { anchorX: 0.5, anchorY: 0.5 }); gameTitle.x = 2048 / 2; gameTitle.y = 2732 / 2 - 500; // Move the game title 500 pixels up // Add a tween to animate the game title function animateTitle() { tween(gameTitle, { y: gameTitle.y - 20 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(gameTitle, { y: gameTitle.y + 20 }, { duration: 1000, easing: tween.easeInOut, onFinish: animateTitle // Loop the animation }); } }); } animateTitle(); // Removed stretching of the game title image startButton.x = 2048 / 2; // Center the start button horizontally startButton.y = 2732 - 500; // Move the start button 400 pixels up from the bottom of the screen // Add a tilting effect to the start button function animateButton() { tween(startButton, { rotation: 0.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(startButton, { rotation: -0.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: animateButton // Loop the tilting effect }); } }); } animateButton(); startButton.down = function (x, y, obj) { self.destroy(); initGame(); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var startScreen = game.addChild(new StartScreen()); // Function to create a screen shake effect function shakeScreen() { var shakeIntensity = 10; var shakeDuration = 500; // in milliseconds var elapsedTime = 0; var originalX = game.x; var originalY = game.y; var shakeInterval = LK.setInterval(function () { if (elapsedTime < shakeDuration) { game.x = originalX + (Math.random() - 0.5) * shakeIntensity; game.y = originalY + (Math.random() - 0.5) * shakeIntensity; elapsedTime += 16; // approximately 60 FPS } else { game.x = originalX; game.y = originalY; LK.clearInterval(shakeInterval); } }, 16); } // Initialize game variables var hero; var spearTrigger; var fireTrigger; var spearCount = 0; // Declare scoreText in the global scope var scoreText; var currentLevel = 1; // Initialize current level // Function to initialize game elements function initGame() { // Play game music on game start LK.playMusic('Gamemusic'); // Create and position the time counter timeCounter = new Text2("0", { size: 210, // 70% of the original size fill: 0xFFFFFF }); timeCounter.anchor.set(0.5, 1); // Sets anchor to the center of the bottom edge of the text. LK.gui.bottom.addChild(timeCounter); // Add the time counter to the GUI overlay at the bottom of the screen. // Update the time counter every second var startTime = Date.now(); var timeInterval = LK.setInterval(function () { var elapsedTime = (Date.now() - startTime) / 1000; timeCounter.setText(elapsedTime.toFixed(3)); // Stop the time counter if hero's health is zero if (hero.health <= 0) { LK.clearInterval(timeInterval); } }, 1); // Add background image var background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5 }); background.x = 2048 / 2; background.y = 2732 / 2; game.addChild(background); hero = game.addChild(new Hero()); hero.health = 100; // Initialize hero health as a number hero.x = 2048 / 2; hero.y = 2732 / 2; // Create and position the lifebar var lifebar = new Lifebar(); lifebar.x = 2048 / 2; lifebar.y = 25; // Centered at the top of the screen game.addChild(lifebar); // Create and position the score text (removed spear hit and level displays) scoreText = new Text2("", { size: 50, fill: 0xFFFFFF }); scoreText.x = 3 * 2048 / 4; scoreText.y = 50; // Align with lifebar game.addChild(scoreText); // Define playable area boundaries var playableArea = { xMin: 100, xMax: 2048 - 100, yMin: 200, yMax: 2732 - 200 }; // Create and position the spear trigger within the playable area spearTrigger = game.addChild(new SpearTrigger()); spearTrigger.x = Math.random() * 2048 * 0.8 + 2048 * 0.1; spearTrigger.y = Math.random() * 2732 * 0.8 + 2732 * 0.1; // Create and position the fire trigger within the playable area fireTrigger = game.addChild(new FireTrigger()); fireTrigger.x = Math.random() * 2048 * 0.8 + 2048 * 0.1; fireTrigger.y = Math.random() * 2732 * 0.8 + 2732 * 0.1; } // Function to handle hero movement function handleMove(x, y, obj) { // Add a wobble and tilting effect to the hero's movement var wobbleIntensity = 5; var tiltIntensity = 0.1; if (hero) { hero.x = x + (Math.random() - 0.5) * wobbleIntensity; hero.y = y + (Math.random() - 0.5) * wobbleIntensity; } if (hero) { hero.rotation = (Math.random() - 0.5) * tiltIntensity; } } // Function to update game state game.update = function () { // Check if the hero intersects with the firewall if (fireTrigger && fireTrigger.fireWall && hero.intersects(fireTrigger.fireWall)) { // Decrease hero's health by 1 every third of a second if (LK.ticks % 20 === 0) { // Assuming 60 ticks per second hero.health -= 1; // Play firewall sound LK.getSound('firewall').play(); } } if (hero && spearTrigger && hero.intersects(spearTrigger)) { var spear = game.addChild(new Spear()); spear.x = Math.random() * 2048; // Random x position spear.y = Math.random() < 0.5 ? 0 : 2732; // Randomly choose top or bottom for y position var dx = hero.x - spear.x; var dy = hero.y - spear.y; var angle = Math.atan2(dy, dx); spear.speedX = Math.cos(angle) * spear.speed; spear.speedY = Math.sin(angle) * spear.speed; spear.rotation = angle; // Rotate the spear in the direction it's moving // Play spear sound LK.getSound('spear').play(); spear.update = function () { this.x += this.speedX; this.y += this.speedY; if (this.intersects(hero.hitbox)) { // Trigger screen shake effect shakeScreen(); // Attach the spear to the hero at the position it first touches him this.speedX = 0; this.speedY = 0; var relativeX = this.x - hero.x; var relativeY = this.y - hero.y; this.update = function () { var wobbleIntensity = 2; var tiltIntensity = 0.05; this.x = hero.x + relativeX + (Math.random() - 0.5) * wobbleIntensity; this.y = hero.y + relativeY + (Math.random() - 0.5) * wobbleIntensity; this.rotation = angle + (Math.random() - 0.5) * tiltIntensity; }; // Play spearhit sound LK.getSound('spearhit').play(); // Reduce player's health hero.health -= 10; // Check if hero's health is 0 to end the game if (hero.health <= 0) { // Set the final score to the time counter LK.setScore(parseFloat(timeCounter.text)); // Show an endscreen for 2 seconds before game over var endScreen = LK.getAsset('hudBackground', { anchorX: 0.5, anchorY: 0.5 }); endScreen.x = 2048 / 2; endScreen.y = 2732 / 2; game.addChild(endScreen); LK.setTimeout(function () { game.removeChild(endScreen); LK.showGameOver(); }, 2000); } } }; // Reposition the spear trigger to a random location spearTrigger.x = Math.random() * 2048; // Random x position spearTrigger.y = Math.random() * 2732; // Random y position } }; // Function to handle transition to the next level function moveToNextLevel() { // Reset hero's health hero.health = 100; // Increment level (removed spear count and level display) currentLevel++; // Reposition hero to the center hero.x = 2048 / 2; hero.y = 2732 / 2; // Reposition spear trigger to a new random location spearTrigger.x = Math.random() * 2048 * 0.8 + 2048 * 0.1; spearTrigger.y = Math.random() * 2732 * 0.8 + 2732 * 0.1; // Optionally, increase difficulty or change level parameters here } // Set up event listeners for touch/mouse interactions game.down = function (x, y, obj) { handleMove(x, y, obj); }; game.move = function (x, y, obj) { handleMove(x, y, obj); }; game.up = function (x, y, obj) { // No specific action needed on release };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var FireTrigger = Container.expand(function () {
var self = Container.call(this);
var fireTriggerGraphics = self.attachAsset('fireTrigger', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
if (!self.fireWall) {
self.fireWall = LK.getAsset('fireWall', {
anchorX: 0.5,
anchorY: 0.5
});
self.fireWall.width = 2048; // Set width to match screen width
self.fireWall.x = 2048 / 2; // Start from the center of the screen
self.fireWall.y = 2732 + self.fireWall.height; // Start from bottom off-screen
self.fireWall.speedX = 0; // No horizontal movement
self.fireWall.speedY = -15; // Move upwards
self.fireWall.update = function () {
this.x += this.speedX;
this.y += this.speedY;
// Add flickering effect
this.alpha = Math.random() * 0.5 + 0.5; // Random alpha between 0.5 and 1
};
game.addChild(self.fireWall);
// Play firewall sound when it spawns
LK.getSound('firewall').play();
// Reposition the fire trigger to a random location
self.x = Math.random() * 2048 * 0.8 + 2048 * 0.1;
self.y = Math.random() * 2732 * 0.8 + 2732 * 0.1;
}
if (self.intersects(hero)) {
self.fireWall = LK.getAsset('fireWall', {
anchorX: 0.5,
anchorY: 0.5
});
self.fireWall.width = 2048; // Set width to match screen width
self.fireWall.x = 2048 / 2; // Start from the center of the screen
self.fireWall.y = 2732 + self.fireWall.height; // Start from bottom off-screen
self.fireWall.speedX = 0; // No horizontal movement
self.fireWall.speedY = -15; // Move upwards
self.fireWall.update = function () {
this.x += this.speedX;
this.y += this.speedY;
// Add flickering effect
this.alpha = Math.random() * 0.5 + 0.5; // Random alpha between 0.5 and 1
};
game.addChild(self.fireWall);
// Play firewall sound when it spawns
LK.getSound('firewall').play();
// Reposition the fire trigger to a random location
self.x = Math.random() * 2048;
self.y = Math.random() * 2732;
}
};
});
// Hero class representing the player character
var Hero = Container.expand(function () {
var self = Container.call(this);
var heroGraphics = self.attachAsset('hero', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
// Add a shadow below the hero
var shadow = self.attachAsset('heroShadow', {
anchorX: 0.5,
anchorY: 0.5
});
shadow.y = heroGraphics.height / 2 + 10; // Position the shadow slightly below the hero
shadow.alpha = 0.5; // Make the shadow semi-transparent
// Add hitbox for collision detection
self.hitbox = new Container();
self.hitbox.width = heroGraphics.width * 1.2; // Increase size for better collision detection
self.hitbox.height = heroGraphics.height * 1.2; // Increase size for better collision detection
self.hitbox.x = -self.hitbox.width;
self.hitbox.y = -self.hitbox.height;
// Display the hitbox with a transparent asset
var hitboxGraphics = LK.getAsset('transparentAsset', {
anchorX: 0.5,
anchorY: 0.5
});
hitboxGraphics.width = self.hitbox.width;
hitboxGraphics.height = self.hitbox.height;
self.hitbox.addChild(hitboxGraphics);
self.addChild(self.hitbox);
self.update = function () {
// Update logic for hero, if needed
};
});
var Lifebar = Container.expand(function () {
var self = Container.call(this);
var lifebarGraphics = self.attachAsset('lifebar', {
anchorX: 0.5,
anchorY: 0.5
});
// Removed life percentage text display
self.update = function () {
// Removed life percentage text display
if (hero.health > 0) {
lifebarGraphics.width = hero.health / 100 * 1500; // Update lifebar width based on health
} else {
lifebarGraphics.width = 0; // Ensure lifebar does not grow after emptying
}
};
});
var Spear = Container.expand(function () {
var self = Container.call(this);
var spearGraphics = self.attachAsset('spear', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 20;
self.update = function () {
self.y += self.speed;
};
});
var SpearTrigger = Container.expand(function () {
var self = Container.call(this);
var spearTriggerGraphics = self.attachAsset('spearTrigger', {
anchorX: 0.5,
anchorY: 0.5
});
});
var StartScreen = Container.expand(function () {
var self = Container.call(this);
var gameTitle = self.attachAsset('gamename', {
anchorX: 0.5,
anchorY: 0.5
});
var startButton = self.attachAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5
});
gameTitle.x = 2048 / 2;
gameTitle.y = 2732 / 2 - 500; // Move the game title 500 pixels up
// Add a tween to animate the game title
function animateTitle() {
tween(gameTitle, {
y: gameTitle.y - 20
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(gameTitle, {
y: gameTitle.y + 20
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: animateTitle // Loop the animation
});
}
});
}
animateTitle();
// Removed stretching of the game title image
startButton.x = 2048 / 2; // Center the start button horizontally
startButton.y = 2732 - 500; // Move the start button 400 pixels up from the bottom of the screen
// Add a tilting effect to the start button
function animateButton() {
tween(startButton, {
rotation: 0.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(startButton, {
rotation: -0.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: animateButton // Loop the tilting effect
});
}
});
}
animateButton();
startButton.down = function (x, y, obj) {
self.destroy();
initGame();
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
var startScreen = game.addChild(new StartScreen());
// Function to create a screen shake effect
function shakeScreen() {
var shakeIntensity = 10;
var shakeDuration = 500; // in milliseconds
var elapsedTime = 0;
var originalX = game.x;
var originalY = game.y;
var shakeInterval = LK.setInterval(function () {
if (elapsedTime < shakeDuration) {
game.x = originalX + (Math.random() - 0.5) * shakeIntensity;
game.y = originalY + (Math.random() - 0.5) * shakeIntensity;
elapsedTime += 16; // approximately 60 FPS
} else {
game.x = originalX;
game.y = originalY;
LK.clearInterval(shakeInterval);
}
}, 16);
}
// Initialize game variables
var hero;
var spearTrigger;
var fireTrigger;
var spearCount = 0;
// Declare scoreText in the global scope
var scoreText;
var currentLevel = 1; // Initialize current level
// Function to initialize game elements
function initGame() {
// Play game music on game start
LK.playMusic('Gamemusic');
// Create and position the time counter
timeCounter = new Text2("0", {
size: 210,
// 70% of the original size
fill: 0xFFFFFF
});
timeCounter.anchor.set(0.5, 1); // Sets anchor to the center of the bottom edge of the text.
LK.gui.bottom.addChild(timeCounter); // Add the time counter to the GUI overlay at the bottom of the screen.
// Update the time counter every second
var startTime = Date.now();
var timeInterval = LK.setInterval(function () {
var elapsedTime = (Date.now() - startTime) / 1000;
timeCounter.setText(elapsedTime.toFixed(3));
// Stop the time counter if hero's health is zero
if (hero.health <= 0) {
LK.clearInterval(timeInterval);
}
}, 1);
// Add background image
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5
});
background.x = 2048 / 2;
background.y = 2732 / 2;
game.addChild(background);
hero = game.addChild(new Hero());
hero.health = 100; // Initialize hero health as a number
hero.x = 2048 / 2;
hero.y = 2732 / 2;
// Create and position the lifebar
var lifebar = new Lifebar();
lifebar.x = 2048 / 2;
lifebar.y = 25; // Centered at the top of the screen
game.addChild(lifebar);
// Create and position the score text (removed spear hit and level displays)
scoreText = new Text2("", {
size: 50,
fill: 0xFFFFFF
});
scoreText.x = 3 * 2048 / 4;
scoreText.y = 50; // Align with lifebar
game.addChild(scoreText);
// Define playable area boundaries
var playableArea = {
xMin: 100,
xMax: 2048 - 100,
yMin: 200,
yMax: 2732 - 200
};
// Create and position the spear trigger within the playable area
spearTrigger = game.addChild(new SpearTrigger());
spearTrigger.x = Math.random() * 2048 * 0.8 + 2048 * 0.1;
spearTrigger.y = Math.random() * 2732 * 0.8 + 2732 * 0.1;
// Create and position the fire trigger within the playable area
fireTrigger = game.addChild(new FireTrigger());
fireTrigger.x = Math.random() * 2048 * 0.8 + 2048 * 0.1;
fireTrigger.y = Math.random() * 2732 * 0.8 + 2732 * 0.1;
}
// Function to handle hero movement
function handleMove(x, y, obj) {
// Add a wobble and tilting effect to the hero's movement
var wobbleIntensity = 5;
var tiltIntensity = 0.1;
if (hero) {
hero.x = x + (Math.random() - 0.5) * wobbleIntensity;
hero.y = y + (Math.random() - 0.5) * wobbleIntensity;
}
if (hero) {
hero.rotation = (Math.random() - 0.5) * tiltIntensity;
}
}
// Function to update game state
game.update = function () {
// Check if the hero intersects with the firewall
if (fireTrigger && fireTrigger.fireWall && hero.intersects(fireTrigger.fireWall)) {
// Decrease hero's health by 1 every third of a second
if (LK.ticks % 20 === 0) {
// Assuming 60 ticks per second
hero.health -= 1;
// Play firewall sound
LK.getSound('firewall').play();
}
}
if (hero && spearTrigger && hero.intersects(spearTrigger)) {
var spear = game.addChild(new Spear());
spear.x = Math.random() * 2048; // Random x position
spear.y = Math.random() < 0.5 ? 0 : 2732; // Randomly choose top or bottom for y position
var dx = hero.x - spear.x;
var dy = hero.y - spear.y;
var angle = Math.atan2(dy, dx);
spear.speedX = Math.cos(angle) * spear.speed;
spear.speedY = Math.sin(angle) * spear.speed;
spear.rotation = angle; // Rotate the spear in the direction it's moving
// Play spear sound
LK.getSound('spear').play();
spear.update = function () {
this.x += this.speedX;
this.y += this.speedY;
if (this.intersects(hero.hitbox)) {
// Trigger screen shake effect
shakeScreen();
// Attach the spear to the hero at the position it first touches him
this.speedX = 0;
this.speedY = 0;
var relativeX = this.x - hero.x;
var relativeY = this.y - hero.y;
this.update = function () {
var wobbleIntensity = 2;
var tiltIntensity = 0.05;
this.x = hero.x + relativeX + (Math.random() - 0.5) * wobbleIntensity;
this.y = hero.y + relativeY + (Math.random() - 0.5) * wobbleIntensity;
this.rotation = angle + (Math.random() - 0.5) * tiltIntensity;
};
// Play spearhit sound
LK.getSound('spearhit').play();
// Reduce player's health
hero.health -= 10;
// Check if hero's health is 0 to end the game
if (hero.health <= 0) {
// Set the final score to the time counter
LK.setScore(parseFloat(timeCounter.text));
// Show an endscreen for 2 seconds before game over
var endScreen = LK.getAsset('hudBackground', {
anchorX: 0.5,
anchorY: 0.5
});
endScreen.x = 2048 / 2;
endScreen.y = 2732 / 2;
game.addChild(endScreen);
LK.setTimeout(function () {
game.removeChild(endScreen);
LK.showGameOver();
}, 2000);
}
}
};
// Reposition the spear trigger to a random location
spearTrigger.x = Math.random() * 2048; // Random x position
spearTrigger.y = Math.random() * 2732; // Random y position
}
};
// Function to handle transition to the next level
function moveToNextLevel() {
// Reset hero's health
hero.health = 100;
// Increment level (removed spear count and level display)
currentLevel++;
// Reposition hero to the center
hero.x = 2048 / 2;
hero.y = 2732 / 2;
// Reposition spear trigger to a new random location
spearTrigger.x = Math.random() * 2048 * 0.8 + 2048 * 0.1;
spearTrigger.y = Math.random() * 2732 * 0.8 + 2732 * 0.1;
// Optionally, increase difficulty or change level parameters here
}
// Set up event listeners for touch/mouse interactions
game.down = function (x, y, obj) {
handleMove(x, y, obj);
};
game.move = function (x, y, obj) {
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
// No specific action needed on release
};
pixealrt spear. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
fireskull button. pixelart.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
spearbutton. pixelart.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixelart button that says "Start". Dungeon vibes.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2000 by 2800 high quality banner. Pixelart. title reads: "Die Knight, Die!". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Pixealrt. Dungeon. Reads: The Knight is DEAD. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.