User prompt
The game ends at 5000 meters and the car accelerates every 750 meters, and obstacles appear intermittently throughout the game.
User prompt
Please fix the bug: 'tween.to is not a function' in or related to this line: 'tween.to(car, {' Line Number: 98 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Let the car come from the road
User prompt
Let the cars come from where the character starts and the game ends at 2500 meters
Code edit (1 edits merged)
Please save this source code
User prompt
Endless Road Runner
Initial prompt
Let's say there is a car, it moves continuously on an endless platform, there are obstacles in front of it, it goes up with W, it goes down with S, the game speeds up 1.5 times every 250 meters.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.targetY = 0;
self.moveSpeed = 8;
self.update = function () {
// Smooth movement toward target position
var diff = self.targetY - self.y;
if (Math.abs(diff) > 2) {
self.y += diff * 0.15;
} else {
self.y = self.targetY;
}
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.update = function () {
self.x -= self.speed * gameSpeed;
};
return self;
});
var Road = Container.expand(function () {
var self = Container.call(this);
var roadGraphics = self.attachAsset('road', {
anchorX: 0,
anchorY: 0.5
});
self.speed = 6;
self.update = function () {
self.x -= self.speed * gameSpeed;
if (self.x <= -2048) {
self.x += 4096;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
var gameSpeed = 1;
var distanceTraveled = 0;
var lastSpeedIncrease = 0;
var obstacles = [];
var roadSegments = [];
var car;
var lastObstacleSpawn = 0;
var obstacleSpawnRate = 90;
// Create road segments
for (var i = 0; i < 3; i++) {
var roadSegment = new Road();
roadSegment.x = i * 2048;
roadSegment.y = 2732 / 2;
roadSegments.push(roadSegment);
game.addChild(roadSegment);
}
// Create car - spawn from left edge
car = new Car();
car.x = -100; // Start off-screen to the left
car.y = 2732 / 2;
car.targetY = 2732 / 2;
game.addChild(car);
// Animate car entering from the left
tween(car, {
x: 400
}, {
duration: 1500
}); // Move to playing position over 1.5 seconds
// Create distance display
var distanceText = new Text2('0m', {
size: 80,
fill: 0xFFFFFF
});
distanceText.anchor.set(0.5, 0);
LK.gui.top.addChild(distanceText);
// Create speed display
var speedText = new Text2('Speed: 1.0x', {
size: 60,
fill: 0xFFFFFF
});
speedText.anchor.set(1, 0);
LK.gui.topRight.addChild(speedText);
function spawnObstacle() {
var obstacle = new Obstacle();
obstacle.x = 2200;
// Spawn obstacles in upper or lower lane
var lanes = [2732 / 2 - 200, 2732 / 2 + 200];
obstacle.y = lanes[Math.floor(Math.random() * lanes.length)];
obstacles.push(obstacle);
game.addChild(obstacle);
}
function handleInput(y) {
var screenCenter = 2732 / 2;
if (y < screenCenter) {
// Move up
car.targetY = 2732 / 2 - 200;
} else {
// Move down
car.targetY = 2732 / 2 + 200;
}
}
game.down = function (x, y, obj) {
handleInput(y);
};
game.update = function () {
// Update distance traveled
distanceTraveled += gameSpeed * 0.5;
distanceText.setText(Math.floor(distanceTraveled) + 'm');
// Increase speed every 750 meters
if (distanceTraveled - lastSpeedIncrease >= 750) {
gameSpeed *= 1.5;
lastSpeedIncrease = distanceTraveled;
speedText.setText('Speed: ' + gameSpeed.toFixed(1) + 'x');
// Increase obstacle spawn rate with speed
obstacleSpawnRate = Math.max(40, obstacleSpawnRate - 10);
// Flash effect for speed increase
LK.effects.flashScreen(0xf39c12, 500);
}
// Spawn obstacles
if (LK.ticks - lastObstacleSpawn > obstacleSpawnRate) {
spawnObstacle();
lastObstacleSpawn = LK.ticks;
}
// Update obstacles and check collisions
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
// Remove obstacles that are off screen
if (obstacle.x < -200) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
// Check collision with car
if (car.intersects(obstacle)) {
LK.getSound('crash').play();
LK.effects.flashScreen(0xe74c3c, 1000);
LK.setScore(Math.floor(distanceTraveled));
LK.showGameOver();
return;
}
}
// Check win condition at 5000 meters
if (distanceTraveled >= 5000) {
LK.setScore(Math.floor(distanceTraveled));
LK.showYouWin();
return;
}
// Update score
LK.setScore(Math.floor(distanceTraveled));
};
LK.playMusic('bgmusic'); ===================================================================
--- original.js
+++ change.js
@@ -130,10 +130,10 @@
game.update = function () {
// Update distance traveled
distanceTraveled += gameSpeed * 0.5;
distanceText.setText(Math.floor(distanceTraveled) + 'm');
- // Increase speed every 250 meters
- if (distanceTraveled - lastSpeedIncrease >= 250) {
+ // Increase speed every 750 meters
+ if (distanceTraveled - lastSpeedIncrease >= 750) {
gameSpeed *= 1.5;
lastSpeedIncrease = distanceTraveled;
speedText.setText('Speed: ' + gameSpeed.toFixed(1) + 'x');
// Increase obstacle spawn rate with speed
@@ -163,10 +163,10 @@
LK.showGameOver();
return;
}
}
- // Check win condition at 2500 meters
- if (distanceTraveled >= 2500) {
+ // Check win condition at 5000 meters
+ if (distanceTraveled >= 5000) {
LK.setScore(Math.floor(distanceTraveled));
LK.showYouWin();
return;
}
Car, transparent background. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
A highly detailed 2D illustration of a modern police car, viewed from a 3/4 front angle. The car should feature realistic proportions, reflective black and white paint, a visible police logo on the doors, detailed sirens and light bars on top, chrome accents, visible tires with tread, a front grille with texture, and a clean, urban background with street reflections. Emphasize realism and intricate detail, with proper shading and highlights to give a semi-realistic hand-drawn look. The style should combine comic art with technical illustration. In-Game asset. 2d. High contrast. No shadows
A highly detailed 2D top-down view of an urban asphalt road with multiple lanes, crosswalks, lane markings, realistic cracks, manholes, faded paint, and small debris like leaves or pebbles. Include sidewalks with curbs, drainage grates, and subtle oil stains. The scene should reflect a realistic city environment, with attention to texture and lighting for depth. The illustration style should be clean yet rich in detail, combining technical drawing precision with artistic shading. In-Game asset. 2d. High contrast. No shadows