User prompt
add a quality start menu to the game
User prompt
add a quality start menu to the game
User prompt
sometimes get nitro on the road ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
düşman arabalar haraket etsin ileri
User prompt
araba zaman geçtikçe hızlansın
User prompt
let the game be pixel art
Code edit (1 edits merged)
Please save this source code
User prompt
Highway Rush
Initial prompt
A simple top-down endless car game
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var EnemyCar = Container.expand(function (carType) { var self = Container.call(this); var assetId = carType || 'enemyCar1'; var carGraphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.lane = 0; self.update = function () { self.speed = 8 * gameSpeed; self.y += self.speed; }; return self; }); var Nitro = Container.expand(function () { var self = Container.call(this); var nitroGraphics = self.attachAsset('nitro', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.rotationSpeed = 0.2; self.pulseScale = 1; self.pulseDirection = 1; self.update = function () { self.y += self.speed; nitroGraphics.rotation += self.rotationSpeed; // Pulsing effect self.pulseScale += self.pulseDirection * 0.02; if (self.pulseScale > 1.3) { self.pulseDirection = -1; } else if (self.pulseScale < 0.8) { self.pulseDirection = 1; } nitroGraphics.scaleX = self.pulseScale; nitroGraphics.scaleY = self.pulseScale; }; return self; }); var PlayerCar = Container.expand(function () { var self = Container.call(this); var carGraphics = self.attachAsset('playerCar', { anchorX: 0.5, anchorY: 0.5 }); self.targetLane = 1; self.currentLane = 1; self.laneWidth = 400; self.moveSpeed = 0.15; self.update = function () { var targetX = self.getLaneX(self.targetLane); var diff = targetX - self.x; var adjustedMoveSpeed = self.moveSpeed * (1 + (gameSpeed - 1) * 0.5); if (Math.abs(diff) > 5) { self.x += diff * adjustedMoveSpeed; } else { self.x = targetX; self.currentLane = self.targetLane; } }; self.getLaneX = function (lane) { return 424 + lane * self.laneWidth; }; self.switchLane = function (direction) { var newLane = self.targetLane + direction; if (newLane >= 0 && newLane <= 3) { self.targetLane = newLane; } }; return self; }); var PowerUp = Container.expand(function () { var self = Container.call(this); var powerUpGraphics = self.attachAsset('powerUp', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.rotationSpeed = 0.1; self.update = function () { self.speed = 8 * gameSpeed; self.y += self.speed; powerUpGraphics.rotation += self.rotationSpeed; }; return self; }); var RoadLine = Container.expand(function () { var self = Container.call(this); var lineGraphics = self.attachAsset('roadLine', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 8; self.update = function () { self.speed = 8 * gameSpeed; self.y += self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c3e50 }); /**** * Game Code ****/ // Game state management var gameState = 'menu'; // 'menu', 'playing', 'gameOver' var menuElements = []; // Start menu creation function createStartMenu() { // Title var titleText = new Text2('HIGHWAY RUSH', { size: 120, fill: '#FFD700' }); titleText.anchor.set(0.5, 0.5); titleText.x = 1024; titleText.y = 800; game.addChild(titleText); menuElements.push(titleText); // Subtitle var subtitleText = new Text2('Endless Car Racing', { size: 60, fill: '#FFFFFF' }); subtitleText.anchor.set(0.5, 0.5); subtitleText.x = 1024; subtitleText.y = 920; game.addChild(subtitleText); menuElements.push(subtitleText); // Instructions var instructionsText = new Text2('Swipe or tap to change lanes\nAvoid traffic and collect power-ups!', { size: 50, fill: '#CCCCCC' }); instructionsText.anchor.set(0.5, 0.5); instructionsText.x = 1024; instructionsText.y = 1200; game.addChild(instructionsText); menuElements.push(instructionsText); // Play button background var playButtonBg = LK.getAsset('enemyCar3', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 0.8, x: 1024, y: 1500 }); playButtonBg.tint = 0x4CAF50; game.addChild(playButtonBg); menuElements.push(playButtonBg); // Play button text var playButtonText = new Text2('TAP TO PLAY', { size: 80, fill: '#FFFFFF' }); playButtonText.anchor.set(0.5, 0.5); playButtonText.x = 1024; playButtonText.y = 1500; game.addChild(playButtonText); menuElements.push(playButtonText); // Animate title with pulsing effect tween(titleText, { scaleX: 1.1, scaleY: 1.1 }, { duration: 1000, yoyo: true, repeat: -1 }); // Animate play button tween(playButtonBg, { scaleX: 2.1, scaleY: 0.85 }, { duration: 800, yoyo: true, repeat: -1 }); } function removeStartMenu() { for (var i = 0; i < menuElements.length; i++) { menuElements[i].destroy(); } menuElements = []; } function startGame() { gameState = 'playing'; removeStartMenu(); initializeGameplay(); } function initializeGameplay() { // Initialize all game variables gameSpeed = 1; spawnTimer = 0; spawnRate = 120; lineSpawnTimer = 0; powerUpSpawnTimer = 0; nitroSpawnTimer = 0; distanceTraveled = 0; nitroEffect = false; nitroEndTime = 0; // Reset score LK.setScore(0); } // Create start menu on game load createStartMenu(); var playerCar = game.addChild(new PlayerCar()); playerCar.x = 424 + 400; // Lane 1 playerCar.y = 2200; var enemyCars = []; var powerUps = []; var roadLines = []; var nitros = []; var gameSpeed = 1; var spawnTimer = 0; var spawnRate = 120; var lineSpawnTimer = 0; var powerUpSpawnTimer = 0; var nitroSpawnTimer = 0; var distanceTraveled = 0; var nitroEffect = false; var nitroEndTime = 0; // Create initial road lines for (var i = 0; i < 20; i++) { for (var lane = 0; lane < 4; lane++) { var line = game.addChild(new RoadLine()); line.x = 624 + lane * 400; // Between lanes line.y = i * 150 - 200; roadLines.push(line); } } // UI Elements var scoreTxt = new Text2('Distance: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var speedTxt = new Text2('Speed: 1x', { size: 60, fill: 0xFFFFFF }); speedTxt.anchor.set(1, 0); speedTxt.x = -20; speedTxt.y = 100; LK.gui.topRight.addChild(speedTxt); // Touch controls var touchStartX = 0; var touchStartTime = 0; game.down = function (x, y, obj) { if (gameState === 'menu') { // Any touch on menu starts the game startGame(); return; } touchStartX = x; touchStartTime = LK.ticks; }; game.up = function (x, y, obj) { if (gameState !== 'playing') return; var touchEndX = x; var swipeDistance = touchEndX - touchStartX; var touchDuration = LK.ticks - touchStartTime; // Detect swipe or tap if (Math.abs(swipeDistance) > 100 && touchDuration < 30) { // Swipe detected if (swipeDistance > 0) { playerCar.switchLane(1); // Swipe right } else { playerCar.switchLane(-1); // Swipe left } } else if (touchDuration < 15) { // Quick tap - determine direction based on screen side if (x > 1024) { playerCar.switchLane(1); // Right side tap } else { playerCar.switchLane(-1); // Left side tap } } }; function spawnEnemyCar() { var lane = Math.floor(Math.random() * 4); var carTypes = ['enemyCar1', 'enemyCar2', 'enemyCar3']; var carType = carTypes[Math.floor(Math.random() * carTypes.length)]; var enemy = game.addChild(new EnemyCar(carType)); enemy.x = 424 + lane * 400; enemy.y = -100; enemy.lane = lane; enemy.speed = 8 * gameSpeed; enemyCars.push(enemy); } function spawnPowerUp() { if (Math.random() < 0.3) { // 30% chance var lane = Math.floor(Math.random() * 4); var powerUp = game.addChild(new PowerUp()); powerUp.x = 424 + lane * 400; powerUp.y = -100; powerUp.speed = 8 * gameSpeed; powerUps.push(powerUp); } } function spawnNitro() { if (Math.random() < 0.2) { // 20% chance var lane = Math.floor(Math.random() * 4); var nitro = game.addChild(new Nitro()); nitro.x = 424 + lane * 400; nitro.y = -100; nitro.speed = 8 * gameSpeed; nitros.push(nitro); } } game.update = function () { // Only update game logic when playing if (gameState !== 'playing') return; // Update distance and speed distanceTraveled += gameSpeed; gameSpeed = 1 + distanceTraveled / 10000; scoreTxt.setText('Distance: ' + Math.floor(distanceTraveled)); speedTxt.setText('Speed: ' + gameSpeed.toFixed(1) + 'x'); // Spawn enemies spawnTimer++; if (spawnTimer >= spawnRate / gameSpeed) { spawnEnemyCar(); spawnTimer = 0; spawnRate = Math.max(60, spawnRate - 1); // Increase spawn rate } // Spawn power-ups powerUpSpawnTimer++; if (powerUpSpawnTimer >= 300 / gameSpeed) { spawnPowerUp(); powerUpSpawnTimer = 0; } // Spawn nitro nitroSpawnTimer++; if (nitroSpawnTimer >= 600 / gameSpeed) { spawnNitro(); nitroSpawnTimer = 0; } // Check nitro effect end if (nitroEffect && LK.ticks >= nitroEndTime) { nitroEffect = false; tween(playerCar, { scaleX: 1, scaleY: 1 }, { duration: 300 }); } // Spawn road lines lineSpawnTimer++; if (lineSpawnTimer >= 25) { for (var lane = 0; lane < 4; lane++) { var line = game.addChild(new RoadLine()); line.x = 624 + lane * 400; line.y = -100; line.speed = 8 * gameSpeed; roadLines.push(line); } lineSpawnTimer = 0; } // Update and check enemy cars for (var i = enemyCars.length - 1; i >= 0; i--) { var enemy = enemyCars[i]; if (enemy.lastY === undefined) enemy.lastY = enemy.y; // Remove off-screen enemies if (enemy.lastY < 2800 && enemy.y >= 2800) { enemy.destroy(); enemyCars.splice(i, 1); continue; } // Check collision with player if (enemy.intersects(playerCar)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } // Check for near miss (score bonus) var distanceFromPlayer = Math.abs(enemy.x - playerCar.x); if (enemy.y > playerCar.y - 150 && enemy.y < playerCar.y + 150 && distanceFromPlayer < 200 && distanceFromPlayer > 150) { if (!enemy.nearMissScored) { LK.setScore(LK.getScore() + 10); LK.getSound('dodge').play(); enemy.nearMissScored = true; } } enemy.lastY = enemy.y; } // Update and check power-ups for (var j = powerUps.length - 1; j >= 0; j--) { var powerUp = powerUps[j]; // Remove off-screen power-ups if (powerUp.y > 2800) { powerUp.destroy(); powerUps.splice(j, 1); continue; } // Check collection if (powerUp.intersects(playerCar)) { LK.setScore(LK.getScore() + 50); LK.getSound('collect').play(); LK.effects.flashObject(powerUp, 0xffffff, 200); powerUp.destroy(); powerUps.splice(j, 1); } } // Update and check nitros for (var n = nitros.length - 1; n >= 0; n--) { var nitro = nitros[n]; // Remove off-screen nitros if (nitro.y > 2800) { nitro.destroy(); nitros.splice(n, 1); continue; } // Check collection if (nitro.intersects(playerCar)) { LK.setScore(LK.getScore() + 100); LK.getSound('collect').play(); // Activate nitro effect nitroEffect = true; nitroEndTime = LK.ticks + 300; // 5 seconds at 60fps tween(playerCar, { scaleX: 1.3, scaleY: 1.3 }, { duration: 300 }); LK.effects.flashScreen(0x00ff00, 500); nitro.destroy(); nitros.splice(n, 1); } } // Update road lines for (var k = roadLines.length - 1; k >= 0; k--) { var line = roadLines[k]; // Remove off-screen lines if (line.y > 2800) { line.destroy(); roadLines.splice(k, 1); } } };
===================================================================
--- original.js
+++ change.js
@@ -116,8 +116,111 @@
/****
* Game Code
****/
+// Game state management
+var gameState = 'menu'; // 'menu', 'playing', 'gameOver'
+var menuElements = [];
+// Start menu creation
+function createStartMenu() {
+ // Title
+ var titleText = new Text2('HIGHWAY RUSH', {
+ size: 120,
+ fill: '#FFD700'
+ });
+ titleText.anchor.set(0.5, 0.5);
+ titleText.x = 1024;
+ titleText.y = 800;
+ game.addChild(titleText);
+ menuElements.push(titleText);
+ // Subtitle
+ var subtitleText = new Text2('Endless Car Racing', {
+ size: 60,
+ fill: '#FFFFFF'
+ });
+ subtitleText.anchor.set(0.5, 0.5);
+ subtitleText.x = 1024;
+ subtitleText.y = 920;
+ game.addChild(subtitleText);
+ menuElements.push(subtitleText);
+ // Instructions
+ var instructionsText = new Text2('Swipe or tap to change lanes\nAvoid traffic and collect power-ups!', {
+ size: 50,
+ fill: '#CCCCCC'
+ });
+ instructionsText.anchor.set(0.5, 0.5);
+ instructionsText.x = 1024;
+ instructionsText.y = 1200;
+ game.addChild(instructionsText);
+ menuElements.push(instructionsText);
+ // Play button background
+ var playButtonBg = LK.getAsset('enemyCar3', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 2,
+ scaleY: 0.8,
+ x: 1024,
+ y: 1500
+ });
+ playButtonBg.tint = 0x4CAF50;
+ game.addChild(playButtonBg);
+ menuElements.push(playButtonBg);
+ // Play button text
+ var playButtonText = new Text2('TAP TO PLAY', {
+ size: 80,
+ fill: '#FFFFFF'
+ });
+ playButtonText.anchor.set(0.5, 0.5);
+ playButtonText.x = 1024;
+ playButtonText.y = 1500;
+ game.addChild(playButtonText);
+ menuElements.push(playButtonText);
+ // Animate title with pulsing effect
+ tween(titleText, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 1000,
+ yoyo: true,
+ repeat: -1
+ });
+ // Animate play button
+ tween(playButtonBg, {
+ scaleX: 2.1,
+ scaleY: 0.85
+ }, {
+ duration: 800,
+ yoyo: true,
+ repeat: -1
+ });
+}
+function removeStartMenu() {
+ for (var i = 0; i < menuElements.length; i++) {
+ menuElements[i].destroy();
+ }
+ menuElements = [];
+}
+function startGame() {
+ gameState = 'playing';
+ removeStartMenu();
+ initializeGameplay();
+}
+function initializeGameplay() {
+ // Initialize all game variables
+ gameSpeed = 1;
+ spawnTimer = 0;
+ spawnRate = 120;
+ lineSpawnTimer = 0;
+ powerUpSpawnTimer = 0;
+ nitroSpawnTimer = 0;
+ distanceTraveled = 0;
+ nitroEffect = false;
+ nitroEndTime = 0;
+ // Reset score
+ LK.setScore(0);
+}
+// Create start menu on game load
+createStartMenu();
var playerCar = game.addChild(new PlayerCar());
playerCar.x = 424 + 400; // Lane 1
playerCar.y = 2200;
var enemyCars = [];
@@ -160,12 +263,18 @@
// Touch controls
var touchStartX = 0;
var touchStartTime = 0;
game.down = function (x, y, obj) {
+ if (gameState === 'menu') {
+ // Any touch on menu starts the game
+ startGame();
+ return;
+ }
touchStartX = x;
touchStartTime = LK.ticks;
};
game.up = function (x, y, obj) {
+ if (gameState !== 'playing') return;
var touchEndX = x;
var swipeDistance = touchEndX - touchStartX;
var touchDuration = LK.ticks - touchStartTime;
// Detect swipe or tap
@@ -218,8 +327,10 @@
nitros.push(nitro);
}
}
game.update = function () {
+ // Only update game logic when playing
+ if (gameState !== 'playing') return;
// Update distance and speed
distanceTraveled += gameSpeed;
gameSpeed = 1 + distanceTraveled / 10000;
scoreTxt.setText('Distance: ' + Math.floor(distanceTraveled));
pixel art ferrari bird's eye view. In-Game asset. 2d. High contrast. No shadows
pixel art tofaş bird's eye view. In-Game asset. 2d. High contrast. No shadows
pixel art Togg bird's eye view. In-Game asset. 2d. High contrast. No shadows
pixel art gas pedal bird's eye view. In-Game asset. 2d. High contrast. No shadows
pixel art nitro. In-Game asset. 2d. High contrast. No shadows
pixel art fantasy car bird's eye view. In-Game asset. 2d. High contrast. No shadows
pixel art straight line,. In-Game asset. 2d. High contrast. No shadows
Gold and Glory pixel art cup. In-Game asset. 2d. High contrast. No shadows
bugatti bolide pixel art bird's eye view. In-Game asset. 2d. High contrast. No shadows
BMW X6 pixel art bird's eye view. In-Game asset. 2d. High contrast. No shadows
pixel art joker. In-Game asset. 2d. High contrast. No shadows
düz sarı çizgi. In-Game asset. 2d. High contrast. No shadows
pixel art peter parker. In-Game asset. 2d. High contrast. No shadows
bird's eye pixel art motorcycle suzuki. In-Game asset. 2d. High contrast. No shadows