User prompt
Delete ground and recode it because this is a parkour game and there needs to be space in between
User prompt
Place a border at the end of the finishLine and when the player touches it, he is eliminated.
User prompt
At the beginning and when you pass to finishLine, put a 3-second timer and the game will start after 3 seconds. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Keep distance between coins and spikes
User prompt
Increase the spacing between spikes. Enlarge the platform and increase the distance from one platform to another. Two platforms should not be next to each other and should not touch each other. Reduce the spike spawn rate.
User prompt
Make game over menu
User prompt
Oyuncu hızını arttır, oyuncuyu küçült, platform yatay uzunluğunu arttır ve bir platform ile başka bir platform aralığı 85 yap
User prompt
Bir platform başka bir platform ile en az 50 px uzaklıkta olmalı
User prompt
Add to player more speed and make objets bigger
User prompt
Make coins and player more bigger
User prompt
Make lava infinite
User prompt
Platformun aşağısına lav koy ve yerçekimini düzelt
User prompt
Make objects bigger
User prompt
Aşağı düşünce ölsün
Code edit (1 edits merged)
Please save this source code
User prompt
Cube Rush - 2D Parkour Adventure
Initial prompt
Cube parkour game 2d
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.update = function () {
if (!self.collected) {
coinGraphics.rotation += 0.1;
}
};
return self;
});
var DeathBorder = Container.expand(function () {
var self = Container.call(this);
var borderGraphics = self.attachAsset('deathBorder', {
anchorX: 0.5,
anchorY: 1.0
});
return self;
});
var FinishLine = Container.expand(function () {
var self = Container.call(this);
var finishGraphics = self.attachAsset('finishLine', {
anchorX: 0.5,
anchorY: 1.0
});
return self;
});
var Lava = Container.expand(function () {
var self = Container.call(this);
var lavaGraphics = self.attachAsset('lava', {
anchorX: 0,
anchorY: 0
});
return self;
});
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
self.velocityY = 0;
self.isGrounded = false;
self.jumpForce = -20;
self.gravity = 0.8;
self.groundY = 0;
self.isJumping = false;
self.jump = function () {
if (self.isGrounded) {
self.velocityY = self.jumpForce;
self.isGrounded = false;
self.isJumping = true;
LK.getSound('jump').play();
}
};
self.strongJump = function () {
if (self.isGrounded) {
self.velocityY = self.jumpForce * 1.5;
self.isGrounded = false;
self.isJumping = true;
LK.getSound('jump').play();
}
};
self.update = function () {
// Apply gravity
if (!self.isGrounded) {
self.velocityY += self.gravity;
}
// Update position
self.y += self.velocityY;
// Platform collision detection is handled in main game loop
};
return self;
});
var Spike = Container.expand(function () {
var self = Container.call(this);
var spikeGraphics = self.attachAsset('spike', {
anchorX: 0.5,
anchorY: 1.0
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game variables
var player;
var platforms = [];
var spikes = [];
var coins = [];
var finishLine;
var deathBorder;
var cameraOffsetX = 0;
var gameSpeed = 16;
var currentLevel = storage.currentLevel || 1;
var levelComplete = false;
var isJumpPressed = false;
var jumpHoldTime = 0;
var maxJumpHoldTime = 15;
var gameStarted = false;
var countdownActive = false;
var countdownNumber = 3;
// UI Elements
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
scoreTxt.x = 50;
scoreTxt.y = 50;
LK.gui.topLeft.addChild(scoreTxt);
var levelTxt = new Text2('Level: ' + currentLevel, {
size: 60,
fill: 0xFFFFFF
});
levelTxt.anchor.set(1, 0);
levelTxt.x = -50;
levelTxt.y = 50;
LK.gui.topRight.addChild(levelTxt);
var countdownTxt = new Text2('3', {
size: 200,
fill: 0xFFFFFF
});
countdownTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(countdownTxt);
countdownTxt.alpha = 0;
// Initialize player
player = game.addChild(new Player());
player.x = 300;
player.y = 2200;
player.groundY = 2200;
// Level generation function
function generateLevel() {
// Clear existing level elements
for (var i = platforms.length - 1; i >= 0; i--) {
platforms[i].destroy();
}
for (var i = spikes.length - 1; i >= 0; i--) {
spikes[i].destroy();
}
for (var i = coins.length - 1; i >= 0; i--) {
coins[i].destroy();
}
if (finishLine) {
finishLine.destroy();
}
if (deathBorder) {
deathBorder.destroy();
}
platforms = [];
spikes = [];
coins = [];
// Generate floating platforms with gaps
var levelLength = 3000 + currentLevel * 500;
var currentX = 200;
var baseY = 2300;
var allSpikePositions = [];
// Create starting platform
var startPlatform = game.addChild(new Platform());
startPlatform.x = 200;
startPlatform.y = baseY;
platforms.push(startPlatform);
currentX = 700; // Start next platforms after gap
while (currentX < levelLength) {
// Vary platform heights
var platformY = baseY + (Math.random() - 0.5) * 300;
// Create platform
var platform = game.addChild(new Platform());
platform.x = currentX;
platform.y = platformY;
platforms.push(platform);
// Track spikes on this platform
var platformSpikes = [];
// Add spikes on some platforms (reduced spawn rate)
if (currentX > 500 && Math.random() < 0.2 + currentLevel * 0.05) {
var spike = game.addChild(new Spike());
spike.x = currentX;
spike.y = platformY - 40;
spikes.push(spike);
platformSpikes.push(spike.x);
allSpikePositions.push(spike.x);
}
// Add coins with minimum distance from spikes
if (Math.random() < 0.6) {
var coinX = currentX + (Math.random() - 0.5) * 150;
var coinY = platformY - 120 - Math.random() * 80;
// Check distance from all spikes
var validPosition = true;
for (var s = 0; s < allSpikePositions.length; s++) {
if (Math.abs(coinX - allSpikePositions[s]) < 250) {
validPosition = false;
break;
}
}
// Only place coin if it's far enough from spikes
if (validPosition) {
var coin = game.addChild(new Coin());
coin.x = coinX;
coin.y = coinY;
coins.push(coin);
}
}
// Create significant gaps between platforms for parkour gameplay
currentX += 400 + Math.random() * 300;
}
// Add infinite lava background
var lavaY = 2500;
var lavaX = 0;
while (lavaX < levelLength + 2048) {
var lava = game.addChild(new Lava());
lava.x = lavaX;
lava.y = lavaY;
lavaX += 2048; // Move to next lava tile position
}
// Create finish platform
var finishPlatform = game.addChild(new Platform());
finishPlatform.x = levelLength - 200;
finishPlatform.y = baseY;
platforms.push(finishPlatform);
// Add finish line
finishLine = game.addChild(new FinishLine());
finishLine.x = levelLength - 200;
finishLine.y = baseY - 40;
// Add death border at the end of finish line
deathBorder = game.addChild(new DeathBorder());
deathBorder.x = levelLength + 50;
deathBorder.y = baseY - 40;
// Reset player position
player.x = 200;
player.y = baseY - 100;
player.velocityY = 0;
player.isGrounded = true;
player.groundY = baseY;
cameraOffsetX = 0;
levelComplete = false;
startCountdown();
}
// Input handling
game.down = function (x, y, obj) {
isJumpPressed = true;
jumpHoldTime = 0;
};
game.up = function (x, y, obj) {
if (isJumpPressed) {
if (jumpHoldTime < 5) {
player.jump();
} else {
player.strongJump();
}
isJumpPressed = false;
jumpHoldTime = 0;
}
};
// Game update loop
game.update = function () {
if (levelComplete || !gameStarted || countdownActive) return;
// Handle jump input
if (isJumpPressed) {
jumpHoldTime++;
if (jumpHoldTime >= maxJumpHoldTime) {
player.strongJump();
isJumpPressed = false;
jumpHoldTime = 0;
}
}
// Move player forward automatically
player.x += gameSpeed;
// Update camera
cameraOffsetX = player.x - 400;
game.x = -cameraOffsetX;
// Check platform collision
var onPlatform = false;
var platformCollisionTolerance = 50;
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
// Check if player is above platform and within horizontal bounds
if (player.x > platform.x - 200 && player.x < platform.x + 200 && player.y >= platform.y - platformCollisionTolerance && player.y <= platform.y + 50 && player.velocityY >= 0) {
player.groundY = platform.y - 40;
onPlatform = true;
// Land on platform
if (player.y >= player.groundY) {
player.y = player.groundY;
player.velocityY = 0;
player.isGrounded = true;
player.isJumping = false;
}
break;
}
}
if (!onPlatform) {
player.isGrounded = false;
}
// Check spike collision
for (var i = 0; i < spikes.length; i++) {
var spike = spikes[i];
if (player.intersects(spike)) {
LK.getSound('death').play();
LK.effects.flashScreen(0xff0000, 500);
resetLevel();
return;
}
}
// Check death border collision
if (deathBorder && player.intersects(deathBorder)) {
LK.getSound('death').play();
LK.effects.flashScreen(0xff0000, 500);
resetLevel();
return;
}
// Check coin collection
for (var i = 0; i < coins.length; i++) {
var coin = coins[i];
if (!coin.collected && player.intersects(coin)) {
coin.collected = true;
coin.alpha = 0;
LK.setScore(LK.getScore() + 10);
scoreTxt.setText('Score: ' + LK.getScore());
LK.getSound('coin').play();
}
}
// Check finish line
if (finishLine && player.intersects(finishLine)) {
levelComplete = true;
currentLevel++;
storage.currentLevel = currentLevel;
levelTxt.setText('Level: ' + currentLevel);
// Flash screen green and generate next level
LK.effects.flashScreen(0x00ff00, 1000);
LK.setTimeout(function () {
generateLevel();
}, 1000);
}
// Check if player fell into lava or fell below ground level
if (player.y > 2500 || player.y > player.groundY + 100) {
LK.getSound('death').play();
LK.effects.flashScreen(0xff0000, 500);
resetLevel();
}
};
function startCountdown() {
countdownActive = true;
gameStarted = false;
countdownNumber = 3;
countdownTxt.setText(countdownNumber.toString());
countdownTxt.alpha = 1;
countdownTxt.scaleX = 1;
countdownTxt.scaleY = 1;
function nextCountdown() {
// Scale up and fade out current number
tween(countdownTxt, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
countdownNumber--;
if (countdownNumber > 0) {
// Show next number
countdownTxt.setText(countdownNumber.toString());
countdownTxt.alpha = 1;
countdownTxt.scaleX = 1;
countdownTxt.scaleY = 1;
LK.setTimeout(nextCountdown, 200);
} else {
// Show GO! and start game
countdownTxt.setText('GO!');
countdownTxt.alpha = 1;
countdownTxt.scaleX = 1;
countdownTxt.scaleY = 1;
tween(countdownTxt, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
countdownActive = false;
gameStarted = true;
}
});
}
}
});
}
LK.setTimeout(nextCountdown, 200);
}
function resetLevel() {
LK.showGameOver();
}
// Game reset function (called when game restarts)
function resetGame() {
currentLevel = 1;
storage.currentLevel = currentLevel;
LK.setScore(0);
scoreTxt.setText('Score: 0');
levelTxt.setText('Level: ' + currentLevel);
generateLevel();
}
// Initialize first level
generateLevel(); ===================================================================
--- original.js
+++ change.js
@@ -36,21 +36,21 @@
anchorY: 1.0
});
return self;
});
-var Ground = Container.expand(function () {
+var Lava = Container.expand(function () {
var self = Container.call(this);
- var groundGraphics = self.attachAsset('ground', {
+ var lavaGraphics = self.attachAsset('lava', {
anchorX: 0,
anchorY: 0
});
return self;
});
-var Lava = Container.expand(function () {
+var Platform = Container.expand(function () {
var self = Container.call(this);
- var lavaGraphics = self.attachAsset('lava', {
- anchorX: 0,
- anchorY: 0
+ var platformGraphics = self.attachAsset('platform', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
return self;
});
var Player = Container.expand(function () {
@@ -87,15 +87,9 @@
self.velocityY += self.gravity;
}
// Update position
self.y += self.velocityY;
- // Ground collision
- if (self.y >= self.groundY) {
- self.y = self.groundY;
- self.velocityY = 0;
- self.isGrounded = true;
- self.isJumping = false;
- }
+ // Platform collision detection is handled in main game loop
};
return self;
});
var Spike = Container.expand(function () {
@@ -118,9 +112,9 @@
* Game Code
****/
// Game variables
var player;
-var grounds = [];
+var platforms = [];
var spikes = [];
var coins = [];
var finishLine;
var deathBorder;
@@ -165,10 +159,10 @@
player.groundY = 2200;
// Level generation function
function generateLevel() {
// Clear existing level elements
- for (var i = grounds.length - 1; i >= 0; i--) {
- grounds[i].destroy();
+ for (var i = platforms.length - 1; i >= 0; i--) {
+ platforms[i].destroy();
}
for (var i = spikes.length - 1; i >= 0; i--) {
spikes[i].destroy();
}
@@ -180,39 +174,49 @@
}
if (deathBorder) {
deathBorder.destroy();
}
- grounds = [];
+ platforms = [];
spikes = [];
coins = [];
- // Generate ground platforms
- var groundY = 2300;
- var currentX = 0;
+ // Generate floating platforms with gaps
var levelLength = 3000 + currentLevel * 500;
+ var currentX = 200;
+ var baseY = 2300;
+ var allSpikePositions = [];
+ // Create starting platform
+ var startPlatform = game.addChild(new Platform());
+ startPlatform.x = 200;
+ startPlatform.y = baseY;
+ platforms.push(startPlatform);
+ currentX = 700; // Start next platforms after gap
while (currentX < levelLength) {
- var ground = game.addChild(new Ground());
- ground.x = currentX;
- ground.y = groundY;
- grounds.push(ground);
- // Track positions of spikes and coins on this platform
+ // Vary platform heights
+ var platformY = baseY + (Math.random() - 0.5) * 300;
+ // Create platform
+ var platform = game.addChild(new Platform());
+ platform.x = currentX;
+ platform.y = platformY;
+ platforms.push(platform);
+ // Track spikes on this platform
var platformSpikes = [];
- var platformCoins = [];
// Add spikes on some platforms (reduced spawn rate)
- if (currentX > 500 && Math.random() < 0.15 + currentLevel * 0.05) {
+ if (currentX > 500 && Math.random() < 0.2 + currentLevel * 0.05) {
var spike = game.addChild(new Spike());
- spike.x = currentX + 150 + Math.random() * 200;
- spike.y = groundY;
+ spike.x = currentX;
+ spike.y = platformY - 40;
spikes.push(spike);
platformSpikes.push(spike.x);
+ allSpikePositions.push(spike.x);
}
// Add coins with minimum distance from spikes
- if (Math.random() < 0.4) {
- var coinX = currentX + 50 + Math.random() * 100;
- var coinY = groundY - 100 - Math.random() * 100;
- // Check distance from all spikes on this platform
+ if (Math.random() < 0.6) {
+ var coinX = currentX + (Math.random() - 0.5) * 150;
+ var coinY = platformY - 120 - Math.random() * 80;
+ // Check distance from all spikes
var validPosition = true;
- for (var s = 0; s < platformSpikes.length; s++) {
- if (Math.abs(coinX - platformSpikes[s]) < 300) {
+ for (var s = 0; s < allSpikePositions.length; s++) {
+ if (Math.abs(coinX - allSpikePositions[s]) < 250) {
validPosition = false;
break;
}
}
@@ -221,16 +225,12 @@
var coin = game.addChild(new Coin());
coin.x = coinX;
coin.y = coinY;
coins.push(coin);
- platformCoins.push(coinX);
}
}
- currentX += 150 + Math.random() * 100;
- // Create gaps between platforms (ensuring minimum distance)
- if (currentX < levelLength - 500 && Math.random() < 0.4) {
- currentX += 200 + Math.random() * 150;
- }
+ // Create significant gaps between platforms for parkour gameplay
+ currentX += 400 + Math.random() * 300;
}
// Add infinite lava background
var lavaY = 2500;
var lavaX = 0;
@@ -239,21 +239,27 @@
lava.x = lavaX;
lava.y = lavaY;
lavaX += 2048; // Move to next lava tile position
}
+ // Create finish platform
+ var finishPlatform = game.addChild(new Platform());
+ finishPlatform.x = levelLength - 200;
+ finishPlatform.y = baseY;
+ platforms.push(finishPlatform);
// Add finish line
finishLine = game.addChild(new FinishLine());
- finishLine.x = levelLength - 100;
- finishLine.y = groundY;
+ finishLine.x = levelLength - 200;
+ finishLine.y = baseY - 40;
// Add death border at the end of finish line
deathBorder = game.addChild(new DeathBorder());
deathBorder.x = levelLength + 50;
- deathBorder.y = groundY;
+ deathBorder.y = baseY - 40;
// Reset player position
- player.x = 300;
- player.y = 2200;
+ player.x = 200;
+ player.y = baseY - 100;
player.velocityY = 0;
player.isGrounded = true;
+ player.groundY = baseY;
cameraOffsetX = 0;
levelComplete = false;
startCountdown();
}
@@ -289,20 +295,29 @@
player.x += gameSpeed;
// Update camera
cameraOffsetX = player.x - 400;
game.x = -cameraOffsetX;
- // Check ground collision
- var onGround = false;
- for (var i = 0; i < grounds.length; i++) {
- var ground = grounds[i];
- if (player.x + 90 > ground.x && player.x - 90 < ground.x + 800 && player.y >= ground.y - 10 && player.y <= ground.y + 100) {
- player.groundY = ground.y;
- onGround = true;
+ // Check platform collision
+ var onPlatform = false;
+ var platformCollisionTolerance = 50;
+ for (var i = 0; i < platforms.length; i++) {
+ var platform = platforms[i];
+ // Check if player is above platform and within horizontal bounds
+ if (player.x > platform.x - 200 && player.x < platform.x + 200 && player.y >= platform.y - platformCollisionTolerance && player.y <= platform.y + 50 && player.velocityY >= 0) {
+ player.groundY = platform.y - 40;
+ onPlatform = true;
+ // Land on platform
+ if (player.y >= player.groundY) {
+ player.y = player.groundY;
+ player.velocityY = 0;
+ player.isGrounded = true;
+ player.isJumping = false;
+ }
break;
}
}
- if (!onGround) {
- player.groundY = 2600; // Fall into lava
+ if (!onPlatform) {
+ player.isGrounded = false;
}
// Check spike collision
for (var i = 0; i < spikes.length; i++) {
var spike = spikes[i];