User prompt
delete road line
User prompt
make a barrier animation ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
add a barrier animation
User prompt
make a road animatipn
User prompt
add a backround image
User prompt
use backround image road
User prompt
make it move in the barrier
User prompt
Let the barrier heat up with the player
User prompt
use barriyer image for road barrier
User prompt
add barriers outside the road
User prompt
increase traffic vehicles and delete the environment
User prompt
road bigger
User prompt
add environment to the game
User prompt
polices dont spawn players behind
User prompt
police speed slower
User prompt
police dont spawn in game starts
User prompt
police chasing player back
User prompt
add police chase
User prompt
make me a car chase game
User prompt
reload game code
Code edit (1 edits merged)
Please save this source code
User prompt
Highway Pursuit
Initial prompt
make me a car chase game
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Player Car var PlayerCar = Container.expand(function () { var self = Container.call(this); var car = self.attachAsset('playerCar', { anchorX: 0.5, anchorY: 0.5 }); self.width = car.width; self.height = car.height; self.lane = 1; // 0: left, 1: center, 2: right self.invincible = false; self.invincibleTimer = 0; self.update = function () { // Invincibility timer if (self.invincible) { self.invincibleTimer--; if (self.invincibleTimer <= 0) { self.invincible = false; car.alpha = 1; } } }; // Flash effect for invincibility self.setInvincible = function (duration) { self.invincible = true; self.invincibleTimer = duration; car.alpha = 0.5; }; return self; }); // Police Car var PoliceCar = Container.expand(function () { var self = Container.call(this); var car = self.attachAsset('policeCar', { anchorX: 0.5, anchorY: 0.5 }); self.width = car.width; self.height = car.height; self.speed = 0; self.lane = 1; self.update = function () { self.y += self.speed; }; return self; }); // Powerup var Powerup = Container.expand(function () { var self = Container.call(this); var p = self.attachAsset('powerup', { anchorX: 0.5, anchorY: 0.5 }); self.width = p.width; self.height = p.height; self.speed = 0; self.type = 'invincible'; // Only one type for MVP self.update = function () { self.y += self.speed; }; return self; }); // Road Line var RoadLine = Container.expand(function () { var self = Container.call(this); var line = self.attachAsset('roadLine', { anchorX: 0.5, anchorY: 0.5 }); self.width = line.width; self.height = line.height; self.speed = 0; self.update = function () { self.y += self.speed; }; return self; }); // Traffic Car var TrafficCar = Container.expand(function () { var self = Container.call(this); var car = self.attachAsset('trafficCar', { anchorX: 0.5, anchorY: 0.5 }); self.width = car.width; self.height = car.height; self.speed = 0; self.lane = 1; self.update = function () { self.y += self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222222 }); /**** * Game Code ****/ // Car assets // Game constants var ROAD_WIDTH = 1200; var ROAD_LEFT = (2048 - ROAD_WIDTH) / 2; var ROAD_RIGHT = ROAD_LEFT + ROAD_WIDTH; var LANE_COUNT = 3; var LANE_WIDTH = ROAD_WIDTH / LANE_COUNT; var PLAYER_Y = 2732 - 400; var SPAWN_TOP = -300; var ROAD_LINE_SPACING = 300; var ROAD_LINE_COUNT = Math.ceil(2732 / ROAD_LINE_SPACING) + 2; // Game state var player; var policeCars = []; var trafficCars = []; var powerups = []; var roadLines = []; var score = 0; var distance = 0; var lastLane = 1; var gameSpeed = 24; var policeSpawnTimer = 0; var trafficSpawnTimer = 0; var powerupSpawnTimer = 0; var difficultyTimer = 0; var dragStartX = null; var dragStartLane = null; var dragNode = null; // Score display var scoreTxt = new Text2('0', { size: 120, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Distance display var distTxt = new Text2('0 m', { size: 60, fill: "#fff" }); distTxt.anchor.set(0.5, 0); LK.gui.top.addChild(distTxt); distTxt.y = 130; // Helper: get lane center X function laneToX(lane) { return ROAD_LEFT + LANE_WIDTH * (lane + 0.5); } // Helper: pick random lane function randomLane() { return Math.floor(Math.random() * LANE_COUNT); } // Helper: clamp lane function clampLane(lane) { if (lane < 0) return 0; if (lane >= LANE_COUNT) return LANE_COUNT - 1; return lane; } // Create road lines for (var i = 0; i < ROAD_LINE_COUNT; i++) { var line = new RoadLine(); line.x = 2048 / 2; line.y = i * ROAD_LINE_SPACING; line.speed = gameSpeed; roadLines.push(line); game.addChild(line); } // Create player player = new PlayerCar(); player.lane = 1; player.x = laneToX(player.lane); player.y = PLAYER_Y; game.addChild(player); // Touch controls: drag to steer game.down = function (x, y, obj) { // Only start drag if touch is on lower half of screen if (y > 1366) { dragStartX = x; dragStartLane = player.lane; dragNode = player; } }; game.move = function (x, y, obj) { if (dragNode === player && dragStartX !== null) { var dx = x - dragStartX; var laneDelta = Math.round(dx / LANE_WIDTH); var newLane = clampLane(dragStartLane + laneDelta); if (newLane !== player.lane) { player.lane = newLane; // Animate car to new lane tween.stop(player, { x: true }); tween(player, { x: laneToX(player.lane) }, { duration: 120, easing: tween.cubicOut }); } } }; game.up = function (x, y, obj) { dragNode = null; dragStartX = null; dragStartLane = null; }; // Main update loop game.update = function () { // Increase difficulty over time difficultyTimer++; if (difficultyTimer % 600 === 0 && gameSpeed < 40) { gameSpeed += 2; } // Move road lines for (var i = 0; i < roadLines.length; i++) { var line = roadLines[i]; line.speed = gameSpeed; line.update(); if (line.y > 2732 + 100) { line.y -= ROAD_LINE_COUNT * ROAD_LINE_SPACING; } } // Update player player.update(); // Move police cars for (var i = policeCars.length - 1; i >= 0; i--) { var p = policeCars[i]; p.speed = gameSpeed + 4; p.update(); // Remove if off screen if (p.y > 2732 + 300) { p.destroy(); policeCars.splice(i, 1); continue; } // Collision with player if (p.intersects(player) && !player.invincible) { LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); return; } } // Move traffic cars for (var i = trafficCars.length - 1; i >= 0; i--) { var t = trafficCars[i]; t.speed = gameSpeed; t.update(); if (t.y > 2732 + 300) { t.destroy(); trafficCars.splice(i, 1); continue; } // Collision with player if (t.intersects(player) && !player.invincible) { LK.effects.flashScreen(0xff0000, 800); LK.showGameOver(); return; } } // Move powerups for (var i = powerups.length - 1; i >= 0; i--) { var pu = powerups[i]; pu.speed = gameSpeed; pu.update(); if (pu.y > 2732 + 200) { pu.destroy(); powerups.splice(i, 1); continue; } // Pickup if (pu.intersects(player)) { if (pu.type === 'invincible') { player.setInvincible(180); // 3 seconds at 60fps } score += 100; LK.setScore(score); scoreTxt.setText(score); pu.destroy(); powerups.splice(i, 1); continue; } } // Spawn police car policeSpawnTimer--; if (policeSpawnTimer <= 0) { var lane = randomLane(); // Don't spawn in same lane as last police if (policeCars.length > 0 && policeCars[policeCars.length - 1].lane === lane) { lane = clampLane((lane + 1) % LANE_COUNT); } var p = new PoliceCar(); p.lane = lane; p.x = laneToX(lane); p.y = SPAWN_TOP; policeCars.push(p); game.addChild(p); policeSpawnTimer = Math.max(90, 240 - Math.floor(distance / 1000) * 10); } // Spawn traffic car trafficSpawnTimer--; if (trafficSpawnTimer <= 0) { var lane = randomLane(); // Avoid spawning on player if (lane === player.lane) { lane = clampLane((lane + 1) % LANE_COUNT); } var t = new TrafficCar(); t.lane = lane; t.x = laneToX(lane); t.y = SPAWN_TOP - 200; trafficCars.push(t); game.addChild(t); trafficSpawnTimer = Math.max(40, 120 - Math.floor(distance / 1000) * 5); } // Spawn powerup powerupSpawnTimer--; if (powerupSpawnTimer <= 0) { var lane = randomLane(); var pu = new Powerup(); pu.x = laneToX(lane); pu.y = SPAWN_TOP - 400; powerups.push(pu); game.addChild(pu); powerupSpawnTimer = 600 + Math.floor(Math.random() * 600); } // Update score and distance distance += gameSpeed; distTxt.setText(Math.floor(distance / 10) + " m"); var newScore = Math.floor(distance / 10) + score; if (newScore !== LK.getScore()) { LK.setScore(newScore); scoreTxt.setText(LK.getScore()); } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,346 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+// Player Car
+var PlayerCar = Container.expand(function () {
+ var self = Container.call(this);
+ var car = self.attachAsset('playerCar', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = car.width;
+ self.height = car.height;
+ self.lane = 1; // 0: left, 1: center, 2: right
+ self.invincible = false;
+ self.invincibleTimer = 0;
+ self.update = function () {
+ // Invincibility timer
+ if (self.invincible) {
+ self.invincibleTimer--;
+ if (self.invincibleTimer <= 0) {
+ self.invincible = false;
+ car.alpha = 1;
+ }
+ }
+ };
+ // Flash effect for invincibility
+ self.setInvincible = function (duration) {
+ self.invincible = true;
+ self.invincibleTimer = duration;
+ car.alpha = 0.5;
+ };
+ return self;
+});
+// Police Car
+var PoliceCar = Container.expand(function () {
+ var self = Container.call(this);
+ var car = self.attachAsset('policeCar', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = car.width;
+ self.height = car.height;
+ self.speed = 0;
+ self.lane = 1;
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+// Powerup
+var Powerup = Container.expand(function () {
+ var self = Container.call(this);
+ var p = self.attachAsset('powerup', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = p.width;
+ self.height = p.height;
+ self.speed = 0;
+ self.type = 'invincible'; // Only one type for MVP
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+// Road Line
+var RoadLine = Container.expand(function () {
+ var self = Container.call(this);
+ var line = self.attachAsset('roadLine', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = line.width;
+ self.height = line.height;
+ self.speed = 0;
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+// Traffic Car
+var TrafficCar = Container.expand(function () {
+ var self = Container.call(this);
+ var car = self.attachAsset('trafficCar', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.width = car.width;
+ self.height = car.height;
+ self.speed = 0;
+ self.lane = 1;
+ self.update = function () {
+ self.y += self.speed;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x222222
+});
+
+/****
+* Game Code
+****/
+// Car assets
+// Game constants
+var ROAD_WIDTH = 1200;
+var ROAD_LEFT = (2048 - ROAD_WIDTH) / 2;
+var ROAD_RIGHT = ROAD_LEFT + ROAD_WIDTH;
+var LANE_COUNT = 3;
+var LANE_WIDTH = ROAD_WIDTH / LANE_COUNT;
+var PLAYER_Y = 2732 - 400;
+var SPAWN_TOP = -300;
+var ROAD_LINE_SPACING = 300;
+var ROAD_LINE_COUNT = Math.ceil(2732 / ROAD_LINE_SPACING) + 2;
+// Game state
+var player;
+var policeCars = [];
+var trafficCars = [];
+var powerups = [];
+var roadLines = [];
+var score = 0;
+var distance = 0;
+var lastLane = 1;
+var gameSpeed = 24;
+var policeSpawnTimer = 0;
+var trafficSpawnTimer = 0;
+var powerupSpawnTimer = 0;
+var difficultyTimer = 0;
+var dragStartX = null;
+var dragStartLane = null;
+var dragNode = null;
+// Score display
+var scoreTxt = new Text2('0', {
+ size: 120,
+ fill: "#fff"
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+// Distance display
+var distTxt = new Text2('0 m', {
+ size: 60,
+ fill: "#fff"
+});
+distTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(distTxt);
+distTxt.y = 130;
+// Helper: get lane center X
+function laneToX(lane) {
+ return ROAD_LEFT + LANE_WIDTH * (lane + 0.5);
+}
+// Helper: pick random lane
+function randomLane() {
+ return Math.floor(Math.random() * LANE_COUNT);
+}
+// Helper: clamp lane
+function clampLane(lane) {
+ if (lane < 0) return 0;
+ if (lane >= LANE_COUNT) return LANE_COUNT - 1;
+ return lane;
+}
+// Create road lines
+for (var i = 0; i < ROAD_LINE_COUNT; i++) {
+ var line = new RoadLine();
+ line.x = 2048 / 2;
+ line.y = i * ROAD_LINE_SPACING;
+ line.speed = gameSpeed;
+ roadLines.push(line);
+ game.addChild(line);
+}
+// Create player
+player = new PlayerCar();
+player.lane = 1;
+player.x = laneToX(player.lane);
+player.y = PLAYER_Y;
+game.addChild(player);
+// Touch controls: drag to steer
+game.down = function (x, y, obj) {
+ // Only start drag if touch is on lower half of screen
+ if (y > 1366) {
+ dragStartX = x;
+ dragStartLane = player.lane;
+ dragNode = player;
+ }
+};
+game.move = function (x, y, obj) {
+ if (dragNode === player && dragStartX !== null) {
+ var dx = x - dragStartX;
+ var laneDelta = Math.round(dx / LANE_WIDTH);
+ var newLane = clampLane(dragStartLane + laneDelta);
+ if (newLane !== player.lane) {
+ player.lane = newLane;
+ // Animate car to new lane
+ tween.stop(player, {
+ x: true
+ });
+ tween(player, {
+ x: laneToX(player.lane)
+ }, {
+ duration: 120,
+ easing: tween.cubicOut
+ });
+ }
+ }
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+ dragStartX = null;
+ dragStartLane = null;
+};
+// Main update loop
+game.update = function () {
+ // Increase difficulty over time
+ difficultyTimer++;
+ if (difficultyTimer % 600 === 0 && gameSpeed < 40) {
+ gameSpeed += 2;
+ }
+ // Move road lines
+ for (var i = 0; i < roadLines.length; i++) {
+ var line = roadLines[i];
+ line.speed = gameSpeed;
+ line.update();
+ if (line.y > 2732 + 100) {
+ line.y -= ROAD_LINE_COUNT * ROAD_LINE_SPACING;
+ }
+ }
+ // Update player
+ player.update();
+ // Move police cars
+ for (var i = policeCars.length - 1; i >= 0; i--) {
+ var p = policeCars[i];
+ p.speed = gameSpeed + 4;
+ p.update();
+ // Remove if off screen
+ if (p.y > 2732 + 300) {
+ p.destroy();
+ policeCars.splice(i, 1);
+ continue;
+ }
+ // Collision with player
+ if (p.intersects(player) && !player.invincible) {
+ LK.effects.flashScreen(0xff0000, 800);
+ LK.showGameOver();
+ return;
+ }
+ }
+ // Move traffic cars
+ for (var i = trafficCars.length - 1; i >= 0; i--) {
+ var t = trafficCars[i];
+ t.speed = gameSpeed;
+ t.update();
+ if (t.y > 2732 + 300) {
+ t.destroy();
+ trafficCars.splice(i, 1);
+ continue;
+ }
+ // Collision with player
+ if (t.intersects(player) && !player.invincible) {
+ LK.effects.flashScreen(0xff0000, 800);
+ LK.showGameOver();
+ return;
+ }
+ }
+ // Move powerups
+ for (var i = powerups.length - 1; i >= 0; i--) {
+ var pu = powerups[i];
+ pu.speed = gameSpeed;
+ pu.update();
+ if (pu.y > 2732 + 200) {
+ pu.destroy();
+ powerups.splice(i, 1);
+ continue;
+ }
+ // Pickup
+ if (pu.intersects(player)) {
+ if (pu.type === 'invincible') {
+ player.setInvincible(180); // 3 seconds at 60fps
+ }
+ score += 100;
+ LK.setScore(score);
+ scoreTxt.setText(score);
+ pu.destroy();
+ powerups.splice(i, 1);
+ continue;
+ }
+ }
+ // Spawn police car
+ policeSpawnTimer--;
+ if (policeSpawnTimer <= 0) {
+ var lane = randomLane();
+ // Don't spawn in same lane as last police
+ if (policeCars.length > 0 && policeCars[policeCars.length - 1].lane === lane) {
+ lane = clampLane((lane + 1) % LANE_COUNT);
+ }
+ var p = new PoliceCar();
+ p.lane = lane;
+ p.x = laneToX(lane);
+ p.y = SPAWN_TOP;
+ policeCars.push(p);
+ game.addChild(p);
+ policeSpawnTimer = Math.max(90, 240 - Math.floor(distance / 1000) * 10);
+ }
+ // Spawn traffic car
+ trafficSpawnTimer--;
+ if (trafficSpawnTimer <= 0) {
+ var lane = randomLane();
+ // Avoid spawning on player
+ if (lane === player.lane) {
+ lane = clampLane((lane + 1) % LANE_COUNT);
+ }
+ var t = new TrafficCar();
+ t.lane = lane;
+ t.x = laneToX(lane);
+ t.y = SPAWN_TOP - 200;
+ trafficCars.push(t);
+ game.addChild(t);
+ trafficSpawnTimer = Math.max(40, 120 - Math.floor(distance / 1000) * 5);
+ }
+ // Spawn powerup
+ powerupSpawnTimer--;
+ if (powerupSpawnTimer <= 0) {
+ var lane = randomLane();
+ var pu = new Powerup();
+ pu.x = laneToX(lane);
+ pu.y = SPAWN_TOP - 400;
+ powerups.push(pu);
+ game.addChild(pu);
+ powerupSpawnTimer = 600 + Math.floor(Math.random() * 600);
+ }
+ // Update score and distance
+ distance += gameSpeed;
+ distTxt.setText(Math.floor(distance / 10) + " m");
+ var newScore = Math.floor(distance / 10) + score;
+ if (newScore !== LK.getScore()) {
+ LK.setScore(newScore);
+ scoreTxt.setText(LK.getScore());
+ }
+};
\ No newline at end of file
car top view. In-Game asset. 2d. High contrast. No shadows
police car top view. In-Game asset. 2d. High contrast. No shadows
add highway barrier top view. In-Game asset. 2d. High contrast. No shadows
power coin. In-Game asset. 2d. High contrast. No shadows. power coin
a highway road but top view. In-Game asset. 2d. High contrast. No shadows