Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
play the kalp sound when I collect hearts in the game
User prompt
play the araba sound when I collect car in the game
User prompt
play the kalp sound when I collect hearts in the game
User prompt
play the para sound when I collect coins in the game
User prompt
Use the hasar sound when he bumps into the anime girl.Use the hasar sound
User prompt
Use the damage sound when he bumps into the anime girl.Use the damage sound
User prompt
I'll start with one life at the beginning of the game
User prompt
remove the market from the game
User prompt
click on the market and the text we open will be in the lower right corner, when we are defeated, it will be under the play again text and
Code edit (7 edits merged)
Please save this source code
User prompt
the market should be in the bottom right corner and we can open it when we are defeated
User prompt
let's add a market
User prompt
always show our highest score when we lose ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
We'll only have three lives, we can't collect any more.
User prompt
Let's collect lives, but not too many lives.
Code edit (1 edits merged)
Please save this source code
User prompt
We get 3 lives and our lives will be shown as hearts in the right corner.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ // Player Car var Car = Container.expand(function () { var self = Container.call(this); var carAsset = self.attachAsset('car', { anchorX: 0.5, anchorY: 0.5 }); // For collision, use bounding box of carAsset self.width = carAsset.width; self.height = carAsset.height; // Lane: 0 (left), 1 (center), 2 (right) self.lane = 1; // Shield status self.hasShield = false; // Move to lane (0,1,2) self.moveToLane = function (lane) { self.lane = lane; // Animate to new x position var targetX = roadLeft + laneWidth * (lane + 0.5); tween(self, { x: targetX }, { duration: 120, easing: tween.cubicOut }); }; return self; }); // Coin (collectible) var Coin = Container.expand(function () { var self = Container.call(this); var coinAsset = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.width = coinAsset.width; self.height = coinAsset.height; self.lane = 1; self.setLane = function (lane, y) { self.lane = lane; self.x = roadLeft + laneWidth * (lane + 0.5); self.y = y; }; self.update = function () { self.y += game.roadSpeed; }; return self; }); // Extra Life (collectible) var ExtraLife = Container.expand(function () { var self = Container.call(this); var heartAsset = self.attachAsset('heart', { anchorX: 0.5, anchorY: 0.5 }); self.width = heartAsset.width; self.height = heartAsset.height; self.lane = 1; self.setLane = function (lane, y) { self.lane = lane; self.x = roadLeft + laneWidth * (lane + 0.5); self.y = y; }; self.update = function () { self.y += game.roadSpeed; }; return self; }); // Heart (lives display) var Heart = Container.expand(function () { var self = Container.call(this); var heartAsset = self.attachAsset('heart', { anchorX: 0.5, anchorY: 0.5 }); self.width = heartAsset.width; self.height = heartAsset.height; self.setPosition = function (index) { self.x = -120 * index; self.y = 200; }; return self; }); // Lane Divider var LaneDivider = Container.expand(function () { var self = Container.call(this); var dividerAsset = self.attachAsset('laneDivider', { anchorX: 0.5, anchorY: 0.5 }); self.width = dividerAsset.width; self.height = dividerAsset.height; // Set lane and position self.setLane = function (lane, y) { self.lane = lane; self.x = roadLeft + laneWidth * (lane + 1); self.y = y; }; // Update per tick self.update = function () { self.y += game.roadSpeed; // Loop to top if out of screen if (self.y > 2732 + self.height / 2) { self.y -= 2732 + self.height; } }; return self; }); // Market (in-game store) var Market = Container.expand(function () { var self = Container.call(this); // Background panel var bg = new Container(); var bgRect = LK.getAsset('shape', { width: 1800, height: 2000, color: 0x333333, shape: 'box', anchorX: 0.5, anchorY: 0.5, alpha: 0.9 }); bg.addChild(bgRect); self.addChild(bg); // Market title var titleText = new Text2('MARKET', { size: 140, fill: 0xFFDD44 }); titleText.anchor.set(0.5, 0); titleText.y = -900; self.addChild(titleText); // Coin display var coinDisplay = new Container(); var coinIcon = LK.getAsset('coin', { anchorX: 0.5, anchorY: 0.5, scale: 0.8 }); coinIcon.x = -100; coinDisplay.addChild(coinIcon); self.coinText = new Text2('0', { size: 80, fill: 0xFFFF00 }); self.coinText.anchor.set(0, 0.5); self.coinText.x = -50; coinDisplay.addChild(self.coinText); coinDisplay.y = -750; self.addChild(coinDisplay); // Close button var closeBtn = new Container(); var closeBtnBg = LK.getAsset('shape', { width: 120, height: 120, color: 0xFF5555, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); closeBtn.addChild(closeBtnBg); var closeText = new Text2('X', { size: 80, fill: 0xFFFFFF }); closeText.anchor.set(0.5, 0.5); closeBtn.addChild(closeText); closeBtn.x = 800; closeBtn.y = -900; // Close button interaction closeBtn.interactive = true; closeBtn.down = function () { self.hide(); }; self.addChild(closeBtn); // Store items container self.itemsContainer = new Container(); self.itemsContainer.y = -400; self.addChild(self.itemsContainer); // Create store items self.items = [{ id: 'extraLife', name: 'Extra Life', price: 100, description: 'Buy an extra life' }, { id: 'speedBoost', name: 'Speed Boost', price: 50, description: 'Increase road speed' }, { id: 'shield', name: 'Shield', price: 1, description: 'Temporary invincibility' }]; // Create item display for (var i = 0; i < self.items.length; i++) { var item = self.items[i]; var itemContainer = new Container(); // Item background var itemBg = LK.getAsset('shape', { width: 1600, height: 300, color: 0x555555, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); itemContainer.addChild(itemBg); // Item name var nameText = new Text2(item.name, { size: 80, fill: 0xFFFFFF }); nameText.anchor.set(0, 0.5); nameText.x = -750; itemContainer.addChild(nameText); // Item description var descText = new Text2(item.description, { size: 50, fill: 0xCCCCCC }); descText.anchor.set(0, 0.5); descText.x = -750; descText.y = 80; itemContainer.addChild(descText); // Price display var priceContainer = new Container(); var coinIcon = LK.getAsset('coin', { anchorX: 0.5, anchorY: 0.5, scale: 0.6 }); coinIcon.x = -40; priceContainer.addChild(coinIcon); var priceText = new Text2(item.price.toString(), { size: 60, fill: 0xFFFF00 }); priceText.anchor.set(0, 0.5); priceContainer.addChild(priceText); priceContainer.x = 500; itemContainer.addChild(priceContainer); // Buy button var buyBtn = new Container(); buyBtn.itemId = item.id; buyBtn.price = item.price; var buyBtnBg = LK.getAsset('shape', { width: 200, height: 100, color: 0x44AA44, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); buyBtn.addChild(buyBtnBg); var buyText = new Text2('BUY', { size: 60, fill: 0xFFFFFF }); buyText.anchor.set(0.5, 0.5); buyBtn.addChild(buyText); buyBtn.x = 700; buyBtn.interactive = true; buyBtn.down = function () { self.buyItem(this.itemId, this.price); }; itemContainer.addChild(buyBtn); itemContainer.y = i * 350; self.itemsContainer.addChild(itemContainer); } // Buy item function self.buyItem = function (itemId, price) { if (coinCount >= price) { // Purchase successful coinCount -= price; coinTxt.setText(coinCount); self.coinText.setText(coinCount); // Apply item effect switch (itemId) { case 'extraLife': if (lives < maxLives) { lives++; var heart = new Heart(); heart.setPosition(hearts.length); hearts.push(heart); heartsContainer.addChild(heart); LK.effects.flashScreen(0x00ff00, 400); } break; case 'speedBoost': game.roadSpeed += 5; if (game.roadSpeed > maxRoadSpeed) { game.roadSpeed = maxRoadSpeed; } LK.effects.flashScreen(0x0088ff, 400); break; case 'shield': car.alpha = 0.5; car.hasShield = true; LK.setTimeout(function () { car.alpha = 1; car.hasShield = false; }, 5000); LK.effects.flashScreen(0x00ffff, 400); break; } } else { // Not enough coins LK.effects.flashScreen(0xff0000, 400); } }; // Show/hide functions self.show = function () { self.visible = true; self.coinText.setText(coinCount); game.marketOpen = true; }; self.hide = function () { self.visible = false; game.marketOpen = false; // Remove the game over button if it exists for (var i = 0; i < self.children.length; i++) { var child = self.children[i]; if (child && child.children && child.children[1] && child.children[1].text === 'CONTINUE') { child.destroy(); break; } } }; // Initial state is hidden self.visible = false; return self; }); // Obstacle (other cars/roadblocks) var Obstacle = Container.expand(function () { var self = Container.call(this); var obsAsset = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.5 }); self.width = obsAsset.width; self.height = obsAsset.height; // Lane: 0,1,2 self.lane = 1; // Set lane and position self.setLane = function (lane, y) { self.lane = lane; self.x = roadLeft + laneWidth * (lane + 0.5); self.y = y; }; // Update per tick self.update = function () { self.y += game.roadSpeed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222222 }); /**** * Game Code ****/ // Lane divider - white thin rectangle // Road - gray rectangle, wide enough for 3 lanes // Obstacle - red rectangle (other cars/roadblocks) // Car (player) - blue rectangle, rear facing player // Road parameters var roadWidth = 1200; var roadLeft = (2048 - roadWidth) / 2; var laneCount = 3; var laneWidth = roadWidth / laneCount; // Add road background var road = LK.getAsset('road', { anchorX: 0, anchorY: 0 }); road.x = roadLeft; road.y = 0; game.addChild(road); // Lane dividers (2 between 3 lanes, repeated vertically) var laneDividers = []; var dividerCount = Math.ceil(2732 / 400) + 2; for (var l = 0; l < laneCount - 1; l++) { for (var i = 0; i < dividerCount; i++) { var divider = new LaneDivider(); divider.setLane(l, i * 400); laneDividers.push(divider); game.addChild(divider); } } // Player car var car = new Car(); car.y = 2732 - 400; car.moveToLane(1); // Start in center lane car.x = roadLeft + laneWidth * 1.5; game.addChild(car); // Obstacles array var obstacles = []; // Coins array var coins = []; // Extra Lives array var extraLives = []; // Maximum lives allowed var maxLives = 3; // Score var score = 0; var highScore = storage.highScore || 0; var scoreTxt = new Text2('0', { size: 120, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // High Score text var highScoreTxt = new Text2('High Score: ' + highScore, { size: 80, fill: 0xFFDD44 }); highScoreTxt.anchor.set(0.5, 0); highScoreTxt.y = 140; highScoreTxt.visible = false; LK.gui.top.addChild(highScoreTxt); // Coin counter var coinCount = 0; var coinTxt = new Text2('0', { size: 100, fill: 0xFFFF00 }); coinTxt.anchor.set(1, 0); // right-top coinTxt.x = 0; coinTxt.y = 40; LK.gui.topRight.addChild(coinTxt); // Lives system var lives = 3; var hearts = []; var heartsContainer = new Container(); heartsContainer.x = -20; heartsContainer.y = 0; LK.gui.topRight.addChild(heartsContainer); // Create hearts for lives display for (var i = 0; i < lives; i++) { var heart = new Heart(); heart.setPosition(i); hearts.push(heart); heartsContainer.addChild(heart); } // Game state game.roadSpeed = 16; // Initial speed (pixels per frame) var minRoadSpeed = 16; var maxRoadSpeed = 38; var speedIncreaseInterval = 600; // ticks between speed increases var lastSpeedIncreaseTick = 0; var obstacleInterval = 60; // ticks between obstacles var lastObstacleTick = 0; var gameOver = false; // Create market button var marketBtn = new Container(); var marketBtnBg = LK.getAsset('shape', { width: 220, height: 120, color: 0x44AA44, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); marketBtn.addChild(marketBtnBg); var marketText = new Text2('SHOP', { size: 80, fill: 0xFFFFFF }); marketText.anchor.set(0.5, 0.5); marketBtn.addChild(marketText); marketBtn.x = 0; marketBtn.y = 120; marketBtn.interactive = true; marketBtn.down = function () { if (!gameOver && !game.marketOpen) { market.show(); } }; LK.gui.topRight.addChild(marketBtn); // Create and initialize market var market = new Market(); market.x = 2048 - 900; market.y = 2732 - 400; game.marketOpen = false; game.addChild(market); // Reset high score visibility and market button when game starts highScoreTxt.visible = false; marketBtn.visible = true; // Touch/drag handling var dragStartX = null; var dragStartLane = null; var dragActive = false; // Helper: get lane from x function getLaneFromX(x) { var relX = x - roadLeft; var lane = Math.floor(relX / laneWidth); if (lane < 0) { lane = 0; } if (lane > laneCount - 1) { lane = laneCount - 1; } return lane; } // Helper: clamp lane function clampLane(lane) { if (lane < 0) { return 0; } if (lane > laneCount - 1) { return laneCount - 1; } return lane; } // Handle swipe left/right to change lanes game.down = function (x, y, obj) { if (gameOver) { return; } dragStartX = x; dragStartLane = car.lane; dragActive = true; }; game.move = function (x, y, obj) { if (!dragActive || gameOver) { return; } var dx = x - dragStartX; // If drag exceeds 120px, move lane if (Math.abs(dx) > 120) { var dir = dx > 0 ? 1 : -1; var newLane = clampLane(dragStartLane + dir); if (newLane !== car.lane) { car.moveToLane(newLane); dragActive = false; // Only allow one lane change per swipe } } }; game.up = function (x, y, obj) { dragActive = false; }; // Main update loop game.update = function () { if (gameOver) { // Hide market button when game is over (market will be shown automatically) marketBtn.visible = false; if (!game.marketOpen) { return; } } else if (game.marketOpen) { return; } // Update lane dividers for (var i = 0; i < laneDividers.length; i++) { laneDividers[i].update(); } // Update obstacles for (var i = obstacles.length - 1; i >= 0; i--) { var obs = obstacles[i]; obs.update(); // Remove if off screen if (obs.y - obs.height / 2 > 2732) { obs.destroy(); obstacles.splice(i, 1); continue; } // Collision with car if (obs.intersects(car)) { // Check if player has shield if (car.hasShield) { // Shield absorbs the hit car.hasShield = false; car.alpha = 1; // Flash screen cyan to show shield absorbed hit LK.effects.flashScreen(0x00ffff, 400); // Remove this obstacle obs.destroy(); obstacles.splice(i, 1); continue; } // No shield, take damage // Flash screen red LK.effects.flashScreen(0xff0000, 800); // Reduce lives lives--; // Remove one heart if (hearts.length > 0) { var heart = hearts.pop(); heart.destroy(); } // If no more lives, game over if (lives <= 0) { gameOver = true; // Update high score if current score is higher if (score > highScore) { highScore = score; storage.highScore = highScore; } // Show high score text highScoreTxt.setText('High Score: ' + highScore); highScoreTxt.visible = true; // Show market instead of immediate game over market.show(); // Add a button to continue to game over var gameOverBtn = new Container(); var gameOverBtnBg = LK.getAsset('shape', { width: 400, height: 120, color: 0xDD3333, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); gameOverBtn.addChild(gameOverBtnBg); var gameOverText = new Text2('CONTINUE', { size: 80, fill: 0xFFFFFF }); gameOverText.anchor.set(0.5, 0.5); gameOverBtn.addChild(gameOverText); gameOverBtn.x = 0; gameOverBtn.y = 700; gameOverBtn.interactive = true; gameOverBtn.down = function () { market.hide(); LK.showGameOver(); }; market.addChild(gameOverBtn); return; } else { // Remove this obstacle obs.destroy(); obstacles.splice(i, 1); // Brief invulnerability period car.alpha = 0.5; LK.setTimeout(function () { car.alpha = 1; }, 1500); continue; } } } // Update coins for (var i = coins.length - 1; i >= 0; i--) { var coin = coins[i]; coin.update(); // Remove if off screen if (coin.y - coin.height / 2 > 2732) { coin.destroy(); coins.splice(i, 1); continue; } // Collect coin if (coin.intersects(car)) { score += 10; scoreTxt.setText(score); coinCount += 1; coinTxt.setText(coinCount); coin.destroy(); coins.splice(i, 1); continue; } } // Update extra lives for (var i = extraLives.length - 1; i >= 0; i--) { var extraLife = extraLives[i]; extraLife.update(); // Remove if off screen if (extraLife.y - extraLife.height / 2 > 2732) { extraLife.destroy(); extraLives.splice(i, 1); continue; } // Collect extra life if (extraLife.intersects(car)) { if (lives < maxLives) { // Add a life lives++; // Add heart display var heart = new Heart(); heart.setPosition(hearts.length); hearts.push(heart); heartsContainer.addChild(heart); // Flash green to indicate positive effect LK.effects.flashScreen(0x00ff00, 400); } else { // Too many lives - penalize score score -= 20; if (score < 0) { score = 0; } scoreTxt.setText(score); // Flash yellow to indicate warning LK.effects.flashScreen(0xffff00, 400); } extraLife.destroy(); extraLives.splice(i, 1); continue; } } // Spawn obstacles if (LK.ticks - lastObstacleTick >= obstacleInterval) { lastObstacleTick = LK.ticks; // Randomly pick 1 or 2 lanes to spawn obstacles var lanesToBlock = []; var blockCount = Math.random() < 0.7 ? 1 : 2; while (lanesToBlock.length < blockCount) { var lane = Math.floor(Math.random() * laneCount); var already = false; for (var j = 0; j < lanesToBlock.length; j++) { if (lanesToBlock[j] === lane) { already = true; } } if (!already) { lanesToBlock.push(lane); } } for (var k = 0; k < lanesToBlock.length; k++) { var obs = new Obstacle(); obs.setLane(lanesToBlock[k], -obs.height / 2); obstacles.push(obs); game.addChild(obs); } // Spawn coins in lanes not blocked by obstacles for (var laneIdx = 0; laneIdx < laneCount; laneIdx++) { var blocked = false; for (var b = 0; b < lanesToBlock.length; b++) { if (lanesToBlock[b] === laneIdx) { blocked = true; } } if (!blocked) { // Spawn extra life (5% chance if below max lives) if (lives < maxLives && Math.random() < 0.05) { var extraLife = new ExtraLife(); extraLife.setLane(laneIdx, -extraLife.height / 2 - 120); extraLives.push(extraLife); game.addChild(extraLife); } // Spawn coin (70% chance if not spawning extra life) else if (Math.random() < 0.7) { var coin = new Coin(); // Place coin a bit ahead of obstacles coin.setLane(laneIdx, -coin.height / 2 - 120); coins.push(coin); game.addChild(coin); } } } } // Increase speed and difficulty over time if (LK.ticks - lastSpeedIncreaseTick >= speedIncreaseInterval) { lastSpeedIncreaseTick = LK.ticks; if (game.roadSpeed < maxRoadSpeed) { game.roadSpeed += 2; if (game.roadSpeed > maxRoadSpeed) { game.roadSpeed = maxRoadSpeed; } } if (obstacleInterval > 28) { obstacleInterval -= 4; if (obstacleInterval < 28) { obstacleInterval = 28; } } } // Score: increase by 1 every 10 ticks if (LK.ticks % 10 === 0) { score += 1; scoreTxt.setText(score); } };
===================================================================
--- original.js
+++ change.js
@@ -497,9 +497,9 @@
LK.gui.topRight.addChild(marketBtn);
// Create and initialize market
var market = new Market();
market.x = 2048 - 900;
-market.y = 2732 - 1000;
+market.y = 2732 - 400;
game.marketOpen = false;
game.addChild(market);
// Reset high score visibility and market button when game starts
highScoreTxt.visible = false;
@@ -636,9 +636,9 @@
});
gameOverText.anchor.set(0.5, 0.5);
gameOverBtn.addChild(gameOverText);
gameOverBtn.x = 0;
- gameOverBtn.y = 500;
+ gameOverBtn.y = 700;
gameOverBtn.interactive = true;
gameOverBtn.down = function () {
market.hide();
LK.showGameOver();
pixel art car top view In-Game asset. 2d. High contrast. No shadows
pixel art coin 2d. In-Game asset. 2d. High contrast. No shadows
pixel art 2d road 3 lane top view
pixel art 2d road 3 lane top view no lane
pixel art 2d white anime girl In-Game asset. 2d. High contrast. No shadows
pixel art 2d heart. In-Game asset. 2d. High contrast. No shadows