User prompt
speed increase 2 times,
User prompt
decrease diamonds
User prompt
make player move with a 360 degree console button make cars moving in all directions like real cars
User prompt
show player's car in different colour decrease number of diamonds make a continuous background with like a city map
User prompt
put chasing car in the middle, and make the map is moving with pace (increases after each crash with a 1 percent) ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Police Chase Escape
Initial prompt
police runner, 2D, top-down, controlling car, escaping from police cars, there are exceptional gold diamonds etc., police and background changes smoothly after milestones, aim is to crush police cars with each other (like police pursuit game) while not crushing with them
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Diamond = Container.expand(function () {
var self = Container.call(this);
var diamondGraphics = self.attachAsset('diamond', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.rotationSpeed = 0.05;
self.update = function () {
diamondGraphics.rotation += self.rotationSpeed;
};
return self;
});
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.attachAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5
});
self.lifetime = 30;
self.age = 0;
self.update = function () {
self.age++;
explosionGraphics.alpha = 1 - self.age / self.lifetime;
explosionGraphics.scaleX = 1 + self.age / self.lifetime;
explosionGraphics.scaleY = 1 + self.age / self.lifetime;
if (self.age >= self.lifetime) {
self.destroy();
}
};
return self;
});
var GetawayCar = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('getawayCar', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.maxSpeed = 8;
self.targetX = 0;
self.targetY = 0;
self.update = function () {
var deltaX = self.targetX - self.x;
var deltaY = self.targetY - self.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
if (distance > 10) {
self.x += deltaX / distance * self.speed;
self.y += deltaY / distance * self.speed;
}
// Keep car within screen bounds
self.x = Math.max(40, Math.min(2048 - 40, self.x));
self.y = Math.max(60, Math.min(2732 - 60, self.y));
};
return self;
});
var PoliceCar = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('policeCar', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.targetCar = null;
self.lastCollisionCheck = false;
self.update = function () {
if (self.targetCar) {
var deltaX = self.targetCar.x - self.x;
var deltaY = self.targetCar.y - self.y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
if (distance > 5) {
self.x += deltaX / distance * self.speed;
self.y += deltaY / distance * self.speed;
}
}
// Keep police car within screen bounds
self.x = Math.max(40, Math.min(2048 - 40, self.x));
self.y = Math.max(60, Math.min(2732 - 60, self.y));
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Game variables
var player;
var policeCars = [];
var diamonds = [];
var explosions = [];
var gameSpeed = 1;
var milestone = 0;
var diamondsCollected = 0;
var policeKills = 0;
// Background colors for different milestones
var backgroundColors = [0x2c3e50, 0x34495e, 0x1abc9c, 0x16a085, 0x27ae60, 0x2980b9];
// UI Elements
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var diamondsTxt = new Text2('Diamonds: 0', {
size: 50,
fill: 0xF1C40F
});
diamondsTxt.anchor.set(0, 0);
diamondsTxt.x = 120;
diamondsTxt.y = 100;
LK.gui.topLeft.addChild(diamondsTxt);
var killsTxt = new Text2('Police Crashes: 0', {
size: 50,
fill: 0xE74C3C
});
killsTxt.anchor.set(1, 0);
killsTxt.x = -20;
killsTxt.y = 100;
LK.gui.topRight.addChild(killsTxt);
// Initialize player
player = game.addChild(new GetawayCar());
player.x = 1024;
player.y = 1366;
player.targetX = player.x;
player.targetY = player.y;
// Spawn initial police cars
function spawnPoliceCar() {
var police = new PoliceCar();
// Spawn from random edge
var edge = Math.floor(Math.random() * 4);
switch (edge) {
case 0:
// Top
police.x = Math.random() * 2048;
police.y = -60;
break;
case 1:
// Right
police.x = 2048 + 60;
police.y = Math.random() * 2732;
break;
case 2:
// Bottom
police.x = Math.random() * 2048;
police.y = 2732 + 60;
break;
case 3:
// Left
police.x = -60;
police.y = Math.random() * 2732;
break;
}
police.targetCar = player;
police.speed = 2 + milestone * 0.5;
policeCars.push(police);
game.addChild(police);
}
// Spawn initial diamonds
function spawnDiamond() {
var diamond = new Diamond();
diamond.x = 100 + Math.random() * 1848;
diamond.y = 100 + Math.random() * 2532;
diamonds.push(diamond);
game.addChild(diamond);
}
// Initialize game objects
for (var i = 0; i < 3; i++) {
spawnPoliceCar();
}
for (var i = 0; i < 5; i++) {
spawnDiamond();
}
// Touch controls
game.move = function (x, y, obj) {
player.targetX = x;
player.targetY = y;
};
game.down = function (x, y, obj) {
player.targetX = x;
player.targetY = y;
};
// Update score display
function updateScore() {
var totalScore = diamondsCollected * 100 + policeKills * 500;
LK.setScore(totalScore);
scoreTxt.setText('Score: ' + totalScore);
diamondsTxt.setText('Diamonds: ' + diamondsCollected);
killsTxt.setText('Police Crashes: ' + policeKills);
}
// Check milestone progression
function checkMilestone() {
var newMilestone = Math.floor(LK.getScore() / 1000);
if (newMilestone > milestone) {
milestone = newMilestone;
// Change background color
if (milestone < backgroundColors.length) {
tween(game, {
backgroundColor: backgroundColors[milestone]
}, {
duration: 2000
});
}
// Spawn additional police car
spawnPoliceCar();
}
}
// Create explosion effect
function createExplosion(x, y) {
var explosion = new Explosion();
explosion.x = x;
explosion.y = y;
explosions.push(explosion);
game.addChild(explosion);
}
// Main game loop
game.update = function () {
// Check diamond collection
for (var i = diamonds.length - 1; i >= 0; i--) {
var diamond = diamonds[i];
if (!diamond.collected && player.intersects(diamond)) {
diamond.collected = true;
diamondsCollected++;
LK.getSound('collectDiamond').play();
diamond.destroy();
diamonds.splice(i, 1);
// Spawn new diamond
spawnDiamond();
}
}
// Check police car collisions with player
for (var i = 0; i < policeCars.length; i++) {
var police = policeCars[i];
if (player.intersects(police)) {
LK.getSound('gameOver').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
// Check police car collisions with each other
for (var i = policeCars.length - 1; i >= 0; i--) {
var police1 = policeCars[i];
var collided = false;
for (var j = i + 1; j < policeCars.length; j++) {
var police2 = policeCars[j];
if (police1.intersects(police2)) {
// Create explosion
var explosionX = (police1.x + police2.x) / 2;
var explosionY = (police1.y + police2.y) / 2;
createExplosion(explosionX, explosionY);
policeKills++;
LK.getSound('policeExplode').play();
// Remove both police cars
police1.destroy();
police2.destroy();
policeCars.splice(j, 1);
policeCars.splice(i, 1);
collided = true;
break;
}
}
if (collided) break;
}
// Clean up explosions
for (var i = explosions.length - 1; i >= 0; i--) {
var explosion = explosions[i];
if (explosion.age >= explosion.lifetime) {
explosions.splice(i, 1);
}
}
// Spawn new police cars periodically
if (LK.ticks % (300 - milestone * 30) === 0) {
spawnPoliceCar();
}
// Update score and check milestones
updateScore();
checkMilestone();
// Win condition
if (LK.getScore() >= 10000) {
LK.showYouWin();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,297 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Diamond = Container.expand(function () {
+ var self = Container.call(this);
+ var diamondGraphics = self.attachAsset('diamond', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.collected = false;
+ self.rotationSpeed = 0.05;
+ self.update = function () {
+ diamondGraphics.rotation += self.rotationSpeed;
+ };
+ return self;
+});
+var Explosion = Container.expand(function () {
+ var self = Container.call(this);
+ var explosionGraphics = self.attachAsset('explosion', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.lifetime = 30;
+ self.age = 0;
+ self.update = function () {
+ self.age++;
+ explosionGraphics.alpha = 1 - self.age / self.lifetime;
+ explosionGraphics.scaleX = 1 + self.age / self.lifetime;
+ explosionGraphics.scaleY = 1 + self.age / self.lifetime;
+ if (self.age >= self.lifetime) {
+ self.destroy();
+ }
+ };
+ return self;
+});
+var GetawayCar = Container.expand(function () {
+ var self = Container.call(this);
+ var carGraphics = self.attachAsset('getawayCar', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 5;
+ self.maxSpeed = 8;
+ self.targetX = 0;
+ self.targetY = 0;
+ self.update = function () {
+ var deltaX = self.targetX - self.x;
+ var deltaY = self.targetY - self.y;
+ var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+ if (distance > 10) {
+ self.x += deltaX / distance * self.speed;
+ self.y += deltaY / distance * self.speed;
+ }
+ // Keep car within screen bounds
+ self.x = Math.max(40, Math.min(2048 - 40, self.x));
+ self.y = Math.max(60, Math.min(2732 - 60, self.y));
+ };
+ return self;
+});
+var PoliceCar = Container.expand(function () {
+ var self = Container.call(this);
+ var carGraphics = self.attachAsset('policeCar', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 2;
+ self.targetCar = null;
+ self.lastCollisionCheck = false;
+ self.update = function () {
+ if (self.targetCar) {
+ var deltaX = self.targetCar.x - self.x;
+ var deltaY = self.targetCar.y - self.y;
+ var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
+ if (distance > 5) {
+ self.x += deltaX / distance * self.speed;
+ self.y += deltaY / distance * self.speed;
+ }
+ }
+ // Keep police car within screen bounds
+ self.x = Math.max(40, Math.min(2048 - 40, self.x));
+ self.y = Math.max(60, Math.min(2732 - 60, self.y));
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2c3e50
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var player;
+var policeCars = [];
+var diamonds = [];
+var explosions = [];
+var gameSpeed = 1;
+var milestone = 0;
+var diamondsCollected = 0;
+var policeKills = 0;
+// Background colors for different milestones
+var backgroundColors = [0x2c3e50, 0x34495e, 0x1abc9c, 0x16a085, 0x27ae60, 0x2980b9];
+// UI Elements
+var scoreTxt = new Text2('Score: 0', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var diamondsTxt = new Text2('Diamonds: 0', {
+ size: 50,
+ fill: 0xF1C40F
+});
+diamondsTxt.anchor.set(0, 0);
+diamondsTxt.x = 120;
+diamondsTxt.y = 100;
+LK.gui.topLeft.addChild(diamondsTxt);
+var killsTxt = new Text2('Police Crashes: 0', {
+ size: 50,
+ fill: 0xE74C3C
+});
+killsTxt.anchor.set(1, 0);
+killsTxt.x = -20;
+killsTxt.y = 100;
+LK.gui.topRight.addChild(killsTxt);
+// Initialize player
+player = game.addChild(new GetawayCar());
+player.x = 1024;
+player.y = 1366;
+player.targetX = player.x;
+player.targetY = player.y;
+// Spawn initial police cars
+function spawnPoliceCar() {
+ var police = new PoliceCar();
+ // Spawn from random edge
+ var edge = Math.floor(Math.random() * 4);
+ switch (edge) {
+ case 0:
+ // Top
+ police.x = Math.random() * 2048;
+ police.y = -60;
+ break;
+ case 1:
+ // Right
+ police.x = 2048 + 60;
+ police.y = Math.random() * 2732;
+ break;
+ case 2:
+ // Bottom
+ police.x = Math.random() * 2048;
+ police.y = 2732 + 60;
+ break;
+ case 3:
+ // Left
+ police.x = -60;
+ police.y = Math.random() * 2732;
+ break;
+ }
+ police.targetCar = player;
+ police.speed = 2 + milestone * 0.5;
+ policeCars.push(police);
+ game.addChild(police);
+}
+// Spawn initial diamonds
+function spawnDiamond() {
+ var diamond = new Diamond();
+ diamond.x = 100 + Math.random() * 1848;
+ diamond.y = 100 + Math.random() * 2532;
+ diamonds.push(diamond);
+ game.addChild(diamond);
+}
+// Initialize game objects
+for (var i = 0; i < 3; i++) {
+ spawnPoliceCar();
+}
+for (var i = 0; i < 5; i++) {
+ spawnDiamond();
+}
+// Touch controls
+game.move = function (x, y, obj) {
+ player.targetX = x;
+ player.targetY = y;
+};
+game.down = function (x, y, obj) {
+ player.targetX = x;
+ player.targetY = y;
+};
+// Update score display
+function updateScore() {
+ var totalScore = diamondsCollected * 100 + policeKills * 500;
+ LK.setScore(totalScore);
+ scoreTxt.setText('Score: ' + totalScore);
+ diamondsTxt.setText('Diamonds: ' + diamondsCollected);
+ killsTxt.setText('Police Crashes: ' + policeKills);
+}
+// Check milestone progression
+function checkMilestone() {
+ var newMilestone = Math.floor(LK.getScore() / 1000);
+ if (newMilestone > milestone) {
+ milestone = newMilestone;
+ // Change background color
+ if (milestone < backgroundColors.length) {
+ tween(game, {
+ backgroundColor: backgroundColors[milestone]
+ }, {
+ duration: 2000
+ });
+ }
+ // Spawn additional police car
+ spawnPoliceCar();
+ }
+}
+// Create explosion effect
+function createExplosion(x, y) {
+ var explosion = new Explosion();
+ explosion.x = x;
+ explosion.y = y;
+ explosions.push(explosion);
+ game.addChild(explosion);
+}
+// Main game loop
+game.update = function () {
+ // Check diamond collection
+ for (var i = diamonds.length - 1; i >= 0; i--) {
+ var diamond = diamonds[i];
+ if (!diamond.collected && player.intersects(diamond)) {
+ diamond.collected = true;
+ diamondsCollected++;
+ LK.getSound('collectDiamond').play();
+ diamond.destroy();
+ diamonds.splice(i, 1);
+ // Spawn new diamond
+ spawnDiamond();
+ }
+ }
+ // Check police car collisions with player
+ for (var i = 0; i < policeCars.length; i++) {
+ var police = policeCars[i];
+ if (player.intersects(police)) {
+ LK.getSound('gameOver').play();
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ return;
+ }
+ }
+ // Check police car collisions with each other
+ for (var i = policeCars.length - 1; i >= 0; i--) {
+ var police1 = policeCars[i];
+ var collided = false;
+ for (var j = i + 1; j < policeCars.length; j++) {
+ var police2 = policeCars[j];
+ if (police1.intersects(police2)) {
+ // Create explosion
+ var explosionX = (police1.x + police2.x) / 2;
+ var explosionY = (police1.y + police2.y) / 2;
+ createExplosion(explosionX, explosionY);
+ policeKills++;
+ LK.getSound('policeExplode').play();
+ // Remove both police cars
+ police1.destroy();
+ police2.destroy();
+ policeCars.splice(j, 1);
+ policeCars.splice(i, 1);
+ collided = true;
+ break;
+ }
+ }
+ if (collided) break;
+ }
+ // Clean up explosions
+ for (var i = explosions.length - 1; i >= 0; i--) {
+ var explosion = explosions[i];
+ if (explosion.age >= explosion.lifetime) {
+ explosions.splice(i, 1);
+ }
+ }
+ // Spawn new police cars periodically
+ if (LK.ticks % (300 - milestone * 30) === 0) {
+ spawnPoliceCar();
+ }
+ // Update score and check milestones
+ updateScore();
+ checkMilestone();
+ // Win condition
+ if (LK.getScore() >= 10000) {
+ LK.showYouWin();
+ }
+};
\ No newline at end of file