User prompt
the platform scroll down should not be instant but smooth
Code edit (8 edits merged)
Please save this source code
User prompt
when a platform goes to the bottom of the screen, it's moved to the top of the screen at a new random X position and new width.
User prompt
when the player land on a platform, all platform should scroll down of the gap distance
Code edit (9 edits merged)
Please save this source code
User prompt
the platform should be placed randomly on screen from bottom to top, with a small gap between them
Code edit (1 edits merged)
Please save this source code
User prompt
the player should not pass trough platform
User prompt
the platform should have a random width, from 10% to 50% of the width.
User prompt
the player should jump from a platform to another one
User prompt
the player should jump higher
User prompt
the player should follow the X mouse position
User prompt
the platform should be placed randomly on screen
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'push')' in or related to this line: 'obstacles.push(game.addChild(platform));' Line Number: 68
User prompt
the platform should be static and all present at the begining
Initial prompt
Jump to Climb
===================================================================
--- original.js
+++ change.js
@@ -1,59 +1,66 @@
-/****
+/****
* Classes
****/
var Hero = Container.expand(function () {
- var self = Container.call(this);
- var heroGraphics = self.attachAsset('hero', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speedY = 0;
- self.gravity = 0.5;
- self.jumpForce = -10;
- self.jump = function () {
- self.speedY = self.jumpForce;
- };
- self.update = function () {
- self.y += self.speedY;
- self.speedY += self.gravity;
- // Prevent hero from falling below the ground
- if (self.y > 2732 - 25) {
- self.y = 2732 - 25;
- self.speedY = 0;
- }
- };
+ var self = Container.call(this);
+ var heroGraphics = self.attachAsset('hero', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speedY = 0;
+ self.gravity = 0.5;
+ self.jumpForce = -10;
+ self.jump = function () {
+ self.speedY = self.jumpForce;
+ };
+ self.update = function () {
+ self.y += self.speedY;
+ self.speedY += self.gravity;
+ // Prevent hero from falling below the ground
+ if (self.y > 2732 - 25) {
+ self.y = 2732 - 25;
+ self.speedY = 0;
+ }
+ };
});
var Obstacle = Container.expand(function () {
- var self = Container.call(this);
- var obstacleGraphics = self.attachAsset('obstacle', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speedX = -5;
- self.move = function () {
- self.x += self.speedX;
- };
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speedX = -5;
+ self.move = function () {
+ self.x += self.speedX;
+ };
});
var Tower = Container.expand(function () {
- var self = Container.call(this);
- var towerGraphics = self.attachAsset('tower', {
- anchorX: 0.5,
- anchorY: 0
- });
- self.x = 2048 / 2; // Center the tower
+ var self = Container.call(this);
+ var towerGraphics = self.attachAsset('tower', {
+ anchorX: 0.5,
+ anchorY: 0
+ });
+ self.x = 2048 / 2; // Center the tower
});
-/****
+/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
****/
+// Create static platforms
+for (var i = 0; i < 10; i++) {
+ var platform = new Obstacle();
+ platform.x = i * 200;
+ platform.y = 2732 - 100;
+ obstacles.push(game.addChild(platform));
+}
var hero = game.addChild(new Hero());
hero.x = 2048 / 2;
hero.y = 2732 / 2;
var towers = [];
@@ -61,31 +68,10 @@
// Create initial tower
var initialTower = game.addChild(new Tower());
// Handle touch to make the hero jump
game.on('down', function () {
- hero.jump();
+ hero.jump();
});
// Game tick
LK.on('tick', function () {
- hero.update();
- // Move obstacles and check for collision with hero
- for (var i = obstacles.length - 1; i >= 0; i--) {
- obstacles[i].move();
- if (hero.intersects(obstacles[i])) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
- // Remove off-screen obstacles
- if (obstacles[i].x < -50) {
- obstacles[i].destroy();
- obstacles.splice(i, 1);
- }
- }
- // Add new obstacles
- if (LK.ticks % 120 == 0) {
- // Every 2 seconds
- var newObstacle = new Obstacle();
- newObstacle.x = 2048 + 50; // Start off-screen to the right
- newObstacle.y = Math.random() * (2732 - 50); // Random height
- obstacles.push(game.addChild(newObstacle));
- }
+ hero.update();
});
\ No newline at end of file
a little squirrel with sun glasses and earring. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d flat leaf green horizontal platform. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
acorn. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.