User prompt
Display score on screen
User prompt
Great call! Let’s add a score system that increases over time and when collecting coins. I’ll show you how to: 1. Add score tracking 2. Display it on screen 3. Update it during gameplay
User prompt
Add assets Zig-Zag Cars – Occasionally switch between lanes
User prompt
Add assets Normal Cars – Standard speed, easy to dodge
User prompt
Add another enemy assets Fast Cars Move quicker, appear less frequently
User prompt
Adjust the position of slow truck within the road
User prompt
Slow truck not move out of the road within the road boundary
User prompt
Add new asset for Slow Trucks – Big size, block more space but enough space for player
User prompt
Add a Police Car enemy assets Follows the player’s lane for a few seconds
User prompt
Types of Enemy Cars You Can Add: 1. Normal Cars – Standard speed, easy to dodge 2. Fast Cars – Move quicker, appear less frequently 3. Slow Trucks – Big size, block more space 4. Zig-Zag Cars – Occasionally switch between lanes 5. Police Car – Follows the player’s lane for a few seconds
Code edit (1 edits merged)
Please save this source code
User prompt
Road Dash
Initial prompt
Player car that moves forward 3 roads vertically stacked Swipe to switch roads Tap right side to accelerate Here’s the prompt you can use: > "Create a top-down endless driving game. The player controls a car that auto-moves forward on one of 3 roads. Swiping on the left side of the screen moves the car up or down between roads. Tapping on the right side of the screen temporarily increases the car's speed. Add other cars as obstacles and coins to collect. Use FRVR (UpIt.com) style JavaScript components." --- Step 2: Add Core Mechanics Prompt Once the base is generated, you can expand with: > "Add collision detection: if the player car hits another car, game over. If it collects a coin, increase the score. Spawn obstacles and coins randomly on different roads." --- Step 3: UI and Game Flow Prompt To generate score, UI, and restart functionality: > "Add a scoring system with score UI at the top. Show coins collected. Add a game over screen with a restart button." --- Step 4: Polishing Prompt Then improve with: > "Add smooth animations when switching roads. Add sound effects for acceleration, coin collection, and crashing. Make the game mobile-friendly."
/**** 
* Plugins
****/ 
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
	highScore: 0
});
/**** 
* Classes
****/ 
var BoostButton = Container.expand(function () {
	var self = Container.call(this);
	var buttonGraphics = self.attachAsset('boostButton', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0.5
	});
	self.down = function () {
		buttonGraphics.alpha = 0.8;
		if (player && !player.boosting) {
			player.boost();
		}
	};
	self.up = function () {
		buttonGraphics.alpha = 0.5;
	};
	return self;
});
var Coin = Container.expand(function () {
	var self = Container.call(this);
	var coinGraphics = self.attachAsset('coin', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.width = coinGraphics.width;
	self.height = coinGraphics.height;
	self.lane = 0;
	self.speed = 0;
	self.setup = function (lane, speed) {
		self.lane = lane;
		self.speed = speed;
		self.x = getLanePosition(lane);
		self.y = -self.height;
	};
	self.update = function () {
		self.y += self.speed;
		// Add a spinning effect to the coin
		coinGraphics.rotation += 0.05;
	};
	return self;
});
var EnemyCar = Container.expand(function () {
	var self = Container.call(this);
	var carGraphics = self.attachAsset('enemyCar', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.width = carGraphics.width;
	self.height = carGraphics.height;
	self.lane = 0;
	self.speed = 0;
	self.setup = function (lane, speed) {
		self.lane = lane;
		self.speed = speed;
		self.x = getLanePosition(lane);
		self.y = -self.height;
	};
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
var FastCar = Container.expand(function () {
	var self = Container.call(this);
	var carGraphics = self.attachAsset('enemyCar', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.width = carGraphics.width;
	self.height = carGraphics.height;
	self.lane = 0;
	self.speed = 0;
	self.setup = function (lane, speed) {
		self.lane = lane;
		self.speed = speed * 1.5; // Fast cars move quicker
		self.x = getLanePosition(lane);
		self.y = -self.height;
	};
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
var NormalCar = Container.expand(function () {
	var self = Container.call(this);
	var carGraphics = self.attachAsset('enemyCar', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.width = carGraphics.width;
	self.height = carGraphics.height;
	self.lane = 0;
	self.speed = 0;
	self.setup = function (lane, speed) {
		self.lane = lane;
		self.speed = speed;
		self.x = getLanePosition(lane);
		self.y = -self.height;
	};
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
var PlayerCar = Container.expand(function () {
	var self = Container.call(this);
	var carGraphics = self.attachAsset('playerCar', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.lane = 1; // 0=left, 1=middle, 2=right
	self.width = carGraphics.width;
	self.height = carGraphics.height;
	self.moving = false;
	self.boosting = false;
	self.boostTime = 0;
	self.boostDuration = 120; // 2 seconds at 60 fps
	self.switchLane = function (targetLane) {
		if (self.moving || targetLane < 0 || targetLane > 2) {
			return;
		}
		self.moving = true;
		var targetX = getLanePosition(targetLane);
		tween(self, {
			x: targetX
		}, {
			duration: 300,
			easing: tween.easeInOut,
			onFinish: function onFinish() {
				self.lane = targetLane;
				self.moving = false;
			}
		});
	};
	self.boost = function () {
		if (self.boosting) {
			return;
		}
		self.boosting = true;
		self.boostTime = self.boostDuration;
		LK.getSound('boost').play();
	};
	self.update = function () {
		if (self.boosting) {
			self.boostTime--;
			if (self.boostTime <= 0) {
				self.boosting = false;
			}
		}
	};
	return self;
});
var PoliceCar = Container.expand(function () {
	var self = Container.call(this);
	var carGraphics = self.attachAsset('enemyCar', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.width = carGraphics.width;
	self.height = carGraphics.height;
	self.lane = 0;
	self.speed = 0;
	self.setup = function (lane, speed) {
		self.lane = lane;
		self.speed = speed;
		self.x = getLanePosition(lane);
		self.y = -self.height;
	};
	self.update = function () {
		self.y += self.speed;
		// Follow player's lane for a few seconds
		if (Math.random() < 0.01) {
			self.lane = player.lane;
			self.x = getLanePosition(self.lane);
		}
	};
	return self;
});
var Road = Container.expand(function () {
	var self = Container.call(this);
	var roadGraphics = self.attachAsset('road', {
		anchorX: 0.5,
		anchorY: 0
	});
	self.laneWidth = roadGraphics.width;
	// Create road lines
	self.lines = [];
	var lineCount = 15;
	var lineSpacing = 2732 / lineCount;
	for (var i = 0; i < lineCount; i++) {
		var line = self.addChild(LK.getAsset('roadLine', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: 0,
			y: i * lineSpacing
		}));
		self.lines.push(line);
	}
	self.speed = 10;
	self.update = function () {
		// Animate the road lines
		for (var i = 0; i < self.lines.length; i++) {
			self.lines[i].y += self.speed;
			// Reset line position when it goes off screen
			if (self.lines[i].y > 2732) {
				self.lines[i].y = 0;
			}
		}
	};
	return self;
});
var SlowTruck = Container.expand(function () {
	var self = Container.call(this);
	var truckGraphics = self.attachAsset('enemyCar', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.width = truckGraphics.width * 1.5; // Trucks are larger
	self.height = truckGraphics.height * 1.5;
	self.lane = 0;
	self.speed = 0;
	self.setup = function (lane, speed) {
		self.lane = lane;
		self.speed = speed * 0.5; // Slow trucks move slower
		self.x = getLanePosition(lane);
		self.y = -self.height;
	};
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
var ZigZagCar = Container.expand(function () {
	var self = Container.call(this);
	var carGraphics = self.attachAsset('enemyCar', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.width = carGraphics.width;
	self.height = carGraphics.height;
	self.lane = 0;
	self.speed = 0;
	self.setup = function (lane, speed) {
		self.lane = lane;
		self.speed = speed;
		self.x = getLanePosition(lane);
		self.y = -self.height;
	};
	self.update = function () {
		self.y += self.speed;
		// Occasionally switch lanes
		if (Math.random() < 0.01) {
			var newLane = (self.lane + 1) % 3;
			self.x = getLanePosition(newLane);
			self.lane = newLane;
		}
	};
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x85C1E9
});
/**** 
* Game Code
****/ 
// Game variables
var player;
var roads = [];
var enemies = [];
var coins = [];
var boostButton;
var baseSpeed = 10;
var score = 0;
var startX, direction;
var spawnTimer = 0;
var spawnInterval = 60; // Spawn an object every second (60 frames)
var difficultyTimer = 0;
var difficultyInterval = 600; // Increase difficulty every 10 seconds
var roadWidth = 240;
var lanePositions = [];
var gameRunning = false;
var scoreText;
var highScoreText;
// Helper function to get the x-position for a lane
function getLanePosition(lane) {
	return lanePositions[lane];
}
// Initialize game elements
function initGame() {
	// Set background
	game.setBackgroundColor(0x85C1E9);
	// Initialize lane positions
	var screenCenter = 2048 / 2;
	lanePositions = [screenCenter - roadWidth, screenCenter, screenCenter + roadWidth];
	// Create roads
	for (var i = 0; i < 3; i++) {
		var road = new Road();
		road.x = lanePositions[i];
		roads.push(road);
		game.addChild(road);
	}
	// Create player car
	player = new PlayerCar();
	player.x = lanePositions[1]; // Start in middle lane
	player.y = 2732 - 500; // Position near bottom of screen
	game.addChild(player);
	// Create boost button
	boostButton = new BoostButton();
	boostButton.x = 2048 - 200;
	boostButton.y = 2732 - 200;
	game.addChild(boostButton);
	// Initialize score
	score = 0;
	// Setup score text
	scoreText = new Text2('Score: 0', {
		size: 80,
		fill: 0xFFFFFF
	});
	scoreText.anchor.set(0, 0);
	LK.gui.topRight.addChild(scoreText);
	// Setup high score text
	highScoreText = new Text2('Best: ' + storage.highScore, {
		size: 60,
		fill: 0xFFFFFF
	});
	highScoreText.anchor.set(0, 0);
	highScoreText.y = 90;
	LK.gui.topRight.addChild(highScoreText);
	// Reset game state
	enemies = [];
	coins = [];
	baseSpeed = 10;
	spawnTimer = 0;
	difficultyTimer = 0;
	gameRunning = true;
	// Start background music
	LK.playMusic('bgmusic', {
		fade: {
			start: 0,
			end: 0.4,
			duration: 1000
		}
	});
}
// Spawn objects (enemies or coins)
function spawnObject() {
	var lane = Math.floor(Math.random() * 3);
	// 30% chance to spawn a coin, 70% chance for enemy car
	if (Math.random() < 0.3) {
		var coin = new Coin();
		coin.setup(lane, baseSpeed);
		coins.push(coin);
		game.addChild(coin);
	} else {
		var enemyType = Math.random();
		var enemy;
		if (enemyType < 0.2) {
			enemy = new NormalCar();
		} else if (enemyType < 0.4) {
			enemy = new FastCar();
		} else if (enemyType < 0.6) {
			enemy = new SlowTruck();
		} else if (enemyType < 0.8) {
			enemy = new ZigZagCar();
		} else {
			enemy = new PoliceCar();
		}
		enemy.setup(lane, baseSpeed * 0.8);
		enemies.push(enemy);
		game.addChild(enemy);
	}
}
// Check for collisions
function checkCollisions() {
	if (!player) {
		return;
	}
	// Check for collision with enemies
	for (var i = enemies.length - 1; i >= 0; i--) {
		if (player.intersects(enemies[i])) {
			// Game over on collision
			LK.getSound('crash').play();
			LK.effects.flashScreen(0xFF0000, 500);
			// Update high score if needed
			if (score > storage.highScore) {
				storage.highScore = score;
				highScoreText.setText('Best: ' + storage.highScore);
			}
			// Show game over
			LK.stopMusic();
			LK.showGameOver();
			gameRunning = false;
			return;
		}
	}
	// Check for collision with coins
	for (var j = coins.length - 1; j >= 0; j--) {
		if (player.intersects(coins[j])) {
			// Collect coin
			score += 10;
			scoreText.setText('Score: ' + score);
			LK.getSound('coinCollect').play();
			LK.effects.flashObject(coins[j], 0xFFFFFF, 200);
			coins[j].destroy();
			coins.splice(j, 1);
		}
	}
}
// Update function for game logic
game.update = function () {
	if (!gameRunning) {
		return;
	}
	// Update road and player
	for (var i = 0; i < roads.length; i++) {
		var speedMultiplier = player.boosting ? 2 : 1;
		roads[i].speed = baseSpeed * speedMultiplier;
		roads[i].update();
	}
	player.update();
	// Spawn objects
	spawnTimer++;
	if (spawnTimer >= spawnInterval) {
		spawnObject();
		spawnTimer = 0;
	}
	// Increase difficulty over time
	difficultyTimer++;
	if (difficultyTimer >= difficultyInterval) {
		baseSpeed += 1;
		spawnInterval = Math.max(30, spawnInterval - 3); // Speed up spawning but not below 0.5 seconds
		difficultyTimer = 0;
		// Add points for surviving longer
		score += 5;
		scoreText.setText('Score: ' + score);
	}
	// Update enemies
	for (var j = enemies.length - 1; j >= 0; j--) {
		var speedMultiplier = player.boosting ? 2 : 1;
		enemies[j].speed = baseSpeed * 0.8 * speedMultiplier;
		enemies[j].update();
		// Remove enemies that are off screen
		if (enemies[j].y > 2732 + enemies[j].height) {
			enemies[j].destroy();
			enemies.splice(j, 1);
			// Add points for each car you pass
			score += 1;
			scoreText.setText('Score: ' + score);
		}
	}
	// Update coins
	for (var k = coins.length - 1; k >= 0; k--) {
		var speedMultiplier = player.boosting ? 2 : 1;
		coins[k].speed = baseSpeed * 0.8 * speedMultiplier;
		coins[k].update();
		// Remove coins that are off screen
		if (coins[k].y > 2732 + coins[k].height) {
			coins[k].destroy();
			coins.splice(k, 1);
		}
	}
	// Check for collisions
	checkCollisions();
};
// Touch handling for lane changes
game.down = function (x, y) {
	if (!gameRunning) {
		return;
	}
	// Left half of screen is for lane switching
	if (x < 2048 / 2) {
		startX = x;
		direction = null;
	}
};
game.move = function (x, y) {
	if (!gameRunning || !startX) {
		return;
	}
	// Left half of screen is for lane switching
	if (startX < 2048 / 2) {
		var deltaX = x - startX;
		// Determine swipe direction if it's significant enough
		if (Math.abs(deltaX) > 50) {
			direction = deltaX > 0 ? 'right' : 'left';
		}
	}
};
game.up = function (x, y) {
	if (!gameRunning) {
		return;
	}
	// Left half of screen is for lane switching
	if (startX < 2048 / 2 && direction) {
		if (direction === 'left' && player.lane > 0) {
			player.switchLane(player.lane - 1);
		} else if (direction === 'right' && player.lane < 2) {
			player.switchLane(player.lane + 1);
		}
	}
	startX = null;
	direction = null;
};
// Initialize the game
initGame(); ===================================================================
--- original.js
+++ change.js
@@ -70,8 +70,50 @@
 		self.y += self.speed;
 	};
 	return self;
 });
+var FastCar = Container.expand(function () {
+	var self = Container.call(this);
+	var carGraphics = self.attachAsset('enemyCar', {
+		anchorX: 0.5,
+		anchorY: 0.5
+	});
+	self.width = carGraphics.width;
+	self.height = carGraphics.height;
+	self.lane = 0;
+	self.speed = 0;
+	self.setup = function (lane, speed) {
+		self.lane = lane;
+		self.speed = speed * 1.5; // Fast cars move quicker
+		self.x = getLanePosition(lane);
+		self.y = -self.height;
+	};
+	self.update = function () {
+		self.y += self.speed;
+	};
+	return self;
+});
+var NormalCar = Container.expand(function () {
+	var self = Container.call(this);
+	var carGraphics = self.attachAsset('enemyCar', {
+		anchorX: 0.5,
+		anchorY: 0.5
+	});
+	self.width = carGraphics.width;
+	self.height = carGraphics.height;
+	self.lane = 0;
+	self.speed = 0;
+	self.setup = function (lane, speed) {
+		self.lane = lane;
+		self.speed = speed;
+		self.x = getLanePosition(lane);
+		self.y = -self.height;
+	};
+	self.update = function () {
+		self.y += self.speed;
+	};
+	return self;
+});
 var PlayerCar = Container.expand(function () {
 	var self = Container.call(this);
 	var carGraphics = self.attachAsset('playerCar', {
 		anchorX: 0.5,
@@ -118,8 +160,34 @@
 		}
 	};
 	return self;
 });
+var PoliceCar = Container.expand(function () {
+	var self = Container.call(this);
+	var carGraphics = self.attachAsset('enemyCar', {
+		anchorX: 0.5,
+		anchorY: 0.5
+	});
+	self.width = carGraphics.width;
+	self.height = carGraphics.height;
+	self.lane = 0;
+	self.speed = 0;
+	self.setup = function (lane, speed) {
+		self.lane = lane;
+		self.speed = speed;
+		self.x = getLanePosition(lane);
+		self.y = -self.height;
+	};
+	self.update = function () {
+		self.y += self.speed;
+		// Follow player's lane for a few seconds
+		if (Math.random() < 0.01) {
+			self.lane = player.lane;
+			self.x = getLanePosition(self.lane);
+		}
+	};
+	return self;
+});
 var Road = Container.expand(function () {
 	var self = Container.call(this);
 	var roadGraphics = self.attachAsset('road', {
 		anchorX: 0.5,
@@ -151,8 +219,56 @@
 		}
 	};
 	return self;
 });
+var SlowTruck = Container.expand(function () {
+	var self = Container.call(this);
+	var truckGraphics = self.attachAsset('enemyCar', {
+		anchorX: 0.5,
+		anchorY: 0.5
+	});
+	self.width = truckGraphics.width * 1.5; // Trucks are larger
+	self.height = truckGraphics.height * 1.5;
+	self.lane = 0;
+	self.speed = 0;
+	self.setup = function (lane, speed) {
+		self.lane = lane;
+		self.speed = speed * 0.5; // Slow trucks move slower
+		self.x = getLanePosition(lane);
+		self.y = -self.height;
+	};
+	self.update = function () {
+		self.y += self.speed;
+	};
+	return self;
+});
+var ZigZagCar = Container.expand(function () {
+	var self = Container.call(this);
+	var carGraphics = self.attachAsset('enemyCar', {
+		anchorX: 0.5,
+		anchorY: 0.5
+	});
+	self.width = carGraphics.width;
+	self.height = carGraphics.height;
+	self.lane = 0;
+	self.speed = 0;
+	self.setup = function (lane, speed) {
+		self.lane = lane;
+		self.speed = speed;
+		self.x = getLanePosition(lane);
+		self.y = -self.height;
+	};
+	self.update = function () {
+		self.y += self.speed;
+		// Occasionally switch lanes
+		if (Math.random() < 0.01) {
+			var newLane = (self.lane + 1) % 3;
+			self.x = getLanePosition(newLane);
+			self.lane = newLane;
+		}
+	};
+	return self;
+});
 
 /**** 
 * Initialize Game
 ****/ 
@@ -251,10 +367,22 @@
 		coin.setup(lane, baseSpeed);
 		coins.push(coin);
 		game.addChild(coin);
 	} else {
-		var enemy = new EnemyCar();
-		enemy.setup(lane, baseSpeed * 0.8); // Enemies move a bit slower than the road
+		var enemyType = Math.random();
+		var enemy;
+		if (enemyType < 0.2) {
+			enemy = new NormalCar();
+		} else if (enemyType < 0.4) {
+			enemy = new FastCar();
+		} else if (enemyType < 0.6) {
+			enemy = new SlowTruck();
+		} else if (enemyType < 0.8) {
+			enemy = new ZigZagCar();
+		} else {
+			enemy = new PoliceCar();
+		}
+		enemy.setup(lane, baseSpeed * 0.8);
 		enemies.push(enemy);
 		game.addChild(enemy);
 	}
 }
:quality(85)/https://cdn.frvr.ai/67f429cff9699d20fcacbf29.png%3F3) 
 Top-down view of a pixel art police car with flashing red and blue lights, 64x64, arcade retro style". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/67f42cf5f9699d20fcacbf82.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/67f42d4cf9699d20fcacbf93.png%3F3) 
 Top-down view of a sleek red sports car, clean and minimal pixel art style, 64x64 size, suitable for a mobile racing game". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/67f42dc5f9699d20fcacbfa4.png%3F3) 
 Top-down view of a simple blue car in pixel art style, 64x64 size, designed for an endless driving game, minimal detail, arcade style". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/67f43077c19c3cd96fa498c2.png%3F3) 
 Top-down view of a simple pink car in pixel art style, 64x64 size, designed for an endless driving game, minimal detail, arcade style". straight top. View Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/67f43364c19c3cd96fa4992e.png%3F3) 
 Pixel art style gold coin with shine, top-down view, 32x32, designed for arcade coin collection in a racing game". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/67f4e222ecc5949d0e6be99b.png%3F3) 
 Top-down seamless vertically scrolling background for an endless driving game, central road with 3 lanes, side grass, trees, and fences, pixel art style, 512x1024 resolution". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/67f4e671ecc5949d0e6be9ed.png%3F3) 
 "Pixel art style accelerate button icon, 64x64 size, glowing red or white, with an upward arrow or speed meter symbol, circular or rounded rectangle, designed for mobile racing game UI, clean and minimal arcade look". button shoudld be straight up and accelerate text hd images Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/67f4ee05ecc5949d0e6bea85.png%3F3) 
 High-quality brake button for mobile racing game, 64x64 pixels, glowing red, with a brake or stop symbol in the center, 3D UI style with soft shadows and clean edges". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/67f5115892e67804b44cbd88.png%3F3)