User prompt
dont provide with too much spped if i want to move it only 1 place it move 2 place why
User prompt
give mine yellow car and others blue and give the both sides car shape ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
give the car's shape
Code edit (1 edits merged)
Please save this source code
User prompt
Highway Rush 3D
Initial prompt
want to be 3d car game
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var PlayerCar = Container.expand(function () {
var self = Container.call(this);
// Car body (main rectangle)
var carBody = self.attachAsset('playerCarBody', {
anchorX: 0.5,
anchorY: 0.5
});
// Car top (smaller rectangle for roof)
var carTop = self.attachAsset('playerCarTop', {
anchorX: 0.5,
anchorY: 0.5
});
carTop.y = -15;
// Windshield
var windshield = self.attachAsset('playerCarWindshield', {
anchorX: 0.5,
anchorY: 0.5
});
windshield.y = -20;
windshield.alpha = 0.7;
// Front wheels
var frontLeftWheel = self.attachAsset('playerCarWheel', {
anchorX: 0.5,
anchorY: 0.5
});
frontLeftWheel.x = -25;
frontLeftWheel.y = -30;
var frontRightWheel = self.attachAsset('playerCarWheel', {
anchorX: 0.5,
anchorY: 0.5
});
frontRightWheel.x = 25;
frontRightWheel.y = -30;
// Rear wheels
var rearLeftWheel = self.attachAsset('playerCarWheel', {
anchorX: 0.5,
anchorY: 0.5
});
rearLeftWheel.x = -25;
rearLeftWheel.y = 30;
var rearRightWheel = self.attachAsset('playerCarWheel', {
anchorX: 0.5,
anchorY: 0.5
});
rearRightWheel.x = 25;
rearRightWheel.y = 30;
// Store components for tinting
self.carBody = carBody;
self.carTop = carTop;
self.windshield = windshield;
self.wheels = [frontLeftWheel, frontRightWheel, rearLeftWheel, rearRightWheel];
// Method to change car color
self.setTint = function (color) {
self.carBody.tint = color;
self.carTop.tint = color;
};
return self;
});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 6;
self.depth = 1.0;
self.type = 'score'; // score, shield, speed
// Color based on type
self.setType = function (type) {
self.type = type;
if (type === 'shield') {
powerUpGraphics.tint = 0x9b59b6;
} else if (type === 'speed') {
powerUpGraphics.tint = 0xe67e22;
} else {
powerUpGraphics.tint = 0xf1c40f;
}
};
self.update = function () {
self.y += self.speed * gameSpeed;
// Update scale based on depth for 3D effect
var scale = self.depth * 0.3 + 0.2;
self.scaleX = scale;
self.scaleY = scale;
// Update depth
self.depth += 0.02 * gameSpeed;
// Gentle rotation animation
self.rotation += 0.1;
};
return self;
});
var RoadLane = Container.expand(function () {
var self = Container.call(this);
var laneGraphics = self.attachAsset('roadLane', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 12;
self.update = function () {
self.y += self.speed * gameSpeed;
};
return self;
});
var TrafficCar = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('trafficCar', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.lane = 0;
self.depth = 1.0;
self.update = function () {
self.y += self.speed * gameSpeed;
// Update scale based on depth for 3D effect
var scale = self.depth * 0.3 + 0.2;
self.scaleX = scale;
self.scaleY = scale;
// Update depth
self.depth += 0.02 * gameSpeed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Game variables
var playerCar;
var trafficCars = [];
var powerUps = [];
var roadLanes = [];
var gameSpeed = 1.0;
var distance = 0;
var playerLane = 1; // 0=left, 1=center, 2=right
var lanePositions = [2048 * 0.25, 2048 * 0.5, 2048 * 0.75];
var dragStartX = 0;
var isDragging = false;
var shieldActive = false;
var shieldTimer = 0;
var speedBoostActive = false;
var speedBoostTimer = 0;
// UI elements
var scoreText = new Text2('Distance: 0m', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
scoreText.x = 150;
scoreText.y = 50;
LK.gui.topLeft.addChild(scoreText);
var speedText = new Text2('Speed: 1.0x', {
size: 50,
fill: 0xFFFFFF
});
speedText.anchor.set(1, 0);
speedText.x = -50;
speedText.y = 50;
LK.gui.topRight.addChild(speedText);
var statusText = new Text2('', {
size: 45,
fill: 0xF39C12
});
statusText.anchor.set(0.5, 0);
statusText.x = 0;
statusText.y = 120;
LK.gui.top.addChild(statusText);
// Initialize player car
playerCar = game.addChild(new PlayerCar());
playerCar.x = lanePositions[playerLane];
playerCar.y = 2732 * 0.8;
// Create road lanes
function createRoadLane(x, y) {
var lane = new RoadLane();
lane.x = x;
lane.y = y;
roadLanes.push(lane);
game.addChild(lane);
}
// Initialize road lanes
for (var i = 0; i < 30; i++) {
createRoadLane(lanePositions[0], i * 100 - 500);
createRoadLane(lanePositions[1], i * 100 - 500);
createRoadLane(lanePositions[2], i * 100 - 500);
}
// Spawn traffic car
function spawnTrafficCar() {
var availableLanes = [0, 1, 2];
var randomLane = availableLanes[Math.floor(Math.random() * availableLanes.length)];
var trafficCar = new TrafficCar();
trafficCar.x = lanePositions[randomLane];
trafficCar.y = -200;
trafficCar.lane = randomLane;
trafficCars.push(trafficCar);
game.addChild(trafficCar);
}
// Spawn power-up
function spawnPowerUp() {
var randomLane = Math.floor(Math.random() * 3);
var powerUp = new PowerUp();
powerUp.x = lanePositions[randomLane];
powerUp.y = -150;
var types = ['score', 'shield', 'speed'];
var randomType = types[Math.floor(Math.random() * types.length)];
powerUp.setType(randomType);
powerUps.push(powerUp);
game.addChild(powerUp);
}
// Move player car to lane
function moveToLane(targetLane) {
if (targetLane < 0) targetLane = 0;
if (targetLane > 2) targetLane = 2;
playerLane = targetLane;
tween(playerCar, {
x: lanePositions[playerLane]
}, {
duration: 200,
easing: tween.easeOut
});
}
// Handle touch/drag controls
game.down = function (x, y, obj) {
isDragging = true;
dragStartX = x;
};
game.move = function (x, y, obj) {
if (!isDragging) return;
var deltaX = x - dragStartX;
var threshold = 100;
if (deltaX > threshold) {
moveToLane(playerLane + 1);
dragStartX = x;
} else if (deltaX < -threshold) {
moveToLane(playerLane - 1);
dragStartX = x;
}
};
game.up = function (x, y, obj) {
isDragging = false;
};
// Game update loop
game.update = function () {
// Update distance and speed
distance += gameSpeed;
gameSpeed += 0.0005;
if (gameSpeed > 3.0) gameSpeed = 3.0;
// Update UI
scoreText.setText('Distance: ' + Math.floor(distance) + 'm');
speedText.setText('Speed: ' + gameSpeed.toFixed(1) + 'x');
// Update shield status
if (shieldActive) {
shieldTimer--;
statusText.setText('SHIELD: ' + Math.ceil(shieldTimer / 60) + 's');
playerCar.setTint(0x9b59b6);
if (shieldTimer <= 0) {
shieldActive = false;
playerCar.setTint(0x3498db);
}
} else if (speedBoostActive) {
speedBoostTimer--;
statusText.setText('SPEED BOOST: ' + Math.ceil(speedBoostTimer / 60) + 's');
if (speedBoostTimer <= 0) {
speedBoostActive = false;
}
} else {
statusText.setText('');
}
// Spawn traffic cars
if (LK.ticks % Math.max(30 - Math.floor(gameSpeed * 5), 15) === 0) {
spawnTrafficCar();
}
// Spawn power-ups occasionally
if (LK.ticks % 300 === 0 && Math.random() < 0.7) {
spawnPowerUp();
}
// Update and check traffic cars
for (var i = trafficCars.length - 1; i >= 0; i--) {
var car = trafficCars[i];
// Remove cars that are off screen
if (car.y > 2732 + 200) {
car.destroy();
trafficCars.splice(i, 1);
continue;
}
// Check collision with player
if (car.intersects(playerCar) && !shieldActive) {
LK.getSound('crash').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
// Update and check power-ups
for (var i = powerUps.length - 1; i >= 0; i--) {
var powerUp = powerUps[i];
// Remove power-ups that are off screen
if (powerUp.y > 2732 + 200) {
powerUp.destroy();
powerUps.splice(i, 1);
continue;
}
// Check collection
if (powerUp.intersects(playerCar)) {
LK.getSound('collect').play();
if (powerUp.type === 'score') {
LK.setScore(LK.getScore() + 100);
} else if (powerUp.type === 'shield') {
shieldActive = true;
shieldTimer = 300; // 5 seconds at 60fps
} else if (powerUp.type === 'speed') {
speedBoostActive = true;
speedBoostTimer = 180; // 3 seconds at 60fps
gameSpeed *= 1.5;
}
powerUp.destroy();
powerUps.splice(i, 1);
}
}
// Update road lanes
for (var i = roadLanes.length - 1; i >= 0; i--) {
var lane = roadLanes[i];
// Respawn lanes at the top when they go off screen
if (lane.y > 2732 + 100) {
lane.y = -100;
}
}
// Update score based on distance
LK.setScore(Math.floor(distance / 10));
}; ===================================================================
--- original.js
+++ change.js
@@ -5,8 +5,66 @@
/****
* Classes
****/
+var PlayerCar = Container.expand(function () {
+ var self = Container.call(this);
+ // Car body (main rectangle)
+ var carBody = self.attachAsset('playerCarBody', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Car top (smaller rectangle for roof)
+ var carTop = self.attachAsset('playerCarTop', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ carTop.y = -15;
+ // Windshield
+ var windshield = self.attachAsset('playerCarWindshield', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ windshield.y = -20;
+ windshield.alpha = 0.7;
+ // Front wheels
+ var frontLeftWheel = self.attachAsset('playerCarWheel', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ frontLeftWheel.x = -25;
+ frontLeftWheel.y = -30;
+ var frontRightWheel = self.attachAsset('playerCarWheel', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ frontRightWheel.x = 25;
+ frontRightWheel.y = -30;
+ // Rear wheels
+ var rearLeftWheel = self.attachAsset('playerCarWheel', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ rearLeftWheel.x = -25;
+ rearLeftWheel.y = 30;
+ var rearRightWheel = self.attachAsset('playerCarWheel', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ rearRightWheel.x = 25;
+ rearRightWheel.y = 30;
+ // Store components for tinting
+ self.carBody = carBody;
+ self.carTop = carTop;
+ self.windshield = windshield;
+ self.wheels = [frontLeftWheel, frontRightWheel, rearLeftWheel, rearRightWheel];
+ // Method to change car color
+ self.setTint = function (color) {
+ self.carBody.tint = color;
+ self.carTop.tint = color;
+ };
+ return self;
+});
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerUp', {
anchorX: 0.5,
@@ -122,12 +180,9 @@
statusText.x = 0;
statusText.y = 120;
LK.gui.top.addChild(statusText);
// Initialize player car
-playerCar = game.addChild(LK.getAsset('playerCar', {
- anchorX: 0.5,
- anchorY: 0.5
-}));
+playerCar = game.addChild(new PlayerCar());
playerCar.x = lanePositions[playerLane];
playerCar.y = 2732 * 0.8;
// Create road lanes
function createRoadLane(x, y) {
@@ -210,12 +265,12 @@
// Update shield status
if (shieldActive) {
shieldTimer--;
statusText.setText('SHIELD: ' + Math.ceil(shieldTimer / 60) + 's');
- playerCar.tint = 0x9b59b6;
+ playerCar.setTint(0x9b59b6);
if (shieldTimer <= 0) {
shieldActive = false;
- playerCar.tint = 0xffffff;
+ playerCar.setTint(0x3498db);
}
} else if (speedBoostActive) {
speedBoostTimer--;
statusText.setText('SPEED BOOST: ' + Math.ceil(speedBoostTimer / 60) + 's');