User prompt
If the obstacle in the right lane,spawn another obstacle to right.if the obstacle in the left lane spawn another obstacle to left
User prompt
And add another obstacle the side of obstacles(make two obstacles in one lane)
User prompt
Make the obstacles spawn to dotted line closer
User prompt
Add tap to switch lanes logic back
User prompt
Remove the car outside logic
User prompt
Make the car go outside of the road when tapped on screen and make it to normal position again
User prompt
Remove the menu,everything crashed
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'visible')' in or related to this line: 'menuBg.visible = true;' Line Number: 200
User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'visible')' in or related to this line: 'menuBg.visible = true;' Line Number: 199
User prompt
Add a start menu,add a backgroun image to menu and add a play button
User prompt
Also make the car 1.5x bigger
User prompt
Make obstacles bigger and centered in sideways
User prompt
Make the road 4x wide and make the car and obstacles position match the road
User prompt
Make everything in normal size again
User prompt
I just mean the make car auto centering wider,make everything normal
User prompt
Make it more wider for better visual effect
User prompt
Make the car start in the middle when its not touched
User prompt
Add Day night but not headlights
User prompt
Just remove the headlights it makes a lot of bugs
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y += car.speed;' Line Number: 293
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y += car.speed;' Line Number: 292
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'self.y += car.speed;' Line Number: 291
User prompt
Please fix the bug: 'LK.getPolygon is not a function' in or related to this line: 'var poly = LK.getPolygon([[-baseOffset, baseY], [0, tipY], [baseOffset, baseY]], color, alpha);' Line Number: 58
User prompt
Remove the headlights,just make them two long triangles the long tip touching to cars front,and make them yellow
User prompt
Also add car headlights when its night ↪💡 Consider importing and using the following plugins: @upit/tween.v1
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Car class
var Car = Container.expand(function () {
var self = Container.call(this);
var carAsset = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
// No headlights
// Direction: 1 = up-right (45deg), -1 = up-left (135deg)
self.direction = 1;
self.speed = 32; // initial speed in px per tick
self.angleRight = Math.PI / 4; // 45deg (up-right)
self.angleLeft = 3 * Math.PI / 4; // 135deg (up-left)
carAsset.rotation = self.angleRight;
// Only allow up-left and up-right, always moving up at an angle
self.setDirection = function (dir) {
// Only allow -1 (up-left) or 1 (up-right)
if (dir !== 1 && dir !== -1) return;
if (self.direction === dir) return; // Already in this direction, do nothing
// Animate rotation
tween(carAsset, {
rotation: dir === 1 ? self.angleRight : self.angleLeft
}, {
duration: 120,
easing: tween.cubicOut
});
// Animate lane change (x position)
// Road line is centered at 2048/2, width 1200 (4x)
var roadLineCenter = 2048 / 2;
var roadLineWidth = 1200;
var obsMargin = 40;
var obsWidth = 160;
var carTravelEdge = roadLineWidth / 2 - obsWidth / 2 - obsMargin;
var targetX = roadLineCenter + dir * carTravelEdge;
// Stop any previous x tweens
tween.stop(self, {
x: true
});
tween(self, {
x: targetX
}, {
duration: 220,
easing: tween.cubicOut
});
self.direction = dir;
};
// Move car visually left/right (simulate up-left/up-right)
self.moveForward = function () {
// Car moves sideways along the gray road line based on direction
// Road line is centered at 2048/2, width 1200 (4x)
var roadLineCenter = 2048 / 2;
var roadLineWidth = 1200;
// Move car to the OUTER side of the grey line (roadLine), not inside it
// The roadLine is 1200px wide, the road itself is 2400px wide, so the outer edge is at roadLineCenter ± roadLineWidth/2
// Place car so its edge is just outside the roadLine, but still inside the road
var roadWidth = 2400;
var carHalfW = self.width / 2;
// Set carTravelEdge so car's edge matches obstacle X offset (so car aligns with obstacles)
// Use the same calculation as obsXOffset in spawnObstacle
var obsMargin = 40;
var obsWidth = 160;
var carTravelEdge = roadLineWidth / 2 - obsWidth / 2 - obsMargin;
// -1 = left, 1 = right
var targetX = roadLineCenter + self.direction * carTravelEdge;
// Smoothly move car toward targetX
var moveSpeed = 0.22; // 0..1, how fast to interpolate
self.x += (targetX - self.x) * moveSpeed;
// Make car always match obstacle's rotation (90deg, PI/2 radians)
carAsset.rotation = Math.PI / 2;
self.lastX = self.x;
self.lastX = self.x;
};
// Reset to center bottom
self.resetPosition = function () {
self.x = 2048 / 2;
self.y = 2732 - 350;
self.setDirection(1);
};
return self;
});
// White dotted line class
var DottedLine = Container.expand(function () {
var self = Container.call(this);
// Each dotted line is a white rectangle (box)
var dotWidth = 40;
var dotHeight = 100;
var dotAsset = self.attachAsset('dottedLine', {
anchorX: 0.5,
anchorY: 0.5
});
// Set size and color
dotAsset.width = dotWidth;
dotAsset.height = dotHeight;
dotAsset.color = 0xffffff;
// Center on road
self.x = 2048 / 2;
// y is set on spawn
self.update = function () {
// Move down at car speed
if (typeof car !== "undefined" && car && typeof car.speed === "number") {
self.y += car.speed;
}
// Remove if offscreen (handled in game.update)
};
return self;
});
// Obstacle class
var Obstacle = Container.expand(function () {
var self = Container.call(this);
// Randomly pick a color for the obstacle: green, blue, red, or black
var colors = [0x2ecc40, 0x1877f7, 0xd83318, 0x000000];
var colorIdx = Math.floor(Math.random() * colors.length);
// Use a box shape for the obstacle, colored accordingly
var obsAsset = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
obsAsset.shape = 'box';
obsAsset.width = 320;
obsAsset.height = 200;
obsAsset.color = colors[colorIdx];
// Rotate 90 degrees (PI/2 radians) so the rectangle is horizontal
obsAsset.rotation = Math.PI / 2;
// side: -1 = left, 1 = right
self.side = 1;
self.passed = false;
// setSide is no longer needed, obstacles are placed directly on the gray line in spawnObstacle
// Set y position
self.setY = function (y) {
self.y = y;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x222222
});
/****
* Game Code
****/
// Road: dark gray box, 2400x2732 (full height, 4x wide)
// Obstacle: yellow ellipse, 160x100
// Car: red box, 180x120
// Road
var road = LK.getAsset('road', {
anchorX: 0.5,
anchorY: 0,
x: 2048 / 2,
y: 0
});
road.width = 2400;
road.height = 2732;
game.addChild(road);
// Add a vertical gray line in the center of the road
var roadLine;
var roadLineAsset = LK.getAsset('roadLine', {
anchorX: 0.5,
anchorY: 0,
x: 2048 / 2,
y: 0
});
roadLineAsset.width = 1200;
roadLineAsset.height = 2732;
game.addChild(roadLineAsset);
// Car
// (Drifting line removed)
var car = new Car();
game.addChild(car);
car.resetPosition();
// Obstacles array
var obstacles = [];
// Score
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Dotted lines (white, moving down the center of the road)
var dottedLines = [];
var dottedLineHeight = 100;
var dottedLineSpacing = 300;
var numDottedLines = Math.ceil(2732 / dottedLineSpacing) + 2; // enough to cover screen + buffer
for (var i = 0; i < numDottedLines; ++i) {
var dot = new DottedLine();
// Always spawn at the top middle, spaced downwards
dot.x = 2048 / 2;
dot.y = -dottedLineHeight / 2 + i * dottedLineSpacing;
dottedLines.push(dot);
game.addChild(dot);
}
// Game state
var gameOver = false;
var passedObstacles = 0;
var ticksSinceLastObstacle = 0;
var obstacleInterval = 45; // ticks between obstacles (start)
var minObstacleInterval = 18; // minimum interval (faster)
var speedIncreaseEvery = 10; // every 10 obstacles, speed up
var carBaseSpeed = 32;
var carMaxSpeed = 72;
// Night/Day cycle variables
var isNight = false;
var lastNightDayScore = 0;
// Overlay for night effect (covers the whole game area, fades in/out)
var nightOverlay = LK.getAsset('road', {
anchorX: 0.5,
anchorY: 0,
x: 2048 / 2,
y: 0
});
nightOverlay.width = 2400;
nightOverlay.height = 2732;
nightOverlay.color = 0x000000;
nightOverlay.alpha = 0; // Start transparent (day)
game.addChild(nightOverlay);
// Helper: spawn obstacle
function spawnObstacle() {
var obs = new Obstacle();
// Always spawn obstacles on the gray road line, not on the dotted line
// The gray road line is centered at 2048/2, width 1200 (4x)
// Place obstacles randomly left or right of the center gray line, but not overlapping the center (dotted) line
var roadLineCenter = 2048 / 2;
var roadLineWidth = 1200;
var obsMargin = 40;
var obsWidth = 320;
var obsXOffset = roadLineWidth / 2 - obsWidth / 2 - obsMargin;
// Randomly left or right of the center gray line
var side = Math.random() < 0.5 ? -1 : 1;
obs.x = roadLineCenter + side * obsXOffset;
obs.y = -100;
obstacles.push(obs);
game.addChild(obs);
}
// Helper: update score
function updateScore() {
scoreTxt.setText(LK.getScore());
}
// Helper: reset game state
function resetGame() {
// Remove all obstacles
for (var i = 0; i < obstacles.length; ++i) {
obstacles[i].destroy();
}
obstacles = [];
car.resetPosition();
car.speed = carBaseSpeed;
obstacleInterval = 90;
passedObstacles = 0;
ticksSinceLastObstacle = 0;
// Reset dotted lines to initial positions
for (var i = 0; i < dottedLines.length; ++i) {
dottedLines[i].x = 2048 / 2;
dottedLines[i].y = -dottedLineHeight / 2 + i * 300;
}
LK.setScore(0);
updateScore();
gameOver = false;
autoMode = false;
carOutside = false;
carNormalX = null;
carOutsideX = null;
if (typeof updateAutoBtn === "function" && typeof autoBtn !== "undefined") updateAutoBtn();
// Reset night/day cycle
isNight = false;
lastNightDayScore = 0;
tween.stop(nightOverlay, {
alpha: true
});
nightOverlay.alpha = 0;
}
// Touch/tap: make car go outside road, then return to normal on next tap
var carOutside = false;
var carNormalX = null;
var carOutsideX = null;
game.down = function (x, y, obj) {
if (gameOver) return;
if (autoMode) return;
// On first tap, move car outside road (to the right)
if (!carOutside) {
// Save normal position
carNormalX = car.x;
// Calculate outside X (move car just outside the road's right edge)
var roadCenter = 2048 / 2;
var roadWidth = 2400;
var carHalfW = car.width / 2;
carOutsideX = roadCenter + roadWidth / 2 + carHalfW + 40; // 40px margin
// Animate car to outside position
tween(car, {
x: carOutsideX
}, {
duration: 220,
easing: tween.cubicOut
});
carOutside = true;
} else {
// On next tap, return car to normal position
if (carNormalX !== null) {
tween(car, {
x: carNormalX
}, {
duration: 220,
easing: tween.cubicOut
});
}
carOutside = false;
}
};
// Main game loop
game.update = function () {
if (gameOver) return;
// Move car
if (autoMode && !gameOver) {
// Find the closest obstacle ahead of the car
var closestObs = null;
var minDist = Infinity;
for (var i = 0; i < obstacles.length; ++i) {
var obs = obstacles[i];
if (obs.y > car.y - 200 && obs.y < car.y + 400) {
// only consider obstacles in front
var dist = Math.abs(obs.y - car.y);
if (dist < minDist) {
minDist = dist;
closestObs = obs;
}
}
}
if (closestObs) {
// If the obstacle is on the same side as the car, switch direction
var carSide = car.x > 2048 / 2 ? 1 : -1;
var obsSide = closestObs.x > 2048 / 2 ? 1 : -1;
if (carSide === obsSide) {
car.setDirection(-car.direction);
}
}
}
// If not autoMode, move car toward center X (normal centering, not wide)
if (!autoMode && !gameOver) {
var centerX = 2048 / 2;
var moveSpeed = 0.12; // slightly slower for normal effect
car.x += (centerX - car.x) * moveSpeed;
}
car.moveForward();
// (Drifting line update removed)
// Keep car inside road bounds, unless carOutside is true
var roadCenter = 2048 / 2;
var roadWidth = 2400;
var carHalfW = car.width / 2;
if (!carOutside) {
if (car.x < roadCenter - roadWidth / 2 + carHalfW) {
car.x = roadCenter - roadWidth / 2 + carHalfW;
}
if (car.x > roadCenter + roadWidth / 2 - carHalfW) {
car.x = roadCenter + roadWidth / 2 - carHalfW;
}
}
// Move dotted lines down and handle despawn/spawn
for (var i = dottedLines.length - 1; i >= 0; --i) {
var dot = dottedLines[i];
dot.update(); // Move the dotted line at car.speed
// If offscreen at bottom, despawn and spawn a new one at the top
if (dot.y > 2732 + dottedLineHeight / 2) {
// Remove from game and array
dot.destroy();
dottedLines.splice(i, 1);
// Find minimum y among all remaining dots
var minY = Infinity;
for (var j = 0; j < dottedLines.length; ++j) {
if (dottedLines[j].y < minY) minY = dottedLines[j].y;
}
// Spawn new dot at top middle, spaced above the highest
var newDot = new DottedLine();
newDot.x = 2048 / 2;
// If there are no dots left, just place at top
if (dottedLines.length === 0) {
newDot.y = -dottedLineHeight / 2;
} else {
newDot.y = minY - dottedLineSpacing;
}
dottedLines.push(newDot);
game.addChild(newDot);
}
}
// Move obstacles straight down
for (var i = obstacles.length - 1; i >= 0; --i) {
var obs = obstacles[i];
obs.y += car.speed;
// Check for collision
if (!gameOver && car.intersects(obs)) {
LK.effects.flashScreen(0xff0000, 800);
gameOver = true;
LK.showGameOver();
return;
}
// Check if passed (obstacle is below car, and not already counted)
if (!obs.passed && obs.y > car.y) {
obs.passed = true;
LK.setScore(LK.getScore() + 5);
updateScore();
passedObstacles += 1;
// Speed up every N obstacles
if (passedObstacles % speedIncreaseEvery === 0 && car.speed < carMaxSpeed) {
car.speed += 2;
if (obstacleInterval > minObstacleInterval) {
obstacleInterval -= 6;
if (obstacleInterval < minObstacleInterval) obstacleInterval = minObstacleInterval;
}
}
// --- Night/Day cycle logic ---
var score = LK.getScore();
if (Math.floor(score / 100) !== Math.floor(lastNightDayScore / 100)) {
isNight = !isNight;
lastNightDayScore = score;
// Animate overlay alpha: 0.6 for night, 0 for day
tween.stop(nightOverlay, {
alpha: true
});
tween(nightOverlay, {
alpha: isNight ? 0.6 : 0
}, {
duration: 1200,
easing: tween.cubicInOut
});
}
// --- End Night/Day cycle logic ---
}
// Remove if offscreen
if (obs.y > 2732 + 120 || obs.x < 0 - 200 || obs.x > 2048 + 200) {
obs.destroy();
obstacles.splice(i, 1);
}
}
// Spawn new obstacles
ticksSinceLastObstacle += 1;
if (ticksSinceLastObstacle >= obstacleInterval) {
spawnObstacle();
ticksSinceLastObstacle = 0;
}
};
// Reset game on game over
game.on('reset', function () {
resetGame();
});
// Initial state
resetGame();
// --- Auto Button UI ---
var autoMode = false;
var autoBtn = new Text2('AUTO', {
size: 90,
fill: 0xFFFFFF,
fontWeight: "bold",
background: 0x008080
});
autoBtn.anchor.set(1, 1); // bottom right
autoBtn.x = LK.gui.width - 40;
autoBtn.y = LK.gui.height - 40;
autoBtn.alpha = 0.85;
autoBtn.interactive = true;
autoBtn.buttonMode = true;
LK.gui.bottomRight.addChild(autoBtn);
// Update button appearance
function updateAutoBtn() {
if (typeof autoBtn !== "undefined" && autoBtn && typeof autoBtn.setText === "function") {
autoBtn.setText(autoMode ? "AUTO ON" : "AUTO");
autoBtn.alpha = autoMode ? 1 : 0.85;
autoBtn.fill = autoMode ? "#00ff00" : "#ffffff";
}
}
updateAutoBtn();
// Toggle auto mode on button press
autoBtn.down = function (x, y, obj) {
autoMode = !autoMode;
updateAutoBtn();
};
// --- End Auto Button UI --- ===================================================================
--- original.js
+++ change.js
@@ -269,8 +269,11 @@
LK.setScore(0);
updateScore();
gameOver = false;
autoMode = false;
+ carOutside = false;
+ carNormalX = null;
+ carOutsideX = null;
if (typeof updateAutoBtn === "function" && typeof autoBtn !== "undefined") updateAutoBtn();
// Reset night/day cycle
isNight = false;
lastNightDayScore = 0;
@@ -278,14 +281,44 @@
alpha: true
});
nightOverlay.alpha = 0;
}
-// Touch/tap: switch direction (visual only)
+// Touch/tap: make car go outside road, then return to normal on next tap
+var carOutside = false;
+var carNormalX = null;
+var carOutsideX = null;
game.down = function (x, y, obj) {
if (gameOver) return;
if (autoMode) return;
- var newDir = car.direction === 1 ? -1 : 1;
- car.setDirection(newDir);
+ // On first tap, move car outside road (to the right)
+ if (!carOutside) {
+ // Save normal position
+ carNormalX = car.x;
+ // Calculate outside X (move car just outside the road's right edge)
+ var roadCenter = 2048 / 2;
+ var roadWidth = 2400;
+ var carHalfW = car.width / 2;
+ carOutsideX = roadCenter + roadWidth / 2 + carHalfW + 40; // 40px margin
+ // Animate car to outside position
+ tween(car, {
+ x: carOutsideX
+ }, {
+ duration: 220,
+ easing: tween.cubicOut
+ });
+ carOutside = true;
+ } else {
+ // On next tap, return car to normal position
+ if (carNormalX !== null) {
+ tween(car, {
+ x: carNormalX
+ }, {
+ duration: 220,
+ easing: tween.cubicOut
+ });
+ }
+ carOutside = false;
+ }
};
// Main game loop
game.update = function () {
if (gameOver) return;
@@ -321,18 +354,20 @@
car.x += (centerX - car.x) * moveSpeed;
}
car.moveForward();
// (Drifting line update removed)
- // Keep car inside road bounds
+ // Keep car inside road bounds, unless carOutside is true
var roadCenter = 2048 / 2;
var roadWidth = 2400;
var carHalfW = car.width / 2;
- if (car.x < roadCenter - roadWidth / 2 + carHalfW) {
- car.x = roadCenter - roadWidth / 2 + carHalfW;
+ if (!carOutside) {
+ if (car.x < roadCenter - roadWidth / 2 + carHalfW) {
+ car.x = roadCenter - roadWidth / 2 + carHalfW;
+ }
+ if (car.x > roadCenter + roadWidth / 2 - carHalfW) {
+ car.x = roadCenter + roadWidth / 2 - carHalfW;
+ }
}
- if (car.x > roadCenter + roadWidth / 2 - carHalfW) {
- car.x = roadCenter + roadWidth / 2 - carHalfW;
- }
// Move dotted lines down and handle despawn/spawn
for (var i = dottedLines.length - 1; i >= 0; --i) {
var dot = dottedLines[i];
dot.update(); // Move the dotted line at car.speed
2d red car. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat,upper profile
A truck,2d,upper profile. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat.upper looking
A car crash effect,red,yellow and orange colors,put the outer side black line. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
Coin with 10 on it . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat