User prompt
When you jump on the platform we were born on, let it stay on it
User prompt
When she jumps she can stand on the platform
User prompt
Let the character jump on his own
User prompt
May we stand on the platform on which we were born in the first place
User prompt
Dies 2 seconds after falling
User prompt
The character should be able to stand on platforms and not fall down.
User prompt
to stand on the platform and not fall down
Code edit (1 edits merged)
Please save this source code
User prompt
Sky Hopper
Initial prompt
Make me a game like doodle jump
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Platform = Container.expand(function (type) {
var self = Container.call(this);
self.platformType = type || 'normal';
var assetName = 'platform';
if (self.platformType === 'moving') {
assetName = 'movingPlatform';
} else if (self.platformType === 'bounce') {
assetName = 'bouncePlatform';
}
var platformGraphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
self.moveDirection = 1;
self.moveSpeed = 2;
self.update = function () {
if (self.platformType === 'moving') {
self.x += self.moveDirection * self.moveSpeed;
if (self.x <= 100 || self.x >= 1948) {
self.moveDirection *= -1;
}
}
};
self.getBounceForce = function () {
if (self.platformType === 'bounce') {
return -25;
}
return -18;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.isOnPlatform = false;
self.lastY = 0;
self.update = function () {
// Store current platform if on one
var currentPlatform = null;
if (self.isOnPlatform && self.velocityY >= 0) {
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
var playerLeft = self.x - 40;
var playerRight = self.x + 40;
var platformLeft = platform.x - 100;
var platformRight = platform.x + 100;
if (Math.abs(self.y - (platform.y - 50)) < 20 && playerRight > platformLeft && playerLeft < platformRight) {
currentPlatform = platform;
break;
}
}
}
// Apply horizontal movement
self.x += self.velocityX;
// If on a moving platform, move with it
if (currentPlatform && currentPlatform.platformType === 'moving') {
self.x += currentPlatform.moveDirection * currentPlatform.moveSpeed;
}
// Apply gravity (reduced when on platform for stability)
if (self.isOnPlatform && self.velocityY >= 0) {
self.velocityY += 0.3; // Reduced gravity when on platform
} else {
self.velocityY += 0.8; // Normal gravity
}
self.y += self.velocityY;
// Horizontal deceleration
self.velocityX *= 0.95;
// Keep player within screen bounds horizontally
if (self.x < 40) {
self.x = 40;
self.velocityX = 0;
}
if (self.x > 2008) {
self.x = 2008;
self.velocityX = 0;
}
self.lastY = self.y;
};
self.bounce = function (bounceForce) {
self.velocityY = bounceForce || -18;
self.isOnPlatform = true; // Set to true initially, will be updated in next frame
LK.getSound('bounce').play();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var player;
var platforms = [];
var cameraY = 0;
var nextPlatformY = 2500;
var highestY = 2732;
var gameStarted = false;
var leftPressed = false;
var rightPressed = false;
// Initialize score display
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize height display
var heightTxt = new Text2('Height: 0m', {
size: 60,
fill: 0xFFFFFF
});
heightTxt.anchor.set(0, 0);
heightTxt.x = 120;
heightTxt.y = 20;
LK.gui.topLeft.addChild(heightTxt);
// Create player
player = game.addChild(new Player());
player.x = 1024;
player.y = 2500;
// Create initial platforms
function createPlatform(x, y, type) {
var platform = new Platform(type);
platform.x = x;
platform.y = y;
platforms.push(platform);
game.addChild(platform);
return platform;
}
// Generate initial platforms
createPlatform(1024, 2600, 'normal');
for (var i = 0; i < 15; i++) {
var x = Math.random() * 1600 + 200;
var y = nextPlatformY - Math.random() * 150 - 100;
var platformType = 'normal';
if (Math.random() < 0.2) {
platformType = 'moving';
} else if (Math.random() < 0.1) {
platformType = 'bounce';
}
createPlatform(x, y, platformType);
nextPlatformY = y;
}
function generateNewPlatforms() {
while (nextPlatformY > cameraY - 1000) {
var x = Math.random() * 1600 + 200;
var y = nextPlatformY - Math.random() * 200 - 120;
var platformType = 'normal';
var random = Math.random();
if (random < 0.25) {
platformType = 'moving';
} else if (random < 0.15) {
platformType = 'bounce';
}
createPlatform(x, y, platformType);
nextPlatformY = y;
}
}
function updateCamera() {
var targetCameraY = player.y - 1800;
if (targetCameraY < cameraY) {
cameraY = targetCameraY;
}
game.y = -cameraY;
}
function updateScore() {
if (player.y < highestY) {
highestY = player.y;
var score = Math.floor((2732 - highestY) / 10);
LK.setScore(score);
scoreTxt.setText(LK.getScore());
var height = Math.floor(score / 10);
heightTxt.setText('Height: ' + height + 'm');
}
}
function checkPlatformCollisions() {
if (player.velocityY <= 0) return;
player.isOnPlatform = false;
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
if (player.intersects(platform)) {
var playerBottom = player.y + 40;
var platformTop = platform.y - 10;
var playerLeft = player.x - 40;
var playerRight = player.x + 40;
var platformLeft = platform.x - 100;
var platformRight = platform.x + 100;
// Check if player is falling down onto the platform and within platform bounds
if (playerBottom >= platformTop && playerBottom <= platformTop + 30 && playerRight > platformLeft && playerLeft < platformRight) {
player.y = platformTop - 40;
player.isOnPlatform = true;
player.bounce(platform.getBounceForce());
break;
}
}
}
}
function cleanupPlatforms() {
for (var i = platforms.length - 1; i >= 0; i--) {
var platform = platforms[i];
if (platform.y > cameraY + 3000) {
platform.destroy();
platforms.splice(i, 1);
}
}
}
function handleInput() {
if (leftPressed) {
player.velocityX -= 1.2;
if (player.velocityX < -8) player.velocityX = -8;
}
if (rightPressed) {
player.velocityX += 1.2;
if (player.velocityX > 8) player.velocityX = 8;
}
}
// Game controls
game.down = function (x, y, obj) {
if (x < 1024) {
leftPressed = true;
} else {
rightPressed = true;
}
gameStarted = true;
};
game.up = function (x, y, obj) {
leftPressed = false;
rightPressed = false;
};
// Main game loop
game.update = function () {
if (!gameStarted) return;
handleInput();
checkPlatformCollisions();
updateCamera();
updateScore();
generateNewPlatforms();
cleanupPlatforms();
// Check for game over (player falls too far below camera)
if (player.y > cameraY + 2900) {
LK.getSound('fall').play();
LK.showGameOver();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -47,12 +47,35 @@
self.velocityY = 0;
self.isOnPlatform = false;
self.lastY = 0;
self.update = function () {
+ // Store current platform if on one
+ var currentPlatform = null;
+ if (self.isOnPlatform && self.velocityY >= 0) {
+ for (var i = 0; i < platforms.length; i++) {
+ var platform = platforms[i];
+ var playerLeft = self.x - 40;
+ var playerRight = self.x + 40;
+ var platformLeft = platform.x - 100;
+ var platformRight = platform.x + 100;
+ if (Math.abs(self.y - (platform.y - 50)) < 20 && playerRight > platformLeft && playerLeft < platformRight) {
+ currentPlatform = platform;
+ break;
+ }
+ }
+ }
// Apply horizontal movement
self.x += self.velocityX;
- // Apply gravity
- self.velocityY += 0.8;
+ // If on a moving platform, move with it
+ if (currentPlatform && currentPlatform.platformType === 'moving') {
+ self.x += currentPlatform.moveDirection * currentPlatform.moveSpeed;
+ }
+ // Apply gravity (reduced when on platform for stability)
+ if (self.isOnPlatform && self.velocityY >= 0) {
+ self.velocityY += 0.3; // Reduced gravity when on platform
+ } else {
+ self.velocityY += 0.8; // Normal gravity
+ }
self.y += self.velocityY;
// Horizontal deceleration
self.velocityX *= 0.95;
// Keep player within screen bounds horizontally
@@ -67,9 +90,9 @@
self.lastY = self.y;
};
self.bounce = function (bounceForce) {
self.velocityY = bounceForce || -18;
- self.isOnPlatform = false;
+ self.isOnPlatform = true; // Set to true initially, will be updated in next frame
LK.getSound('bounce').play();
};
return self;
});
@@ -168,15 +191,22 @@
}
}
function checkPlatformCollisions() {
if (player.velocityY <= 0) return;
+ player.isOnPlatform = false;
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
if (player.intersects(platform)) {
var playerBottom = player.y + 40;
var platformTop = platform.y - 10;
- if (playerBottom >= platformTop && playerBottom <= platformTop + 20) {
+ var playerLeft = player.x - 40;
+ var playerRight = player.x + 40;
+ var platformLeft = platform.x - 100;
+ var platformRight = platform.x + 100;
+ // Check if player is falling down onto the platform and within platform bounds
+ if (playerBottom >= platformTop && playerBottom <= platformTop + 30 && playerRight > platformLeft && playerLeft < platformRight) {
player.y = platformTop - 40;
+ player.isOnPlatform = true;
player.bounce(platform.getBounceForce());
break;
}
}