User prompt
Add night and day cycle in every 100 points ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Remove the road cross from the car
User prompt
Make lane change animation for car ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
I mean the road cross animation not the +
User prompt
Add a cross animation at the car
User prompt
Also make it same as the obstacle's degrees
User prompt
Make the car asset size same of the obstacles
User prompt
Make four car tires in same asset,not dedicated
User prompt
Now make it vertical
User prompt
Just make car horizantal
User prompt
Make it 180°
User prompt
Ake my car 90° tilted dont touch to tires
User prompt
Make it the opposite
User prompt
Match the tire's angle with car's angle
User prompt
Just add tires at directly in car asset,and make them black
User prompt
Add black tires at my car to make it look better
User prompt
Make the cars and line move 2 times faster
User prompt
Car still has cross animation,but when it animation finished cars look at 90°
User prompt
Make the car horizantal when it crossed other side
User prompt
Match the cartraveledge with obstacles
User prompt
İt doesnt have any effect
User prompt
Make it 5x
User prompt
Adjust it 2x
User prompt
Adjust cartraveledges
User prompt
Make the cars edges touch to outer sides of the roadline
/****
* 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
});
// --- Tires are now visually included in the car asset itself. No separate tire assets needed. ---
// 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;
self.direction = dir;
// Animate rotation
tween(carAsset, {
rotation: dir === 1 ? self.angleRight : self.angleLeft
}, {
duration: 120,
easing: tween.cubicOut
});
};
// 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 960
var roadLineCenter = 2048 / 2;
var roadLineWidth = 960;
// Move car to the OUTER side of the grey line (roadLine), not inside it
// The roadLine is 960px wide, the road itself is 600px 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 = 600;
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 = 80;
var obsWidth = 320;
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 vertical (rotation 0 radians)
carAsset.rotation = 0;
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 = 32;
var dotHeight = 120;
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
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, 600x2732 (full height)
// Obstacle: yellow ellipse, 160x100
// Car: red box, 180x120
// Road
var road = LK.getAsset('road', {
anchorX: 0.5,
anchorY: 0,
x: 2048 / 2,
y: 0
});
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
});
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 = 120;
var dottedLineSpacing = 320;
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;
// 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 960
// Place obstacles randomly left or right of the center gray line, but not overlapping the center (dotted) line
var roadLineCenter = 2048 / 2;
var roadLineWidth = 960;
var obsMargin = 80;
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 = -120;
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 * dottedLineSpacing;
}
LK.setScore(0);
updateScore();
gameOver = false;
autoMode = false;
if (typeof updateAutoBtn === "function" && typeof autoBtn !== "undefined") updateAutoBtn();
}
// Touch/tap: switch direction (visual only)
game.down = function (x, y, obj) {
if (gameOver) return;
if (autoMode) return;
var newDir = car.direction === 1 ? -1 : 1;
car.setDirection(newDir);
};
// 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);
}
}
}
car.moveForward();
// (Drifting line update removed)
// Keep car inside road bounds
var roadCenter = 2048 / 2;
var roadWidth = 600;
var carHalfW = car.width / 2;
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;
}
}
}
// 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
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