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 last position for collision detection
self.lastY = self.y;
// Store current platform if on one
var currentPlatform = null;
if (self.isOnPlatform) {
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;
var playerBottom = self.y + 40;
var platformTop = platform.y - 10;
if (Math.abs(playerBottom - platformTop) <= 5 && 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;
}
// Auto-jump when standing on platform
if (self.isOnPlatform && self.velocityY >= 0) {
// Check if we're on the starting platform
var onStartingPlatform = false;
if (currentPlatform && currentPlatform.isStartingPlatform) {
onStartingPlatform = true;
}
// Auto-jump every 30 ticks (0.5 seconds) when standing still, but not on starting platform
if (LK.ticks % 30 === 0 && !onStartingPlatform) {
self.velocityY = -15; // Auto-jump force
self.isOnPlatform = false;
LK.getSound('bounce').play();
} else {
// Don't apply gravity when standing on platform
self.velocityY = Math.max(0, self.velocityY);
}
} 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.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;
var fallStartTime = null;
var isFalling = 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 = 2560; // Position player on top of the starting platform (2600 - 40 = 2560)
player.isOnPlatform = true; // Start on platform
// 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
var startingPlatform = createPlatform(1024, 2600, 'normal');
startingPlatform.isStartingPlatform = true;
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() {
// Check for platform collision when falling
if (player.velocityY > 0) {
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
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 landing on platform from above
if (playerBottom >= platformTop && playerBottom <= platformTop + 25 && playerRight > platformLeft && playerLeft < platformRight && player.lastY + 40 <= platformTop) {
player.y = platformTop - 40;
player.isOnPlatform = true;
player.velocityY = 0; // Stop falling, don't auto-bounce
// Only bounce on bounce platforms
if (platform.platformType === 'bounce') {
player.bounce(platform.getBounceForce());
}
return;
}
}
}
// Check if player is still on a platform (for standing)
if (player.velocityY >= 0) {
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
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 standing on platform
if (Math.abs(playerBottom - platformTop) <= 5 && playerRight > platformLeft && playerLeft < platformRight) {
player.y = platformTop - 40;
player.isOnPlatform = true;
player.velocityY = Math.max(0, player.velocityY); // Prevent falling through
return;
}
}
}
// If no platform found, player is not on platform
player.isOnPlatform = false;
}
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();
// Track falling state
var wasOnPlatform = player.isOnPlatform;
var currentlyFalling = player.velocityY > 0 && !player.isOnPlatform;
// Start fall timer when player starts falling
if (!isFalling && currentlyFalling) {
isFalling = true;
fallStartTime = LK.ticks;
}
// Reset fall timer when player lands or bounces up
if (isFalling && (!currentlyFalling || player.velocityY < 0)) {
isFalling = false;
fallStartTime = null;
}
// Check for 2-second fall timer (120 ticks = 2 seconds at 60 FPS)
if (isFalling && fallStartTime !== null && LK.ticks - fallStartTime >= 120) {
LK.getSound('fall').play();
LK.showGameOver();
}
// 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
@@ -74,10 +74,15 @@
self.x += currentPlatform.moveDirection * currentPlatform.moveSpeed;
}
// Auto-jump when standing on platform
if (self.isOnPlatform && self.velocityY >= 0) {
- // Auto-jump every 30 ticks (0.5 seconds) when standing still
- if (LK.ticks % 30 === 0) {
+ // Check if we're on the starting platform
+ var onStartingPlatform = false;
+ if (currentPlatform && currentPlatform.isStartingPlatform) {
+ onStartingPlatform = true;
+ }
+ // Auto-jump every 30 ticks (0.5 seconds) when standing still, but not on starting platform
+ if (LK.ticks % 30 === 0 && !onStartingPlatform) {
self.velocityY = -15; // Auto-jump force
self.isOnPlatform = false;
LK.getSound('bounce').play();
} else {
@@ -158,9 +163,10 @@
game.addChild(platform);
return platform;
}
// Generate initial platforms
-createPlatform(1024, 2600, 'normal');
+var startingPlatform = createPlatform(1024, 2600, 'normal');
+startingPlatform.isStartingPlatform = true;
for (var i = 0; i < 15; i++) {
var x = Math.random() * 1600 + 200;
var y = nextPlatformY - Math.random() * 150 - 100;
var platformType = 'normal';