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) { var distance = Math.abs(self.y - self.carRef.y); // Check if close AND in the same lane AND in front of car for transformation to green if (!self.transformed && distance < 500 && self.lane === self.carRef.currentLane && self.y < self.carRef.y) { // When really close and in same lane and in front of car self.transformed = true; // Transform into green circle self.removeChildren(); var greenCircle = self.attachAsset('greenCircle', { anchorX: 0.5, anchorY: 0.5 }); } else if (self.transformed && (self.y > self.carRef.y + 100 || self.lane !== self.carRef.currentLane)) { // Transform back when car has passed or in different lane self.transformed = false; // Transform back to red obstacle self.removeChildren(); var obstacleGraphics = self.attachAsset('obstacle', { 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); } }; // 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
@@ -62,11 +62,11 @@
self.y += self.speed;
// Track if we're close to the car
if (self.carRef) {
var distance = Math.abs(self.y - self.carRef.y);
- // Check if close AND in the same lane for transformation to green
- if (!self.transformed && distance < 500 && self.lane === self.carRef.currentLane) {
- // When really close and in same lane
+ // Check if close AND in the same lane AND in front of car for transformation to green
+ if (!self.transformed && distance < 500 && self.lane === self.carRef.currentLane && self.y < self.carRef.y) {
+ // When really close and in same lane and in front of car
self.transformed = true;
// Transform into green circle
self.removeChildren();
var greenCircle = self.attachAsset('greenCircle', {