User prompt
Add the red effect with hit sound in game over
User prompt
And the hit sound
User prompt
Jump sound
User prompt
Add the sounds the game over sound happens, and then, game over happens
User prompt
Make too to add the other obstacle
User prompt
Fix the LK score that does not increase the score
User prompt
!Fix the LK score
User prompt
And set to LK variable too
User prompt
A obstacle or plataform go up = 1 score to LK score
User prompt
And set the variable every obstacle/plataform that goes up
User prompt
Go to up = game over
User prompt
And... try to don't go to up
User prompt
Now make plataforms solid
User prompt
Let's make the game
User prompt
Add shadow to lk score
User prompt
Place the lk score
Code edit (1 edits merged)
Please save this source code
Initial prompt
Jumper
/**** * Classes ****/ // Obstacle class var Obstacle = Container.expand(function () { var self = Container.call(this); var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; self.update = function () { self.y += self.speed; if (self.y < 0) { self.y = 2732; } }; }); // Platform class var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.attachAsset('Plataform', { anchorX: 0.5, anchorY: 0.5 }); self.speed = -5; self.update = function () { self.y += self.speed; if (self.y < 0) { self.y = 2732; } }; }); // The assets will be automatically created and loaded by the LK engine // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // 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); // Initialize and display the score text in the game. var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff", shadow: { color: "#000000", blur: 10, offsetX: 5, offsetY: 5 } }); scoreTxt.setText(LK.getScore()); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize platforms var platforms = []; for (var i = 0; i < 5; i++) { var platform = game.addChild(new Platform()); platform.x = Math.random() * 2048; platform.y = Math.random() * 2732; platforms.push(platform); } // Initialize player and obstacles LK.setScore(game.score); var player = game.addChild(new Player()); player.x = 2048 / 2; player.y = 2732 / 2; var obstacles = []; for (var i = 0; i < 10; i++) { var obstacle = game.addChild(new Obstacle()); obstacle.x = Math.random() * 2048; obstacle.y = Math.random() * 2732; obstacles.push(obstacle); } // Game update function game.update = function () { // Update player movement player.speed += 1; // Gravity effect player.y += player.speed; // Check for collisions with obstacles for (var i = 0; i < obstacles.length; i++) { if (player.intersects(obstacles[i])) { LK.showGameOver(); break; } } // Check for collisions with platforms for (var i = 0; i < platforms.length; i++) { if (player.intersects(platforms[i])) { player.speed = 0; // Stop player movement player.y = platforms[i].y - player.height / 2; // Position player on top of the platform } } }; // Player control game.down = function (x, y, obj) { player.x = x; player.y = y; player.speed = -15; // Make the player jump }; game.move = function (x, y, obj) { player.x = x; player.y = y; };
===================================================================
--- original.js
+++ change.js
@@ -104,15 +104,22 @@
game.update = function () {
// Update player movement
player.speed += 1; // Gravity effect
player.y += player.speed;
- // Check for collisions
+ // Check for collisions with obstacles
for (var i = 0; i < obstacles.length; i++) {
if (player.intersects(obstacles[i])) {
LK.showGameOver();
break;
}
}
+ // Check for collisions with platforms
+ for (var i = 0; i < platforms.length; i++) {
+ if (player.intersects(platforms[i])) {
+ player.speed = 0; // Stop player movement
+ player.y = platforms[i].y - player.height / 2; // Position player on top of the platform
+ }
+ }
};
// Player control
game.down = function (x, y, obj) {
player.x = x;