User prompt
Change how you move the player car, just follow the mouse x position to move left or right, no click needed
Code edit (5 edits merged)
Please save this source code
User prompt
Scale the traffic cars double compared to how it is right now
User prompt
Don't spawn any more traffic cars untli the existing one has disappear
Code edit (1 edits merged)
Please save this source code
User prompt
Ok the road looks like this: / \ So I want my trafficCars to appear in the middle of the screen (0.5, 0.5) like this /*\ and then they will go down left or right like /_ \ or / _\ and scaling as now
User prompt
Remove obstacles. Remove checkpoiints. Remove timebonus. Remove roadline.
User prompt
The trafficCars come from max about 1000 pixels above the bottom and they scale up as they come close to the playerCar. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Retro Rush: Arcade Driving Challenge
Initial prompt
Out run the retro arcade driving game
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0 }); /**** * Classes ****/ var PlayerCar = Container.expand(function () { var self = Container.call(this); var carGraphics = self.attachAsset('playerCar', { anchorX: 0.5, anchorY: 0.5 }); self.width = carGraphics.width; self.height = carGraphics.height; self.speed = 0; self.maxSpeed = 15; self.steering = 0; self.crashed = false; self.crash = function () { if (!self.crashed) { self.crashed = true; LK.getSound('crash').play(); LK.effects.flashObject(self, 0xFF0000, 1000); // Reduce speed on crash self.speed = Math.max(0, self.speed - 5); // Reset crash state after 1 second LK.setTimeout(function () { self.crashed = false; }, 1000); } }; self.update = function () { // Handle car physics if (!self.crashed) { self.speed = Math.min(self.maxSpeed, self.speed + 0.1); } // Apply steering if not crashed if (!self.crashed) { self.x += self.steering; } // Keep car within bounds if (self.x < self.width / 2) { self.x = self.width / 2; } if (self.x > 2048 - self.width / 2) { self.x = 2048 - self.width / 2; } }; return self; }); var TrafficCar = Container.expand(function () { var self = Container.call(this); var carGraphics = self.attachAsset('trafficCar', { anchorX: 0.5, anchorY: 0.5 }); self.width = carGraphics.width; self.height = carGraphics.height; self.speed = 5; self.startY = 1732; // Starting Y position (approx 1000px from bottom) self.targetY = 2732 + self.height; // Y position when fully off-screen (bottom) self.initialScale = 0.1; self.targetScale = 1.0; // Set initial scale self.scale.set(self.initialScale); self.update = function () { self.y += gameSpeed - self.speed; // Calculate progress towards target Y var progress = (self.y - self.startY) / (self.targetY - self.startY); progress = Math.max(0, Math.min(1, progress)); // Clamp between 0 and 1 // Interpolate scale based on progress var currentScale = self.initialScale + (self.targetScale - self.initialScale) * progress; self.scale.set(currentScale); // Destroy if off screen if (self.y > self.targetY) { // Check against targetY self.destroy(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Game state variables var gameSpeed = 10; var gameStarted = false; var gameTime = 30; // Initial time in seconds var distance = 0; var level = 1; var checkpointDistance = 500; // Distance between checkpoints var nextCheckpointAt = checkpointDistance; var trafficCars = []; var obstacles = []; var checkpoints = []; var timeBonuses = []; var difficultyTimer; // Create road var road = LK.getAsset('road', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(road); // Create player car var player = new PlayerCar(); player.x = 2048 / 2; player.y = 2732 - 300; game.addChild(player); // Create UI elements var timeText = new Text2('Time: 30', { size: 80, fill: 0xFFFFFF }); timeText.anchor.set(0, 0); LK.gui.topRight.addChild(timeText); timeText.x = -250; // Offset from right edge var scoreText = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreText.anchor.set(0, 0); LK.gui.top.addChild(scoreText); var levelText = new Text2('Level: 1', { size: 80, fill: 0xFFFFFF }); levelText.anchor.set(0, 0); LK.gui.topRight.addChild(levelText); levelText.y = 100; // Offset below time levelText.x = -250; // Offset from right edge var startText = new Text2('TAP TO START', { size: 120, fill: 0xFFFFFF }); startText.anchor.set(0.5, 0.5); LK.gui.center.addChild(startText); // Functions to spawn game elements function spawnTrafficCar() { var car = new TrafficCar(); car.x = 400 + Math.random() * (2048 - 800); // Random x position on road car.y = car.startY; // Start at the defined startY car.speed = 3 + Math.random() * 5; // Random speed trafficCars.push(car); game.addChild(car); // Schedule next car spawn based on difficulty var nextSpawnTime = 2000 - level * 100; nextSpawnTime = Math.max(nextSpawnTime, 500); // Minimum 0.5 seconds LK.setTimeout(spawnTrafficCar, nextSpawnTime); } // Start game function function startGame() { gameStarted = true; gameTime = 30; distance = 0; level = 1; gameSpeed = 10; nextCheckpointAt = checkpointDistance; LK.setScore(0); // Update UI scoreText.setText('Score: 0'); timeText.setText('Time: ' + Math.ceil(gameTime)); levelText.setText('Level: ' + level); // Remove start text LK.gui.center.removeChild(startText); // Start spawning game elements spawnTrafficCar(); // Set timer to increase difficulty difficultyTimer = LK.setInterval(function () { if (gameStarted) { level++; gameSpeed += 1; levelText.setText('Level: ' + level); } }, 30000); // Increase difficulty every 30 seconds // Play background music LK.playMusic('bgmusic'); } // Handle touch input game.down = function (x, y) { if (!gameStarted) { startGame(); return; } // Store starting touch position for steering game.lastTouchX = x; }; game.move = function (x, y) { if (!gameStarted || !game.lastTouchX) { return; } // Calculate steering based on touch movement var deltaX = x - game.lastTouchX; player.steering = deltaX * 0.2; // Scale down movement // Update last position game.lastTouchX = x; }; game.up = function () { if (gameStarted) { // Stop steering when touch ends player.steering = 0; game.lastTouchX = null; } }; // Main game update function game.update = function () { if (!gameStarted) { return; } // Update game time gameTime -= 1 / 60; // Assuming 60 FPS timeText.setText('Time: ' + Math.ceil(gameTime)); // Update distance if (gameStarted) { distance += gameSpeed; LK.setScore(Math.floor(distance / 10)); scoreText.setText('Score: ' + LK.getScore()); } // Check for game over if (gameTime <= 0) { endGame(); return; } // Check collisions with traffic cars for (var i = trafficCars.length - 1; i >= 0; i--) { var car = trafficCars[i]; if (player.intersects(car) && !player.crashed) { player.crash(); trafficCars.splice(i, 1); car.destroy(); } } }; function endGame() { if (!gameStarted) { return; } gameStarted = false; // Save high score if (LK.getScore() > storage.highScore) { storage.highScore = LK.getScore(); } // Clear any intervals LK.clearInterval(difficultyTimer); // Show game over LK.showGameOver(); }
===================================================================
--- original.js
+++ change.js
@@ -8,44 +8,8 @@
/****
* Classes
****/
-var Checkpoint = Container.expand(function () {
- var self = Container.call(this);
- var checkpointGraphics = self.attachAsset('checkpoint', {
- anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.5
- });
- self.width = checkpointGraphics.width;
- self.height = checkpointGraphics.height;
- self.passed = false;
- self.update = function () {
- self.y += gameSpeed;
- // Destroy if off screen
- if (self.y > 2732 + self.height) {
- self.destroy();
- }
- };
- return self;
-});
-var Obstacle = Container.expand(function () {
- var self = Container.call(this);
- var obstacleGraphics = self.attachAsset('obstacle', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.width = obstacleGraphics.width;
- self.height = obstacleGraphics.height;
- self.update = function () {
- self.y += gameSpeed;
- // Destroy if off screen
- if (self.y > 2732 + self.height) {
- self.destroy();
- }
- };
- return self;
-});
var PlayerCar = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('playerCar', {
anchorX: 0.5,
@@ -88,73 +52,8 @@
}
};
return self;
});
-var RoadLine = Container.expand(function () {
- var self = Container.call(this);
- var lineGraphics = self.attachAsset('roadLine', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 10;
- self.update = function () {
- self.y += self.speed;
- // Reset when off screen
- if (self.y > 2732) {
- self.y = -80;
- }
- };
- return self;
-});
-var TimeBonus = Container.expand(function () {
- var self = Container.call(this);
- var bonusGraphics = self.attachAsset('timeBonus', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.width = bonusGraphics.width;
- self.height = bonusGraphics.height;
- self.timeValue = 5; // 5 second bonus
- // Make it pulse
- tween(bonusGraphics, {
- scaleX: 1.2,
- scaleY: 1.2
- }, {
- duration: 500,
- easing: tween.easeInOut,
- onFinish: function onFinish() {
- tween(bonusGraphics, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 500,
- easing: tween.easeInOut,
- onFinish: function onFinish() {
- // Repeat the pulse animation
- if (self.parent) {
- tween(bonusGraphics, {
- scaleX: 1.2,
- scaleY: 1.2
- }, {
- duration: 500,
- easing: tween.easeInOut
- });
- }
- }
- });
- }
- });
- self.update = function () {
- self.y += gameSpeed;
- // Rotate the bonus
- bonusGraphics.rotation += 0.05;
- // Destroy if off screen
- if (self.y > 2732 + self.height) {
- self.destroy();
- }
- };
- return self;
-});
var TrafficCar = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('trafficCar', {
anchorX: 0.5,
@@ -207,9 +106,8 @@
var trafficCars = [];
var obstacles = [];
var checkpoints = [];
var timeBonuses = [];
-var roadLines = [];
var difficultyTimer;
// Create road
var road = LK.getAsset('road', {
anchorX: 0.5,
@@ -222,16 +120,8 @@
var player = new PlayerCar();
player.x = 2048 / 2;
player.y = 2732 - 300;
game.addChild(player);
-// Create road lines
-for (var i = 0; i < 20; i++) {
- var roadLine = new RoadLine();
- roadLine.x = 2048 / 2;
- roadLine.y = i * 150 - 80; // Distribute lines evenly, some off-screen
- roadLines.push(roadLine);
- game.addChild(roadLine);
-}
// Create UI elements
var timeText = new Text2('Time: 30', {
size: 80,
fill: 0xFFFFFF
@@ -271,35 +161,8 @@
var nextSpawnTime = 2000 - level * 100;
nextSpawnTime = Math.max(nextSpawnTime, 500); // Minimum 0.5 seconds
LK.setTimeout(spawnTrafficCar, nextSpawnTime);
}
-function spawnObstacle() {
- var obstacle = new Obstacle();
- obstacle.x = 400 + Math.random() * (2048 - 800); // Random x position on road
- obstacle.y = -100; // Start offscreen
- obstacles.push(obstacle);
- game.addChild(obstacle);
- // Schedule next obstacle spawn based on difficulty
- var nextSpawnTime = 3000 - level * 150;
- nextSpawnTime = Math.max(nextSpawnTime, 1000); // Minimum 1 second
- LK.setTimeout(spawnObstacle, nextSpawnTime);
-}
-function spawnCheckpoint() {
- var checkpoint = new Checkpoint();
- checkpoint.x = 2048 / 2;
- checkpoint.y = -30; // Start offscreen
- checkpoints.push(checkpoint);
- game.addChild(checkpoint);
-}
-function spawnTimeBonus() {
- var bonus = new TimeBonus();
- bonus.x = 400 + Math.random() * (2048 - 800); // Random x position on road
- bonus.y = -60; // Start offscreen
- timeBonuses.push(bonus);
- game.addChild(bonus);
- // Schedule next bonus spawn (rarer than obstacles)
- LK.setTimeout(spawnTimeBonus, 5000 + Math.random() * 10000);
-}
// Start game function
function startGame() {
gameStarted = true;
gameTime = 30;
@@ -315,20 +178,14 @@
// Remove start text
LK.gui.center.removeChild(startText);
// Start spawning game elements
spawnTrafficCar();
- spawnObstacle();
- spawnTimeBonus();
// Set timer to increase difficulty
difficultyTimer = LK.setInterval(function () {
if (gameStarted) {
level++;
gameSpeed += 1;
levelText.setText('Level: ' + level);
- // Update road line speed
- for (var i = 0; i < roadLines.length; i++) {
- roadLines[i].speed = gameSpeed;
- }
}
}, 30000); // Increase difficulty every 30 seconds
// Play background music
LK.playMusic('bgmusic');
@@ -366,18 +223,13 @@
}
// Update game time
gameTime -= 1 / 60; // Assuming 60 FPS
timeText.setText('Time: ' + Math.ceil(gameTime));
- // Update distance and check for checkpoints
+ // Update distance
if (gameStarted) {
distance += gameSpeed;
LK.setScore(Math.floor(distance / 10));
scoreText.setText('Score: ' + LK.getScore());
- // Check if we need to spawn a checkpoint
- if (distance >= nextCheckpointAt) {
- spawnCheckpoint();
- nextCheckpointAt += checkpointDistance;
- }
}
// Check for game over
if (gameTime <= 0) {
endGame();
@@ -391,78 +243,8 @@
trafficCars.splice(i, 1);
car.destroy();
}
}
- // Check collisions with obstacles
- for (var i = obstacles.length - 1; i >= 0; i--) {
- var obstacle = obstacles[i];
- if (player.intersects(obstacle) && !player.crashed) {
- player.crash();
- obstacles.splice(i, 1);
- obstacle.destroy();
- }
- }
- // Check collisions with checkpoints
- for (var i = checkpoints.length - 1; i >= 0; i--) {
- var checkpoint = checkpoints[i];
- if (player.intersects(checkpoint) && !checkpoint.passed) {
- checkpoint.passed = true;
- LK.getSound('checkpoint').play();
- // Add time bonus for passing checkpoint
- gameTime += 10;
- // Flash checkpoint
- LK.effects.flashObject(checkpoint, 0x00FF00, 500);
- // Animate timeText to show bonus
- timeText.setText('Time: ' + Math.ceil(gameTime) + ' +10');
- tween(timeText, {
- scaleX: 1.3,
- scaleY: 1.3
- }, {
- duration: 300,
- easing: tween.easeOut,
- onFinish: function onFinish() {
- tween(timeText, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 300,
- easing: tween.easeIn
- });
- }
- });
- }
- }
- // Check collisions with time bonuses
- for (var i = timeBonuses.length - 1; i >= 0; i--) {
- var bonus = timeBonuses[i];
- if (player.intersects(bonus)) {
- LK.getSound('pickup').play();
- // Add time bonus
- gameTime += bonus.timeValue;
- // Update display with bonus
- timeText.setText('Time: ' + Math.ceil(gameTime) + ' +' + bonus.timeValue);
- // Animate timeText
- tween(timeText, {
- scaleX: 1.3,
- scaleY: 1.3
- }, {
- duration: 300,
- easing: tween.easeOut,
- onFinish: function onFinish() {
- tween(timeText, {
- scaleX: 1.0,
- scaleY: 1.0
- }, {
- duration: 300,
- easing: tween.easeIn
- });
- }
- });
- // Remove bonus
- timeBonuses.splice(i, 1);
- bonus.destroy();
- }
- }
};
function endGame() {
if (!gameStarted) {
return;