User prompt
Adjust the spawn position of triggers. Can only appear in the 80 percent of the height and 80 percent of the witdh of the screen
User prompt
Game over screen should cove all the screen with an asset
User prompt
Show an endscreen for 2 seconds before game over
User prompt
Why is life bar growing again after emptying?
User prompt
Please fix the bug: 'ReferenceError: lifebar is not defined' in or related to this line: 'if (hero.health <= 0 || lifebar.width <= 0) {' Line Number: 367
User prompt
Please fix the bug: 'ReferenceError: lifebar is not defined' in or related to this line: 'if (hero.health <= 0 || lifebar.lifebarGraphics.width <= 0) {' Line Number: 367
User prompt
Please fix the bug: 'ReferenceError: lifebarGraphics is not defined' in or related to this line: 'if (hero.health <= 0 || lifebarGraphics.width <= 0) {' Line Number: 367
User prompt
Life should be 0 when bar is empty
User prompt
On game end, update lk score with counter time
User prompt
Replcae timer wit lk score
User prompt
Counter should be ocnsiderd as lk score
User prompt
Play gamemusic on game start
User prompt
Add some fire and speers moving areound in the background of rhe startscreen
User prompt
Move helthbar 200 pixels down
User prompt
Title and button ahoild keep on their movement endlessly
User prompt
Add effect to the start button, a little titling
User prompt
Use a tween for the game title to look alive ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Move startbutton 400 pixela up
User prompt
Remove logic for startbutton possition, just place it in the bottom of the screen
User prompt
Move start button 300 pixela doen
User prompt
Move gamename 500 pixels up
User prompt
Do not strech gamename
User prompt
Endure triggers are not closer than 200 pixels from the borders
User prompt
Buttona shoild not be closer to the borders of the screen tahn 200 pixels
User prompt
Move start button 400 pixela down
/**** * 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; self.y = Math.random() * 2732; } 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 lifebarGraphics.width = hero.health / 100 * 1500; // Update lifebar width based on health }; }); 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; // Center the game title gameTitle.width = 2048; // Stretch to fit the screen width gameTitle.height = 2732; // Stretch to fit the screen height startButton.x = 2048 / 2; startButton.y = 2732 / 2 + 400; // Move start button 400 pixels down to ensure it appears over the background 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() { // Create and position the time counter timeCounter = new Text2("0", { size: 210, // 70% of the original size fill: "#ffffff" }); 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(); LK.setInterval(function () { var elapsedTime = (Date.now() - startTime) / 1000; timeCounter.setText(elapsedTime.toFixed(3)); }, 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: "#ffffff" }); 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 = playableArea.xMin + Math.random() * (playableArea.xMax - playableArea.xMin); spearTrigger.y = playableArea.yMin + Math.random() * (playableArea.yMax - playableArea.yMin); // Create and position the fire trigger within the playable area fireTrigger = game.addChild(new FireTrigger()); fireTrigger.x = playableArea.xMin + Math.random() * (playableArea.xMax - playableArea.xMin); fireTrigger.y = playableArea.yMin + Math.random() * (playableArea.yMax - playableArea.yMin); } // 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 game over LK.showGameOver(); } } }; // 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; spearTrigger.y = Math.random() * 2732; // 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 };
/****
* 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;
self.y = Math.random() * 2732;
}
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
lifebarGraphics.width = hero.health / 100 * 1500; // Update lifebar width based on health
};
});
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; // Center the game title
gameTitle.width = 2048; // Stretch to fit the screen width
gameTitle.height = 2732; // Stretch to fit the screen height
startButton.x = 2048 / 2;
startButton.y = 2732 / 2 + 400; // Move start button 400 pixels down to ensure it appears over the background
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() {
// Create and position the time counter
timeCounter = new Text2("0", {
size: 210,
// 70% of the original size
fill: "#ffffff"
});
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();
LK.setInterval(function () {
var elapsedTime = (Date.now() - startTime) / 1000;
timeCounter.setText(elapsedTime.toFixed(3));
}, 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: "#ffffff"
});
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 = playableArea.xMin + Math.random() * (playableArea.xMax - playableArea.xMin);
spearTrigger.y = playableArea.yMin + Math.random() * (playableArea.yMax - playableArea.yMin);
// Create and position the fire trigger within the playable area
fireTrigger = game.addChild(new FireTrigger());
fireTrigger.x = playableArea.xMin + Math.random() * (playableArea.xMax - playableArea.xMin);
fireTrigger.y = playableArea.yMin + Math.random() * (playableArea.yMax - playableArea.yMin);
}
// 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 game over
LK.showGameOver();
}
}
};
// 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;
spearTrigger.y = Math.random() * 2732;
// 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.