User prompt
remove the counter at the top
User prompt
remove the counter at the top and replace it with point counter
User prompt
give the player points when they dodge obstacles. 10 points every time an obstacles is dodged
User prompt
make the range that obstacles turns into green circle 1.5x larger
User prompt
adjust the obstacle and car hitboxes according to the new assets
User prompt
make it so that obstacles can't turn into green circles even if you are near them if they are behind the car
User prompt
make it so that the obstacles turn back from green circle to their original form when you avoid them
User prompt
increase the range at which obstacles turn into green circles when you are near them
User prompt
make sure only the obstacles that you are in the same lane with change into green circles, not other lanes
User prompt
make the obstacles turn back into their original asset after you dodge them
User prompt
it doesn't work
User prompt
make it so that you can control the car with left and right arrow keys
User prompt
increase the range more but not too much
User prompt
the obstacles don't turn into green circles when you get close to them, increase the range a little
User prompt
make sure only the obstacles that you are in the same lane with change into green circles, not other lanes
User prompt
it doesn't work
User prompt
make it so that when you are really close to the obstacles they turn into green circles ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
make all the lanes size even
Code edit (1 edits merged)
Please save this source code
User prompt
Highway Runner
Initial prompt
create a game where there is a yellow square (representing a car) and a wide road, make the road asset move down as you are playing to give the illusion of the car moving. make it so there are 4 lanes, each divided with white lines. as you are driving there will be obstacles randomly at lanes and you must make the square (representing a car) switch lanes horizontally to avoid the obstacles, make sure the obstacles move with the road so there is space for new obstacles.
/****
* 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.currentLane = 1; // Start in second lane (0-3)
self.isMoving = false;
self.switchLane = function (direction) {
if (self.isMoving) return;
var newLane = self.currentLane + direction;
if (newLane < 0 || newLane > 3) return;
self.isMoving = true;
self.currentLane = newLane;
var targetX = lanePositions[self.currentLane];
tween(self, {
x: targetX
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
self.isMoving = false;
}
});
};
return self;
});
var LaneDivider = Container.expand(function () {
var self = Container.call(this);
var dividerGraphics = self.attachAsset('laneDivider', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = baseSpeed;
self.update = function () {
self.y += self.speed;
if (self.y > 2732 + 50) {
self.y = -50;
}
};
return self;
});
var Obstacle = Container.expand(function (carRef) {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = baseSpeed;
self.transformed = false;
self.carRef = carRef;
self.lane = -1; // Initialize lane property
self.update = function () {
self.y += self.speed;
// Track if we're close to the car
if (self.carRef && !self.transformed) {
var distance = Math.abs(self.y - self.carRef.y);
// Check if close AND in the same lane
if (distance < 450 && self.lane === self.carRef.currentLane) {
// When really close and in same lane
self.transformed = true;
// Transform into green circle
self.removeChildren();
var greenCircle = self.attachAsset('greenCircle', {
anchorX: 0.5,
anchorY: 0.5
});
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x222222
});
/****
* Game Code
****/
// Game constants
var laneWidth = 512; // Width of each lane (2048 / 4)
var lanePositions = [256, 768, 1280, 1792]; // Center of each lane
var baseSpeed = 8;
var currentSpeed = baseSpeed;
var speedIncreaseRate = 0.0002;
var obstacleSpawnDelay = 90; // Ticks between obstacle spawns
var lastObstacleSpawn = 0;
// Game variables
var car;
var obstacles = [];
var laneDividers = [];
var distance = 0;
var scoreText;
// Create road background
var road = game.addChild(LK.getAsset('road', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
// Create lane dividers
for (var lane = 0; lane < 3; lane++) {
for (var i = 0; i < 30; i++) {
var divider = new LaneDivider();
divider.x = (lane + 1) * laneWidth; // Place dividers at lane boundaries
divider.y = i * 120;
laneDividers.push(divider);
game.addChild(divider);
}
}
// Create car
car = new Car();
car.x = lanePositions[1]; // Start in second lane
car.y = 2200;
game.addChild(car);
// Create score display
scoreText = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Input handling
game.down = function (x, y, obj) {
if (x < 1024) {
// Left side - move left
car.switchLane(-1);
} else {
// Right side - move right
car.switchLane(1);
}
};
// Keyboard input handling
LK.on('keydown', function (event) {
if (event.key === 'ArrowLeft') {
car.switchLane(-1);
} else if (event.key === 'ArrowRight') {
car.switchLane(1);
}
});
// Main game loop
game.update = function () {
// Update speed
currentSpeed = baseSpeed + LK.ticks * speedIncreaseRate;
// Update distance and score
distance += currentSpeed;
LK.setScore(Math.floor(distance / 10));
scoreText.setText(LK.getScore());
// Spawn obstacles
if (LK.ticks - lastObstacleSpawn > obstacleSpawnDelay) {
lastObstacleSpawn = LK.ticks;
// Random lane for obstacle
var lane = Math.floor(Math.random() * 4);
var obstacle = new Obstacle(car);
obstacle.x = lanePositions[lane];
obstacle.y = -100;
obstacle.speed = currentSpeed;
obstacle.lane = lane; // Set the lane for this obstacle
obstacles.push(obstacle);
game.addChild(obstacle);
// Decrease spawn delay as game progresses
obstacleSpawnDelay = Math.max(30, 90 - Math.floor(distance / 5000));
}
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
obstacle.speed = currentSpeed;
// Check if obstacle is off screen
if (obstacle.y > 2732 + 100) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
// Check collision with car
if (obstacle.intersects(car)) {
LK.showGameOver();
}
}
// Update lane dividers speed
for (var j = 0; j < laneDividers.length; j++) {
laneDividers[j].speed = currentSpeed;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -141,8 +141,16 @@
// Right side - move right
car.switchLane(1);
}
};
+// Keyboard input handling
+LK.on('keydown', function (event) {
+ if (event.key === 'ArrowLeft') {
+ car.switchLane(-1);
+ } else if (event.key === 'ArrowRight') {
+ car.switchLane(1);
+ }
+});
// Main game loop
game.update = function () {
// Update speed
currentSpeed = baseSpeed + LK.ticks * speedIncreaseRate;