User prompt
display 3 heart icon and make it functional 3 lives of player
User prompt
add 3 heart of health to the player meaning that player has 3 more lives
User prompt
make enemies bigger and a bit faster
User prompt
remove the double jump effect
User prompt
add dash sfx
User prompt
add sound effects and musics to the game
User prompt
player is not jumping please fix it
User prompt
make the enemies hitboxes small and fix double jump when on ground
Code edit (8 edits merged)
Please save this source code
User prompt
add jump and dash icons on buttons
User prompt
fix doublejump, when the player is on ground reset normal jump
User prompt
fix the double jump while on ground. it should not activated. and make the cooldownText updated with the dash cooldown
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ // Define a class for big flying enemies var BigEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); self.speed = Math.random() * 6 + 6; self.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Define a class for enemies var Enemy = Container.expand(function () { var self = Container.call(this); // Randomize enemy size var size = Math.random() * 0.5 + 0.5; var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5, scaleX: size, scaleY: size }); // Randomize enemy speed self.speed = Math.random() * 3 + 3; self.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); //<Assets used in the game will automatically appear here> // Define a class for the player character var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; self.jumpHeight = 30; self.isJumping = false; self.velocityY = 0; self.update = function () { if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.6; // Decreased gravity effect by 30% if (self.y >= 2732 / 2) { // Ground level self.y = 2732 / 2; self.isJumping = false; self.velocityY = 0; self.canDoubleJump = false; // Reset double jump self.canDoubleDash = true; // Reset double dash when player lands } } }; self.dashBack = function () { if (!self.isDashing || self.canDoubleDash) { if (self.isDashing && self.canDoubleDash) { self.canDoubleDash = false; self.x -= 350; // Second dash back is shorter } if (self.canDoubleDash) { self.canDoubleDash = false; } else { self.isDashing = true; } self.dashTimer = 0; self.oldX = self.x; self.x -= 300; // Increase dash distance } }; self.jump = function () { if (!self.isJumping || self.canDoubleJump) { self.isJumping = true; self.velocityY = self.canDoubleJump ? -self.jumpHeight * 0.5 : -self.jumpHeight * 1.2; if (self.canDoubleJump) { self.canDoubleJump = false; } else { self.canDoubleJump = true; } } }; self.update = function () { if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.7; // Decreased gravity effect by 30% if (self.y >= 2732 / 2) { // Ground level self.y = 2732 / 2; self.isJumping = false; self.velocityY = 0; } } if (self.isDashing) { self.dashTimer++; if (self.dashTimer > 80) { // Increase dash cooldown self.isDashing = false; self.x = self.oldX; } } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Draw white rectangles on screen to indicate where to touch var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0 })); background.x = 0; background.y = 0; var leftTouchArea = game.addChild(LK.getAsset('leftTouchArea', { anchorX: 0, anchorY: 0 })); var rightTouchArea = game.addChild(LK.getAsset('rightTouchArea', { anchorX: 0, anchorY: 0 })); leftTouchArea.alpha = 0.7; leftTouchArea.y = 1474; leftTouchArea.x = 137; rightTouchArea.alpha = 0.7; rightTouchArea.x = 1161; rightTouchArea.y = 1474; // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2; // Initialize enemies var enemies = []; var enemySpawnInterval = 100; var enemySpawnCounter = 0; // Create a new Text2 object to display the score var scoreText = new Text2('0', { size: 100, fill: 0x000000 }); // Add a new Text2 object to display the cooldown of Dash var cooldownText = new Text2('0', { size: 175, fill: 0x0000000 }); // Add the cooldown text to the game GUI at the middle of dash button game.addChild(cooldownText); cooldownText.x = leftTouchArea.x + leftTouchArea.x / 2; cooldownText.y = leftTouchArea.y + leftTouchArea.y / 2; // Add the score text to the game GUI at the top right of the screen game.addChild(scoreText); scoreText.x = 2048 / 2; scoreText.y = 100; // Add control instructions to the game screen var controlText = new Text2('Tap right to jump, tap left to dash back', { anchorX: 25, anchorY: 0.5, size: 100, fill: 0x000000 }); game.addChild(controlText); controlText.x = 2048 / 9; controlText.y = 2620; // Handle game updates game.update = function () { player.update(); // Spawn enemies enemySpawnCounter++; if (enemySpawnCounter >= enemySpawnInterval) { var enemy; if (Math.random() < 0.2) { // 20% chance to spawn a big enemy enemy = new BigEnemy(); enemy.y = 2732 / 4; } else { enemy = new Enemy(); enemy.y = 2732 / 2; } enemy.x = 2096; enemies.push(enemy); game.addChild(enemy); // Randomize the spawn interval for the next enemy enemySpawnInterval = Math.floor(Math.random() * 100) + 50; enemySpawnCounter = 0; } // Update enemies for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (player.intersects(enemies[j])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } else if (player.x > enemies[j].x && !enemies[j].passed) { enemies[j].passed = true; LK.setScore(LK.getScore() + (enemies[j] instanceof BigEnemy ? 2 : 1)); // Big enemies give 2 points scoreText.setText(LK.getScore()); } } }; // Handle player jump game.down = function (x, y, obj) { if (x < 1024) { player.dashBack(); } else { player.jump(); } };
/****
* Classes
****/
// Define a class for big flying enemies
var BigEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 2,
scaleY: 2
});
self.speed = Math.random() * 6 + 6;
self.update = function () {
self.x -= self.speed;
if (self.x < -50) {
self.destroy();
}
};
});
// Define a class for enemies
var Enemy = Container.expand(function () {
var self = Container.call(this);
// Randomize enemy size
var size = Math.random() * 0.5 + 0.5;
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: size,
scaleY: size
});
// Randomize enemy speed
self.speed = Math.random() * 3 + 3;
self.update = function () {
self.x -= self.speed;
if (self.x < -50) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
// Define a class for the player character
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3;
self.jumpHeight = 30;
self.isJumping = false;
self.velocityY = 0;
self.update = function () {
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 0.6; // Decreased gravity effect by 30%
if (self.y >= 2732 / 2) {
// Ground level
self.y = 2732 / 2;
self.isJumping = false;
self.velocityY = 0;
self.canDoubleJump = false; // Reset double jump
self.canDoubleDash = true; // Reset double dash when player lands
}
}
};
self.dashBack = function () {
if (!self.isDashing || self.canDoubleDash) {
if (self.isDashing && self.canDoubleDash) {
self.canDoubleDash = false;
self.x -= 350; // Second dash back is shorter
}
if (self.canDoubleDash) {
self.canDoubleDash = false;
} else {
self.isDashing = true;
}
self.dashTimer = 0;
self.oldX = self.x;
self.x -= 300; // Increase dash distance
}
};
self.jump = function () {
if (!self.isJumping || self.canDoubleJump) {
self.isJumping = true;
self.velocityY = self.canDoubleJump ? -self.jumpHeight * 0.5 : -self.jumpHeight * 1.2;
if (self.canDoubleJump) {
self.canDoubleJump = false;
} else {
self.canDoubleJump = true;
}
}
};
self.update = function () {
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 0.7; // Decreased gravity effect by 30%
if (self.y >= 2732 / 2) {
// Ground level
self.y = 2732 / 2;
self.isJumping = false;
self.velocityY = 0;
}
}
if (self.isDashing) {
self.dashTimer++;
if (self.dashTimer > 80) {
// Increase dash cooldown
self.isDashing = false;
self.x = self.oldX;
}
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Draw white rectangles on screen to indicate where to touch
var background = game.addChild(LK.getAsset('background', {
anchorX: 0,
anchorY: 0
}));
background.x = 0;
background.y = 0;
var leftTouchArea = game.addChild(LK.getAsset('leftTouchArea', {
anchorX: 0,
anchorY: 0
}));
var rightTouchArea = game.addChild(LK.getAsset('rightTouchArea', {
anchorX: 0,
anchorY: 0
}));
leftTouchArea.alpha = 0.7;
leftTouchArea.y = 1474;
leftTouchArea.x = 137;
rightTouchArea.alpha = 0.7;
rightTouchArea.x = 1161;
rightTouchArea.y = 1474;
// Initialize player
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 / 2;
// Initialize enemies
var enemies = [];
var enemySpawnInterval = 100;
var enemySpawnCounter = 0;
// Create a new Text2 object to display the score
var scoreText = new Text2('0', {
size: 100,
fill: 0x000000
});
// Add a new Text2 object to display the cooldown of Dash
var cooldownText = new Text2('0', {
size: 175,
fill: 0x0000000
});
// Add the cooldown text to the game GUI at the middle of dash button
game.addChild(cooldownText);
cooldownText.x = leftTouchArea.x + leftTouchArea.x / 2;
cooldownText.y = leftTouchArea.y + leftTouchArea.y / 2;
// Add the score text to the game GUI at the top right of the screen
game.addChild(scoreText);
scoreText.x = 2048 / 2;
scoreText.y = 100;
// Add control instructions to the game screen
var controlText = new Text2('Tap right to jump, tap left to dash back', {
anchorX: 25,
anchorY: 0.5,
size: 100,
fill: 0x000000
});
game.addChild(controlText);
controlText.x = 2048 / 9;
controlText.y = 2620;
// Handle game updates
game.update = function () {
player.update();
// Spawn enemies
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval) {
var enemy;
if (Math.random() < 0.2) {
// 20% chance to spawn a big enemy
enemy = new BigEnemy();
enemy.y = 2732 / 4;
} else {
enemy = new Enemy();
enemy.y = 2732 / 2;
}
enemy.x = 2096;
enemies.push(enemy);
game.addChild(enemy);
// Randomize the spawn interval for the next enemy
enemySpawnInterval = Math.floor(Math.random() * 100) + 50;
enemySpawnCounter = 0;
}
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
if (player.intersects(enemies[j])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
} else if (player.x > enemies[j].x && !enemies[j].passed) {
enemies[j].passed = true;
LK.setScore(LK.getScore() + (enemies[j] instanceof BigEnemy ? 2 : 1)); // Big enemies give 2 points
scoreText.setText(LK.getScore());
}
}
};
// Handle player jump
game.down = function (x, y, obj) {
if (x < 1024) {
player.dashBack();
} else {
player.jump();
}
};