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 = -22;
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 () {
// Apply gravity
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 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 = 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
for (var i = 0; i < 20; i++) {
generatePlatform(2200 - i * 200);
}
// 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() {
// 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.jump();
return;
}
// Check regular platforms
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
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.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;
}
}
}
function updateCamera() {
var targetY = character.y - 1366; // Keep character in middle-upper area
cameraOffsetY += (targetY - cameraOffsetY) * 0.1;
// Apply camera offset to all game objects
character.y -= cameraOffsetY * 0.1;
spawnPlatform.y -= cameraOffsetY * 0.1;
for (var i = 0; i < platforms.length; i++) {
platforms[i].y -= cameraOffsetY * 0.1;
}
}
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
var highestPlatform = Math.min.apply(Math, platforms.map(function (p) {
return p.y;
}));
while (highestPlatform > character.y - 2000) {
highestPlatform -= 180 + Math.random() * 80;
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
if (character.y > cameraOffsetY + 3000) {
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,21 +8,21 @@
anchorY: 0.5
});
self.velocityY = 0;
self.gravity = 0.8;
- self.jumpPower = -18;
+ self.jumpPower = -22;
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 - 1, -self.maxHorizontalSpeed);
+ self.horizontalSpeed = Math.max(self.horizontalSpeed - 2, -self.maxHorizontalSpeed);
};
self.moveRight = function () {
- self.horizontalSpeed = Math.min(self.horizontalSpeed + 1, self.maxHorizontalSpeed);
+ self.horizontalSpeed = Math.min(self.horizontalSpeed + 2, self.maxHorizontalSpeed);
};
self.update = function () {
// Apply gravity
self.velocityY += self.gravity;
@@ -128,9 +128,9 @@
game.addChild(platform);
}
// Generate initial platforms
for (var i = 0; i < 20; i++) {
- generatePlatform(2200 - i * 300);
+ generatePlatform(2200 - i * 200);
}
// Create control buttons
leftButton = new ControlButton('left');
leftButton.x = 200;
@@ -191,9 +191,9 @@
var highestPlatform = Math.min.apply(Math, platforms.map(function (p) {
return p.y;
}));
while (highestPlatform > character.y - 2000) {
- highestPlatform -= 250 + Math.random() * 100;
+ highestPlatform -= 180 + Math.random() * 80;
generatePlatform(highestPlatform);
}
}
game.update = function () {