User prompt
make jump logic to "hold for longer jump"
User prompt
add a jump system where you can jump above obstacles if player wants to
User prompt
make the game's background a road
User prompt
allow player to use all of the game's screen
User prompt
still some coins are combined into obstacles fix it
User prompt
some coins are combined into obstacles fix it
Code edit (1 edits merged)
Please save this source code
User prompt
Infinite Dash
Initial prompt
make a endless runner game
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Coin var Coin = Container.expand(function () { var self = Container.call(this); var coinGfx = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); // Lane: 0,1,2 self.lane = 1; // For collision detection self.isCoin = true; return self; }); // Obstacle var Obstacle = Container.expand(function () { var self = Container.call(this); var obsGfx = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); // Lane: 0,1,2 self.lane = 1; // For collision detection self.isObstacle = true; return self; }); // Runner (player character) var Runner = Container.expand(function () { var self = Container.call(this); var runnerGfx = self.attachAsset('runner', { anchorX: 0.5, anchorY: 0.5 }); // Current lane: 0 (left), 1 (center), 2 (right) self.lane = 1; // Move to lane (0,1,2) self.moveToLane = function (lane, duration) { self.lane = lane; var targetX = laneToX(lane); tween(self, { x: targetX }, { duration: duration || 120, easing: tween.cubicOut }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Coin: Yellow ellipse // Obstacle: Gray box // Character: Red box // --- ROAD BACKGROUND --- var roadBg1 = LK.getAsset('road', { anchorX: 0.5, anchorY: 0 }); roadBg1.x = 2048 / 2; roadBg1.y = 0; game.addChild(roadBg1); var roadBg2 = LK.getAsset('road', { anchorX: 0.5, anchorY: 0 }); roadBg2.x = 2048 / 2; roadBg2.y = -2732; game.addChild(roadBg2); // --- LANE SYSTEM --- var NUM_LANES = 3; var LANE_WIDTH = 2048 / NUM_LANES; // Use full width var LANE_START_X = LANE_WIDTH / 2; // Center of first lane at left edge function laneToX(lane) { // lane: 0 (left), 1 (center), 2 (right) return LANE_START_X + lane * LANE_WIDTH; } // --- GAMEPLAY VARIABLES --- var runner; var obstacles = []; var coins = []; var speed = 18; // Initial speed (pixels per frame) var speedIncrease = 0.012; // Speed up per tick var spawnTimer = 0; var coinSpawnTimer = 0; var minObstacleGap = 420; // Minimum vertical gap between obstacles var lastObstacleY = 0; var isGameOver = false; // --- SCORE --- var score = 0; var scoreTxt = new Text2('0', { size: 120, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // --- INIT RUNNER --- runner = new Runner(); runner.y = 2732 - 400; runner.x = laneToX(1); runner.lane = 1; game.addChild(runner); // --- INPUT HANDLING --- var dragStartX = null; var dragStartLane = null; var dragActive = false; function handleMove(x, y, obj) { if (dragActive && dragStartX !== null) { var dx = x - dragStartX; if (Math.abs(dx) > 120) { // Swipe detected if (dx > 0 && runner.lane < NUM_LANES - 1) { runner.moveToLane(runner.lane + 1); dragStartX = x; } else if (dx < 0 && runner.lane > 0) { runner.moveToLane(runner.lane - 1); dragStartX = x; } } } } game.move = handleMove; game.down = function (x, y, obj) { dragActive = true; dragStartX = x; dragStartLane = runner.lane; }; game.up = function (x, y, obj) { dragActive = false; dragStartX = null; dragStartLane = null; }; // --- TAP TO MOVE (for single taps) --- game.tap = function (x, y, obj) { // Not supported by LK, so handled via down/up quick tap // (No implementation needed) }; // --- SPAWN OBSTACLES & COINS --- function spawnObstacle() { var lane = Math.floor(Math.random() * NUM_LANES); var obs = new Obstacle(); obs.lane = lane; obs.x = laneToX(lane); obs.y = -180; obstacles.push(obs); game.addChild(obs); lastObstacleY = obs.y; } function spawnCoin() { // Prevent coins from spawning in the same lane and too close to obstacles, and at the same Y as obstacles var availableLanes = [0, 1, 2]; var coinSpawnY = -120; // Remove lanes with obstacles too close to spawn Y or at the same Y for (var i = 0; i < obstacles.length; i++) { var obs = obstacles[i]; // If obstacle is in the same lane and within 320px vertically of coin spawn Y (-120) if (Math.abs(obs.y - coinSpawnY) < 320) { var idx = availableLanes.indexOf(obs.lane); if (idx !== -1) availableLanes.splice(idx, 1); } // Prevent coin from spawning at the same Y as any obstacle (even in other lanes) if (Math.abs(obs.y - coinSpawnY) < 1) { // If any obstacle is at the same Y, skip coin spawn entirely return; } } if (availableLanes.length === 0) return; // No safe lane, skip coin spawn var lane = availableLanes[Math.floor(Math.random() * availableLanes.length)]; var coin = new Coin(); coin.lane = lane; coin.x = laneToX(lane); coin.y = coinSpawnY; coins.push(coin); game.addChild(coin); } // --- COLLISION DETECTION --- function checkCollision(a, b) { // Simple AABB var dx = Math.abs(a.x - b.x); var dy = Math.abs(a.y - b.y); var aw = a.width || 180, ah = a.height || 180; var bw = b.width || 180, bh = b.height || 180; return dx < aw / 2 + bw / 2 - 20 && dy < ah / 2 + bh / 2 - 20; } // --- GAME LOOP --- game.update = function () { if (isGameOver) return; // Scroll road background roadBg1.y += speed; roadBg2.y += speed; // Loop backgrounds if (roadBg1.y >= 2732) { roadBg1.y = roadBg2.y - 2732; } if (roadBg2.y >= 2732) { roadBg2.y = roadBg1.y - 2732; } // Increase speed speed += speedIncrease; // Move obstacles for (var i = obstacles.length - 1; i >= 0; i--) { var obs = obstacles[i]; obs.y += speed; if (obs.y > 2732 + 200) { obs.destroy(); obstacles.splice(i, 1); continue; } // Collision with runner if (checkCollision(obs, runner)) { isGameOver = true; LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); return; } } // Move coins for (var j = coins.length - 1; j >= 0; j--) { var coin = coins[j]; coin.y += speed; if (coin.y > 2732 + 120) { coin.destroy(); coins.splice(j, 1); continue; } // Collision with runner if (checkCollision(coin, runner)) { // Collect coin score += 1; LK.setScore(score); scoreTxt.setText(score); LK.effects.flashObject(coin, 0xffff00, 200); coin.destroy(); coins.splice(j, 1); continue; } } // Spawn obstacles spawnTimer -= speed; if (spawnTimer <= 0) { spawnObstacle(); // Next spawn in 700-1100 px spawnTimer = minObstacleGap + Math.floor(Math.random() * 400); } // Spawn coins coinSpawnTimer -= speed; if (coinSpawnTimer <= 0) { spawnCoin(); // Next coin in 400-900 px coinSpawnTimer = 400 + Math.floor(Math.random() * 500); } }; // --- RESET ON GAME OVER --- game.on('destroy', function () { // Clean up arrays for (var i = 0; i < obstacles.length; i++) { obstacles[i].destroy(); } for (var j = 0; j < coins.length; j++) { coins[j].destroy(); } obstacles = []; coins = []; isGameOver = false; speed = 18; score = 0; LK.setScore(0); scoreTxt.setText('0'); runner.x = laneToX(1); runner.lane = 1; runner.y = 2732 - 400; spawnTimer = 0; coinSpawnTimer = 0; roadBg1.y = 0; roadBg2.y = -2732; });
===================================================================
--- original.js
+++ change.js
@@ -67,8 +67,23 @@
****/
// Coin: Yellow ellipse
// Obstacle: Gray box
// Character: Red box
+// --- ROAD BACKGROUND ---
+var roadBg1 = LK.getAsset('road', {
+ anchorX: 0.5,
+ anchorY: 0
+});
+roadBg1.x = 2048 / 2;
+roadBg1.y = 0;
+game.addChild(roadBg1);
+var roadBg2 = LK.getAsset('road', {
+ anchorX: 0.5,
+ anchorY: 0
+});
+roadBg2.x = 2048 / 2;
+roadBg2.y = -2732;
+game.addChild(roadBg2);
// --- LANE SYSTEM ---
var NUM_LANES = 3;
var LANE_WIDTH = 2048 / NUM_LANES; // Use full width
var LANE_START_X = LANE_WIDTH / 2; // Center of first lane at left edge
@@ -187,8 +202,18 @@
}
// --- GAME LOOP ---
game.update = function () {
if (isGameOver) return;
+ // Scroll road background
+ roadBg1.y += speed;
+ roadBg2.y += speed;
+ // Loop backgrounds
+ if (roadBg1.y >= 2732) {
+ roadBg1.y = roadBg2.y - 2732;
+ }
+ if (roadBg2.y >= 2732) {
+ roadBg2.y = roadBg1.y - 2732;
+ }
// Increase speed
speed += speedIncrease;
// Move obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
@@ -263,5 +288,7 @@
runner.lane = 1;
runner.y = 2732 - 400;
spawnTimer = 0;
coinSpawnTimer = 0;
+ roadBg1.y = 0;
+ roadBg2.y = -2732;
});
\ No newline at end of file
Pixel, 2d, Coin. In-Game asset. 2d. High contrast. No shadows
container, 2d, pixel. In-Game asset. 2d. High contrast. No shadows
character with a hat, 2d, pixel,. 2d. High contrast. No shadows
road, pixel, 2d. In-Game asset. 2d. High contrast. No shadows. In-Game asset
indicator, pixel, 2d. In-Game asset. 2d. High contrast. No shadows
Start button, pixel art. In-Game asset. 2d. High contrast. No shadows
how to play button, orange outline, white text, pixel art. In-Game asset. 2d. High contrast. No shadows
restart button, orange outline, white text, pixel art.. In-Game asset. 2d. High contrast. No shadows