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 () {
// Apply horizontal movement
self.x += self.velocityX;
// Apply gravity
self.velocityY += 0.8;
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 = false;
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;
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) {
player.y = platformTop - 40;
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
@@ -1,6 +1,231 @@
-/****
+/****
+* 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 () {
+ // Apply horizontal movement
+ self.x += self.velocityX;
+ // Apply gravity
+ self.velocityY += 0.8;
+ 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 = false;
+ LK.getSound('bounce').play();
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ 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;
+ 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) {
+ player.y = platformTop - 40;
+ 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();
+ }
+};
\ No newline at end of file