User prompt
Add drags for all cars. improve play experience
User prompt
Explosion effect should not cover all screen ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make police spawn from the edge of screen. Make map repeat and never end.
User prompt
Please fix the bug: 'TypeError: setTimeout is not a function' in or related to this line: 'setTimeout(function () {' Line Number: 719
User prompt
Crash effect more explosive. increase all speeds by 3 times ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make sure player car is a little bit faster than police cars for lower levels, increase difficulty with time, diamonds and police crashes. Place player car in the middle through game
User prompt
Enable to move car not map itself, create a repeating-itself to make sure game is endless. Enable player moves not only rotation
User prompt
Decrease police car spawn interval (more common). Make map moves according to button moves. Place player car always in the middle.
User prompt
İncrease car speed
User prompt
Place right button more left and down, remove left button
User prompt
Buttons are not visible?
User prompt
Both buttons to more to middle
User prompt
Place button to a more visible place, upper
User prompt
Place button on right and left bottom when needed (should be 1 on the screen always)
User prompt
Make action stick button visible
User prompt
Not playable
User prompt
Touch screen doesn't work
User prompt
Not playable
User prompt
Enable screen touch playing
User prompt
increase reality of city map with more details
User prompt
increase pace and change cars icons with real car photos, police cars & bugatti for player ca
User prompt
enable desktop joystick button to use with mouse
User prompt
enable desktop play mode
User prompt
i need player to move all directions
User prompt
show console button
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var CityBackground = Container.expand(function () {
var self = Container.call(this);
var backgroundElements = [];
self.tileHeight = 400;
self.tilesPerRow = 10;
self.rows = 10;
// Helper function to create building complex
function createBuildingComplex(col, row, topY) {
var complex = new Container();
var buildingTypes = ['building', 'tallBuilding', 'skyscraper', 'apartment', 'office'];
var buildingType = buildingTypes[Math.floor(Math.random() * buildingTypes.length)];
var building = LK.getAsset(buildingType, {
anchorX: 0,
anchorY: 0
});
building.width = 150 + Math.random() * 50;
building.height = 200 + Math.random() * 200;
building.alpha = 0.8;
complex.addChild(building);
// Add windows effect with alpha variations
building.alpha = 0.7 + Math.random() * 0.3;
// Add sidewalk
var sidewalk = LK.getAsset('sidewalk', {
anchorX: 0,
anchorY: 0
});
sidewalk.width = 200;
sidewalk.height = 30;
sidewalk.y = building.height - 30;
complex.addChild(sidewalk);
// Randomly add street elements
if (Math.random() < 0.3) {
var streetLight = LK.getAsset('streetLight', {
anchorX: 0,
anchorY: 0
});
streetLight.x = 20 + Math.random() * 160;
streetLight.y = building.height - 80;
complex.addChild(streetLight);
}
if (Math.random() < 0.2) {
var tree = LK.getAsset('tree', {
anchorX: 0,
anchorY: 0
});
tree.x = 30 + Math.random() * 140;
tree.y = building.height - 60;
complex.addChild(tree);
}
if (Math.random() < 0.15) {
var mailbox = LK.getAsset('mailbox', {
anchorX: 0,
anchorY: 0
});
mailbox.x = 40 + Math.random() * 120;
mailbox.y = building.height - 30;
complex.addChild(mailbox);
}
complex.x = col * 200;
complex.y = topY;
return complex;
}
// Helper function to create road with details
function createRoadSection(col, row, topY) {
var roadSection = new Container();
var road = LK.getAsset('road', {
anchorX: 0,
anchorY: 0
});
road.width = 200;
road.height = 100;
roadSection.addChild(road);
// Add lane markings
for (var i = 0; i < 3; i++) {
var laneLine = LK.getAsset('laneLine', {
anchorX: 0,
anchorY: 0
});
laneLine.width = 200;
laneLine.height = 3;
laneLine.y = 25 + i * 25;
laneLine.alpha = 0.8;
roadSection.addChild(laneLine);
}
// Randomly add crosswalk
if (Math.random() < 0.2) {
var crosswalk = LK.getAsset('crosswalk', {
anchorX: 0,
anchorY: 0
});
crosswalk.width = 200;
crosswalk.height = 15;
crosswalk.y = 85;
crosswalk.alpha = 0.9;
roadSection.addChild(crosswalk);
}
// Randomly add parked vehicles
if (Math.random() < 0.3) {
var vehicleTypes = ['parkedCar', 'taxi'];
var vehicleType = vehicleTypes[Math.floor(Math.random() * vehicleTypes.length)];
var vehicle = LK.getAsset(vehicleType, {
anchorX: 0,
anchorY: 0
});
vehicle.width = 60;
vehicle.height = 100;
vehicle.x = 10 + Math.random() * 130;
vehicle.y = 0;
vehicle.alpha = 0.8;
roadSection.addChild(vehicle);
}
// Randomly add bus
if (Math.random() < 0.1) {
var bus = LK.getAsset('bus', {
anchorX: 0,
anchorY: 0
});
bus.width = 90;
bus.height = 200;
bus.x = 55;
bus.y = -50;
bus.alpha = 0.8;
roadSection.addChild(bus);
}
roadSection.x = col * 200;
roadSection.y = topY;
return roadSection;
}
// Create initial background tiles
for (var row = 0; row < self.rows; row++) {
for (var col = 0; col < self.tilesPerRow; col++) {
var element;
var elementType = Math.floor(Math.random() * 10);
var topY = (row - 2) * self.tileHeight;
if (elementType < 3) {
// Road with details (30% chance)
element = createRoadSection(col, row, topY);
} else if (elementType < 8) {
// Building complex (50% chance)
element = createBuildingComplex(col, row, topY);
} else {
// City block (20% chance)
element = LK.getAsset('cityBlock', {
anchorX: 0,
anchorY: 0
});
element.width = 200;
element.height = 200;
element.x = col * 200;
element.y = topY;
element.alpha = 0.7;
}
self.addChild(element);
backgroundElements.push(element);
}
}
self.update = function () {
// Move all background elements with map speed
for (var i = backgroundElements.length - 1; i >= 0; i--) {
var element = backgroundElements[i];
element.y += mapSpeed;
// Remove elements that went off screen bottom
if (element.y > 2732 + 400) {
element.destroy();
backgroundElements.splice(i, 1);
}
}
// Add new row of tiles at the top when needed
if (backgroundElements.length < self.tilesPerRow * 8) {
var topY = -800;
for (var col = 0; col < self.tilesPerRow; col++) {
var element;
var elementType = Math.floor(Math.random() * 10);
if (elementType < 3) {
// Road with details
element = createRoadSection(col, 0, topY);
} else if (elementType < 8) {
// Building complex
element = createBuildingComplex(col, 0, topY);
} else {
// City block
element = LK.getAsset('cityBlock', {
anchorX: 0,
anchorY: 0
});
element.width = 200;
element.height = 200;
element.x = col * 200;
element.y = topY;
element.alpha = 0.7;
}
self.addChild(element);
backgroundElements.push(element);
}
}
};
return self;
});
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;
// Move with map scrolling
self.y += mapSpeed;
// Remove diamonds that go off screen
if (self.y > 2732 + 100) {
self.destroy();
}
};
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;
// Move with map scrolling
self.y += mapSpeed;
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 = 8;
self.maxSpeed = 18;
self.velocityX = 0;
self.velocityY = 0;
self.acceleration = 0.8;
self.friction = 0.85;
self.update = function () {
var inputX = 0;
var inputY = 0;
var hasInput = false;
// Apply active button input if available (mobile)
if (activeButton && activeButton.isActive) {
inputX = activeButton.currentX;
inputY = activeButton.currentY;
hasInput = true;
}
// Keyboard input removed - not supported in LK engine
// Apply input to velocity
if (hasInput) {
self.velocityX += inputX * self.acceleration;
self.velocityY += inputY * self.acceleration;
// Rotate car to face movement direction
if (inputX !== 0 || inputY !== 0) {
var angle = Math.atan2(inputY, inputX);
carGraphics.rotation = angle + Math.PI / 2;
}
}
// Apply friction
self.velocityX *= self.friction;
self.velocityY *= self.friction;
// Limit velocity
var speed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY);
if (speed > self.maxSpeed) {
self.velocityX = self.velocityX / speed * self.maxSpeed;
self.velocityY = self.velocityY / speed * self.maxSpeed;
}
// Move player
self.x += self.velocityX;
self.y += self.velocityY;
// Keep player within bounds with more generous boundaries
self.x = Math.max(40, Math.min(2008, self.x));
self.y = Math.max(40, Math.min(2692, self.y));
};
return self;
});
var JoystickControl = Container.expand(function () {
var self = Container.call(this);
var joystickBase = self.attachAsset('joystickBase', {
anchorX: 0.5,
anchorY: 0.5
});
var joystickKnob = self.attachAsset('joystickKnob', {
anchorX: 0.5,
anchorY: 0.5
});
joystickBase.alpha = 1.0;
joystickKnob.alpha = 1.0;
joystickBase.tint = 0x7f8c8d; // Light gray for better visibility
joystickKnob.tint = 0xffffff; // White knob for contrast
self.isActive = false;
self.currentX = 0;
self.currentY = 0;
self.maxDistance = 100;
self.down = function (x, y, obj) {
self.isActive = true;
self.updateKnob(x, y);
};
self.move = function (x, y, obj) {
if (self.isActive) {
self.updateKnob(x, y);
}
};
self.up = function (x, y, obj) {
self.isActive = false;
joystickKnob.x = 0;
joystickKnob.y = 0;
self.currentX = 0;
self.currentY = 0;
};
self.updateKnob = function (x, y) {
var deltaX = x;
var deltaY = y;
var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
if (distance > self.maxDistance) {
deltaX = deltaX / distance * self.maxDistance;
deltaY = deltaY / distance * self.maxDistance;
}
joystickKnob.x = deltaX;
joystickKnob.y = deltaY;
self.currentX = deltaX / self.maxDistance;
self.currentY = deltaY / self.maxDistance;
};
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.velocityX = 0;
self.velocityY = 0;
self.acceleration = 0.2;
self.friction = 0.95;
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) {
// Apply acceleration towards target
self.velocityX += deltaX / distance * self.acceleration;
self.velocityY += deltaY / distance * self.acceleration;
// Rotate car to face movement direction
var angle = Math.atan2(deltaY, deltaX);
carGraphics.rotation = angle + Math.PI / 2;
}
}
// Apply friction
self.velocityX *= self.friction;
self.velocityY *= self.friction;
// Limit velocity
var speed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY);
if (speed > self.speed) {
self.velocityX = self.velocityX / speed * self.speed;
self.velocityY = self.velocityY / speed * self.speed;
}
// Move police car
self.x += self.velocityX;
self.y += self.velocityY;
// Move with map scrolling
self.y += mapSpeed;
// Remove police cars that go off screen
if (self.y > 2732 + 100) {
self.destroy();
}
};
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;
var mapSpeed = 12;
var mapOffsetY = 0;
var baseMapSpeed = 12;
// 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.5, 0);
diamondsTxt.x = 0;
diamondsTxt.y = 80;
LK.gui.top.addChild(diamondsTxt);
var killsTxt = new Text2('Police Crashes: 0', {
size: 50,
fill: 0xE74C3C
});
killsTxt.anchor.set(0.5, 0);
killsTxt.x = 0;
killsTxt.y = 140;
LK.gui.top.addChild(killsTxt);
// Initialize city background
var cityBackground = game.addChild(new CityBackground());
// Initialize joystick control
var joystick = new JoystickControl();
// Create right action button
var rightButton = new JoystickControl();
rightButton.x = 0;
rightButton.y = 0;
// Scale up the button for better visibility
rightButton.scaleX = 1.5;
rightButton.scaleY = 1.5;
LK.gui.center.addChild(rightButton);
rightButton.x = 300; // Move more left from center
rightButton.y = 400; // Move down from center
// Only show right button
rightButton.visible = true;
var activeButton = rightButton;
// Initialize player
player = game.addChild(new GetawayCar());
player.x = 1024; // Center horizontally
player.y = 1366; // Center vertically
// Spawn initial police cars
function spawnPoliceCar() {
var police = new PoliceCar();
// Spawn from random edge, favoring top and sides for moving map
var edge = Math.floor(Math.random() * 4);
switch (edge) {
case 0:
// Top (ahead of player)
police.x = Math.random() * 2048;
police.y = -60;
break;
case 1:
// Right
police.x = 2048 + 60;
police.y = Math.random() * 1000; // Spawn closer to top
break;
case 2:
// Bottom (behind player, will move forward)
police.x = Math.random() * 2048;
police.y = 2732 + 60;
break;
case 3:
// Left
police.x = -60;
police.y = Math.random() * 1000; // Spawn closer to top
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() * 500; // Spawn ahead of player
diamonds.push(diamond);
game.addChild(diamond);
}
// Initialize game objects
for (var i = 0; i < 3; i++) {
spawnPoliceCar();
}
for (var i = 0; i < 1; i++) {
spawnDiamond();
}
// Joystick controls are now handled by the JoystickControl class
// Desktop keyboard controls (removed - not supported in LK engine)
var keys = {};
// Touch and mouse controls for action buttons
game.down = function (x, y, obj) {
// Check if touch is in right button area
if (rightButton.visible) {
// Touch in right button area
var buttonPos = LK.gui.center.toLocal({
x: x,
y: y
});
buttonPos.x -= 300; // Adjust for right button offset
buttonPos.y -= 400; // Adjust for right button Y offset
var distance = Math.sqrt(buttonPos.x * buttonPos.x + buttonPos.y * buttonPos.y);
if (distance <= rightButton.maxDistance * 1.5) {
activeButton = rightButton;
rightButton.down(buttonPos.x, buttonPos.y, obj);
}
}
};
game.move = function (x, y, obj) {
if (activeButton && activeButton.isActive) {
if (activeButton === rightButton) {
var buttonPos = LK.gui.center.toLocal({
x: x,
y: y
});
buttonPos.x -= 300; // Adjust for right button offset
buttonPos.y -= 400; // Adjust for right button Y offset
rightButton.move(buttonPos.x, buttonPos.y, obj);
}
}
};
game.up = function (x, y, obj) {
if (activeButton && activeButton.isActive) {
activeButton.up(x, y, obj);
}
};
// 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();
// Increase map speed by 1%
mapSpeed = mapSpeed * 1.01;
// Remove both police cars
police1.destroy();
police2.destroy();
policeCars.splice(j, 1);
policeCars.splice(i, 1);
collided = true;
break;
}
}
if (collided) break;
}
// Clean up police cars that went off screen
for (var i = policeCars.length - 1; i >= 0; i--) {
var police = policeCars[i];
if (police.y > 2732 + 100) {
police.destroy();
policeCars.splice(i, 1);
}
}
// Clean up diamonds that went off screen
for (var i = diamonds.length - 1; i >= 0; i--) {
var diamond = diamonds[i];
if (diamond.y > 2732 + 100) {
diamond.destroy();
diamonds.splice(i, 1);
// Spawn new diamond
spawnDiamond();
}
}
// 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();
}
// Spawn new diamonds periodically
if (LK.ticks % 500 === 0) {
spawnDiamond();
}
// Update score and check milestones
updateScore();
checkMilestone();
// Win condition
if (LK.getScore() >= 10000) {
LK.showYouWin();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -249,13 +249,13 @@
var carGraphics = self.attachAsset('getawayCar', {
anchorX: 0.5,
anchorY: 0.5
});
- self.speed = 5;
- self.maxSpeed = 12;
+ self.speed = 8;
+ self.maxSpeed = 18;
self.velocityX = 0;
self.velocityY = 0;
- self.acceleration = 0.5;
+ self.acceleration = 0.8;
self.friction = 0.85;
self.update = function () {
var inputX = 0;
var inputY = 0;