User prompt
Finally, add rare coins that give +3 score when collected
Code edit (2 edits merged)
Please save this source code
User prompt
Still the same problem, platforms do not appear in the right place and we fall to the ground after jumping once on the normal platform
User prompt
You still haven't done it right and when we wait on normal platforms we suddenly fall to the ground.
Code edit (1 edits merged)
Please save this source code
User prompt
platforms are too high and far apart fix this and add fragile platforms Also the character doesn't die when he falls to the ground, fix that
User prompt
Make the right and left control buttons have the same value, increase the jumping power and make the platform heights proportional so that the player can jump.
Code edit (1 edits merged)
Please save this source code
User prompt
Doodle Jump Adventure
Initial prompt
Make a doodle jump game, the character will jump automatically and there will be right and left control buttons, there will be a good speed, a jump button and the game will be endless, let's get +1 score for every platform we jump on without dying and when we start the game, there should be a special platform under us that protects the spawn point.
/**** * Classes ****/ var Character = Container.expand(function () { var self = Container.call(this); var characterGraphics = self.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); self.velocityY = 0; self.gravity = 0.8; self.jumpPower = -25.5; self.horizontalSpeed = 0; self.maxHorizontalSpeed = 8; self.onGround = false; self.jump = function () { self.velocityY = self.jumpPower; self.onGround = false; }; self.moveLeft = function () { self.horizontalSpeed = Math.max(self.horizontalSpeed - 2, -self.maxHorizontalSpeed); }; self.moveRight = function () { self.horizontalSpeed = Math.min(self.horizontalSpeed + 2, self.maxHorizontalSpeed); }; self.update = function () { // Only apply gravity if not on ground if (!self.onGround) { self.velocityY += self.gravity; } // Update position self.y += self.velocityY; self.x += self.horizontalSpeed; // Apply horizontal friction self.horizontalSpeed *= 0.85; // Screen wrapping if (self.x < 0) { self.x = 2048; } else if (self.x > 2048) { self.x = 0; } }; return self; }); var ControlButton = Container.expand(function (direction) { var self = Container.call(this); var buttonAsset = direction === 'left' ? 'leftButton' : 'rightButton'; var buttonGraphics = self.attachAsset(buttonAsset, { anchorX: 0.5, anchorY: 0.5 }); self.direction = direction; self.alpha = 0.7; self.down = function (x, y, obj) { self.alpha = 1.0; if (self.direction === 'left') { isLeftPressed = true; } else { isRightPressed = true; } }; self.up = function (x, y, obj) { self.alpha = 0.7; if (self.direction === 'left') { isLeftPressed = false; } else { isRightPressed = false; } }; return self; }); var FragilePlatform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.attachAsset('fragilePlatform', { anchorX: 0.5, anchorY: 0.5 }); self.hasBeenLandedOn = false; self.isBroken = false; self.breakPlatform = function () { self.isBroken = true; platformGraphics.alpha = 0.3; // Platform will be removed after a short delay LK.setTimeout(function () { if (self.parent) { self.destroy(); } }, 200); }; return self; }); var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.attachAsset('platform', { anchorX: 0.5, anchorY: 0.5 }); self.hasBeenLandedOn = false; return self; }); var SpawnPlatform = Container.expand(function () { var self = Container.call(this); var spawnPlatformGraphics = self.attachAsset('spawnPlatform', { anchorX: 0.5, anchorY: 0.5 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var character; var platforms = []; var spawnPlatform; var leftButton; var rightButton; var cameraOffsetY = 0; var isLeftPressed = false; var isRightPressed = false; var gameSpeed = 1; // Create score display var scoreTxt = new Text2('0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create spawn platform spawnPlatform = game.addChild(new SpawnPlatform()); spawnPlatform.x = 1024; spawnPlatform.y = 2500; // Create character character = game.addChild(new Character()); character.x = 1024; character.y = 2400; // Generate initial platforms function generatePlatform(y) { var platform; // 30% chance to create fragile platform if (Math.random() < 0.3) { platform = new FragilePlatform(); } else { platform = new Platform(); } platform.x = Math.random() * 1800 + 124; // Keep platforms within screen bounds platform.y = y; platforms.push(platform); game.addChild(platform); } // Generate initial platforms with closer spacing for (var i = 0; i < 20; i++) { generatePlatform(2200 - i * 80); // Reduced to 80 for much closer spacing } // Create control buttons leftButton = new ControlButton('left'); leftButton.x = 200; leftButton.y = 2600; LK.gui.bottomLeft.addChild(leftButton); rightButton = new ControlButton('right'); rightButton.x = 200; rightButton.y = 2600; LK.gui.bottomRight.addChild(rightButton); // Position buttons correctly leftButton.x = 150; leftButton.y = -100; rightButton.x = -150; rightButton.y = -100; function checkPlatformCollisions() { var wasOnGround = character.onGround; character.onGround = false; // Check collision with spawn platform first if (character.velocityY >= 0 && character.y + 40 >= spawnPlatform.y - 15 && character.y - 40 <= spawnPlatform.y + 15 && character.x >= spawnPlatform.x - 150 && character.x <= spawnPlatform.x + 150) { character.y = spawnPlatform.y - 40; character.velocityY = 0; character.onGround = true; // Only jump if we just landed (not if we were already on ground) if (!wasOnGround) { character.jump(); } return; } // Check regular platforms for (var i = platforms.length - 1; i >= 0; i--) { var platform = platforms[i]; // Skip broken fragile platforms if (platform.isBroken) { continue; } if (character.velocityY >= 0 && character.y + 40 >= platform.y - 10 && character.y - 40 <= platform.y + 10 && character.x >= platform.x - 100 && character.x <= platform.x + 100) { character.y = platform.y - 40; character.velocityY = 0; character.onGround = true; // Only jump and score if we just landed (not if we were already on ground) if (!wasOnGround) { character.jump(); if (!platform.hasBeenLandedOn) { platform.hasBeenLandedOn = true; LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); // Increase game speed gradually gameSpeed = 1 + LK.getScore() * 0.02; // Break fragile platforms after landing if (platform.breakPlatform) { platform.breakPlatform(); // Remove from platforms array platforms.splice(i, 1); } } } break; } } } function updateCamera() { var targetY = character.y - 1366; // Keep character in middle-upper area var newCameraOffsetY = targetY; var cameraDiff = newCameraOffsetY - cameraOffsetY; cameraOffsetY = newCameraOffsetY; // Apply camera offset to all game objects game.y -= cameraDiff; } function managePlatforms() { // Remove platforms that are too far below for (var i = platforms.length - 1; i >= 0; i--) { if (platforms[i].y > character.y + 1500) { platforms[i].destroy(); platforms.splice(i, 1); } } // Add new platforms above with better spacing var highestPlatform = Math.min.apply(Math, platforms.map(function (p) { return p.y; })); while (highestPlatform > character.y - 2000) { highestPlatform -= 60 + Math.random() * 20; // Much closer spacing: 60-80 pixels generatePlatform(highestPlatform); } } game.update = function () { // Handle input if (isLeftPressed) { character.moveLeft(); } if (isRightPressed) { character.moveRight(); } // Check platform collisions checkPlatformCollisions(); // Update camera updateCamera(); // Manage platforms managePlatforms(); // Check game over - character falls below spawn platform if (character.y > spawnPlatform.y + 500) { LK.showGameOver(); } }; // Handle global touch controls for mobile game.down = function (x, y, obj) { if (x < 1024) { isLeftPressed = true; leftButton.alpha = 1.0; } else { isRightPressed = true; rightButton.alpha = 1.0; } }; game.up = function (x, y, obj) { isLeftPressed = false; isRightPressed = false; leftButton.alpha = 0.7; rightButton.alpha = 0.7; };
===================================================================
--- original.js
+++ change.js
@@ -8,9 +8,9 @@
anchorY: 0.5
});
self.velocityY = 0;
self.gravity = 0.8;
- self.jumpPower = -23;
+ self.jumpPower = -25.5;
self.horizontalSpeed = 0;
self.maxHorizontalSpeed = 8;
self.onGround = false;
self.jump = function () {