/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Taxi = Container.expand(function () {
var self = Container.call(this);
var taxiGraphics = self.attachAsset('taxi', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 12;
self.update = function () {
// Keep taxi in bounds (narrower road width)
if (self.x < 400) self.x = 400;
if (self.x > 1648) self.x = 1648;
};
return self;
});
var TrafficCar = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('trafficCar', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8 + Math.random() * 6;
self.lastY = 0;
self.update = function () {
self.lastY = self.y;
self.y += self.speed;
// Check collision with other traffic cars and prevent overlap
for (var i = 0; i < trafficCars.length; i++) {
var otherCar = trafficCars[i];
if (otherCar !== self && self.intersects(otherCar)) {
// Calculate distance and move cars apart more effectively
var distanceX = Math.abs(self.x - otherCar.x);
var distanceY = Math.abs(self.y - otherCar.y);
if (distanceY < 150) {
// Minimum safe distance
if (self.y > otherCar.y) {
self.y = otherCar.y + 150;
} else {
self.y = otherCar.y - 150;
}
}
// Also check horizontal overlap and adjust
if (distanceX < 130 && distanceY < 200) {
if (self.x < 1024) {
self.x -= 50;
} else {
self.x += 50;
}
// Keep within road bounds
if (self.x < 400) self.x = 400;
if (self.x > 1648) self.x = 1648;
}
break;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2C5F2D
});
/****
* Game Code
****/
// Game variables
var taxi;
var trafficCars = [];
var roadLines = [];
var spawnTimer = 0;
var roadSpeed = 12;
// Create road background
var road = game.addChild(LK.getAsset('road', {
x: 0,
y: 0
}));
// Create road lines for visual effect
for (var i = 0; i < 30; i++) {
var line = game.addChild(LK.getAsset('roadLine', {
anchorX: 0.5,
anchorY: 0.5
}));
line.x = 1024;
line.y = i * 120;
roadLines.push(line);
}
// Create taxi
taxi = game.addChild(new Taxi());
taxi.x = 1024;
taxi.y = 2200;
// Create score display
var scoreText = new Text2('Score: ' + LK.getScore(), {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
scoreText.y = 20;
// Drag controls for taxi
var isDragging = false;
var dragStartX = 0;
game.down = function (x, y, obj) {
isDragging = true;
dragStartX = x;
};
game.move = function (x, y, obj) {
if (isDragging) {
var deltaX = x - dragStartX;
taxi.x += deltaX;
dragStartX = x;
}
};
game.up = function (x, y, obj) {
isDragging = false;
};
function spawnTrafficCar() {
var car = new TrafficCar();
car.x = 450 + Math.random() * 1148; // Random position on narrower road
car.y = -50;
car.lastY = car.y;
trafficCars.push(car);
game.addChild(car);
}
game.update = function () {
spawnTimer++;
// Move road lines for visual effect
for (var i = 0; i < roadLines.length; i++) {
var line = roadLines[i];
line.y += roadSpeed;
if (line.y > 2732 + 50) {
line.y = -50;
}
}
// Spawn traffic cars less frequently
if (spawnTimer % 60 === 0) {
spawnTrafficCar();
}
// Update traffic cars
for (var i = trafficCars.length - 1; i >= 0; i--) {
var car = trafficCars[i];
if (car.y > 2732 + 50) {
car.destroy();
trafficCars.splice(i, 1);
// Increase score for dodging car
LK.setScore(LK.getScore() + 10);
scoreText.setText('Score: ' + LK.getScore());
continue;
}
// Check collision with taxi - GAME OVER if collision
if (taxi.intersects(car)) {
LK.getSound('crash').play();
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
return;
}
}
// Increase difficulty over time
if (spawnTimer % 600 === 0 && roadSpeed < 10) {
roadSpeed += 0.5;
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Taxi = Container.expand(function () {
var self = Container.call(this);
var taxiGraphics = self.attachAsset('taxi', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 12;
self.update = function () {
// Keep taxi in bounds (narrower road width)
if (self.x < 400) self.x = 400;
if (self.x > 1648) self.x = 1648;
};
return self;
});
var TrafficCar = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('trafficCar', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8 + Math.random() * 6;
self.lastY = 0;
self.update = function () {
self.lastY = self.y;
self.y += self.speed;
// Check collision with other traffic cars and prevent overlap
for (var i = 0; i < trafficCars.length; i++) {
var otherCar = trafficCars[i];
if (otherCar !== self && self.intersects(otherCar)) {
// Calculate distance and move cars apart more effectively
var distanceX = Math.abs(self.x - otherCar.x);
var distanceY = Math.abs(self.y - otherCar.y);
if (distanceY < 150) {
// Minimum safe distance
if (self.y > otherCar.y) {
self.y = otherCar.y + 150;
} else {
self.y = otherCar.y - 150;
}
}
// Also check horizontal overlap and adjust
if (distanceX < 130 && distanceY < 200) {
if (self.x < 1024) {
self.x -= 50;
} else {
self.x += 50;
}
// Keep within road bounds
if (self.x < 400) self.x = 400;
if (self.x > 1648) self.x = 1648;
}
break;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2C5F2D
});
/****
* Game Code
****/
// Game variables
var taxi;
var trafficCars = [];
var roadLines = [];
var spawnTimer = 0;
var roadSpeed = 12;
// Create road background
var road = game.addChild(LK.getAsset('road', {
x: 0,
y: 0
}));
// Create road lines for visual effect
for (var i = 0; i < 30; i++) {
var line = game.addChild(LK.getAsset('roadLine', {
anchorX: 0.5,
anchorY: 0.5
}));
line.x = 1024;
line.y = i * 120;
roadLines.push(line);
}
// Create taxi
taxi = game.addChild(new Taxi());
taxi.x = 1024;
taxi.y = 2200;
// Create score display
var scoreText = new Text2('Score: ' + LK.getScore(), {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
scoreText.y = 20;
// Drag controls for taxi
var isDragging = false;
var dragStartX = 0;
game.down = function (x, y, obj) {
isDragging = true;
dragStartX = x;
};
game.move = function (x, y, obj) {
if (isDragging) {
var deltaX = x - dragStartX;
taxi.x += deltaX;
dragStartX = x;
}
};
game.up = function (x, y, obj) {
isDragging = false;
};
function spawnTrafficCar() {
var car = new TrafficCar();
car.x = 450 + Math.random() * 1148; // Random position on narrower road
car.y = -50;
car.lastY = car.y;
trafficCars.push(car);
game.addChild(car);
}
game.update = function () {
spawnTimer++;
// Move road lines for visual effect
for (var i = 0; i < roadLines.length; i++) {
var line = roadLines[i];
line.y += roadSpeed;
if (line.y > 2732 + 50) {
line.y = -50;
}
}
// Spawn traffic cars less frequently
if (spawnTimer % 60 === 0) {
spawnTrafficCar();
}
// Update traffic cars
for (var i = trafficCars.length - 1; i >= 0; i--) {
var car = trafficCars[i];
if (car.y > 2732 + 50) {
car.destroy();
trafficCars.splice(i, 1);
// Increase score for dodging car
LK.setScore(LK.getScore() + 10);
scoreText.setText('Score: ' + LK.getScore());
continue;
}
// Check collision with taxi - GAME OVER if collision
if (taxi.intersects(car)) {
LK.getSound('crash').play();
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
return;
}
}
// Increase difficulty over time
if (spawnTimer % 600 === 0 && roadSpeed < 10) {
roadSpeed += 0.5;
}
};