User prompt
grass delete
User prompt
let the game get a little faster and harder every 100 meters, and let there be natural things around instead of black trees grass flowers like houses
User prompt
play the background music while using the engine and we can go anywhere with the engines except back and forth
User prompt
Generate the first version of the source code of my game: The long road
User prompt
Highway Rush
Initial prompt
The game will be a motor game, the road will be straight, there will be obstacles on the way, we will go by overcoming those obstacles, collecting points on the straight road, the longer we go, the more points we will get, and we will go right and left Title
/****
* Classes
****/
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.active = true;
self.lastY = 0;
self.collected = false;
self.update = function () {
self.lastY = self.y;
self.y += self.speed;
// Rotate coin
self.rotation += 0.05;
// Check if coin is off screen
if (self.y > 2832) {
self.active = false;
}
};
return self;
});
// Game variables
var Motorcycle = Container.expand(function () {
var self = Container.call(this);
var motorcycleGraphics = self.attachAsset('motorcycle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.lane = 1; // 0 = left, 1 = center, 2 = right
self.lanePositions = [680, 1024, 1368]; // X positions for lanes
self.targetX = self.lanePositions[self.lane];
self.isMoving = false;
self.update = function () {
// Smooth lane movement
if (self.x < self.targetX - 5) {
self.x += self.speed;
} else if (self.x > self.targetX + 5) {
self.x -= self.speed;
} else {
self.x = self.targetX;
self.isMoving = false;
}
};
self.moveLeft = function () {
if (self.lane > 0 && !self.isMoving) {
self.lane--;
self.targetX = self.lanePositions[self.lane];
self.isMoving = true;
}
};
self.moveRight = function () {
if (self.lane < 2 && !self.isMoving) {
self.lane++;
self.targetX = self.lanePositions[self.lane];
self.isMoving = true;
}
};
// Adding free movement for any direction except backward
self.freeMove = function (targetX) {
// Don't allow moving backwards (above current Y)
self.targetX = targetX;
self.isMoving = true;
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 15;
self.active = true;
self.lastY = 0;
self.update = function () {
self.lastY = self.y;
self.y += self.speed;
// Check if obstacle is off screen
if (self.y > 2832) {
self.active = false;
}
};
return self;
});
var Road = Container.expand(function () {
var self = Container.call(this);
// Add road background
var roadGraphics = self.attachAsset('road', {
anchorX: 0.5,
anchorY: 0
});
// Create road lines
self.lines = [];
self.lineSpeed = 15;
self.lineInterval = 150;
self.createLine = function (y) {
var line = self.addChild(LK.getAsset('roadLine', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: y
}));
self.lines.push(line);
return line;
};
// Initialize road lines
for (var y = -100; y < 2732 + 100; y += self.lineInterval) {
self.createLine(y);
}
self.update = function () {
// Update road lines
for (var i = self.lines.length - 1; i >= 0; i--) {
var line = self.lines[i];
line.y += self.lineSpeed;
// If line goes beyond the bottom of the screen, move it to the top
if (line.y > 2732 + 100) {
line.y = -100;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Game variables
// Game assets
var road;
var motorcycle;
var obstacles = [];
var coins = [];
var score = 0;
var distance = 0;
var gameActive = true;
var obstacleSpawnRate = 90; // Frames between obstacle spawns
var coinSpawnRate = 120; // Frames between coin spawns
var difficultyIncreaseRate = 1000; // Distance between difficulty increases
var gameSpeed = 15;
var lastDifficultyIncrease = 0;
// Play background music
LK.playMusic('backround');
// Set up score display
var scoreTxt = new Text2('Score: 0', {
size: 70,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(scoreTxt);
scoreTxt.x = 120; // Avoid the top left 100x100 px area
// Set up distance display
var distanceTxt = new Text2('Distance: 0m', {
size: 70,
fill: 0xFFFFFF
});
distanceTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(distanceTxt);
// Create and position road
road = game.addChild(new Road());
road.x = 2048 / 2;
// Create and position motorcycle
motorcycle = game.addChild(new Motorcycle());
motorcycle.x = 1024; // Center lane
motorcycle.y = 2200; // Near bottom of screen
// Handle touches for motorcycle control
game.down = function (x, y, obj) {
// Allow free horizontal movement but prevent going backward
if (x >= 0 && x <= 2048) {
// Restrict to screen width
if (x < motorcycle.lanePositions[0]) {
motorcycle.targetX = motorcycle.lanePositions[0]; // Left boundary
} else if (x > motorcycle.lanePositions[2]) {
motorcycle.targetX = motorcycle.lanePositions[2]; // Right boundary
} else {
motorcycle.targetX = x;
}
motorcycle.isMoving = true;
}
};
// Helper functions
function spawnObstacle() {
var obstacle = new Obstacle();
// Random lane position
var lane = Math.floor(Math.random() * 3); // 0, 1, or 2
obstacle.x = motorcycle.lanePositions[lane];
obstacle.y = -100; // Above screen
obstacles.push(obstacle);
game.addChild(obstacle);
return obstacle;
}
function spawnCoin() {
var coin = new Coin();
// Random lane position
var lane = Math.floor(Math.random() * 3); // 0, 1, or 2
coin.x = motorcycle.lanePositions[lane];
coin.y = -100; // Above screen
coins.push(coin);
game.addChild(coin);
return coin;
}
function checkCollisions() {
if (!gameActive) return;
// Check obstacle collisions
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
// Check collision with motorcycle
if (obstacle.active && motorcycle.intersects(obstacle)) {
// Game over
gameActive = false;
LK.getSound('crash').play();
LK.effects.flashScreen(0xFF0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
return;
}
// Remove inactive obstacles
if (!obstacle.active) {
obstacle.destroy();
obstacles.splice(i, 1);
}
}
// Check coin collisions
for (var j = coins.length - 1; j >= 0; j--) {
var coin = coins[j];
// Check collision with motorcycle
if (coin.active && !coin.collected && motorcycle.intersects(coin)) {
// Collect coin
coin.collected = true;
coin.active = false;
LK.getSound('coinCollect').play();
// Update score
score += 10;
scoreTxt.setText("Score: " + score);
// Flash effect
LK.effects.flashObject(coin, 0xFFFFFF, 300);
}
// Remove inactive coins
if (!coin.active) {
coin.destroy();
coins.splice(j, 1);
}
}
}
function increaseDifficulty() {
if (distance - lastDifficultyIncrease >= difficultyIncreaseRate) {
gameSpeed += 1;
obstacleSpawnRate = Math.max(40, obstacleSpawnRate - 5);
coinSpawnRate = Math.max(60, coinSpawnRate - 5);
// Update road line speed
road.lineSpeed = gameSpeed;
// Update obstacle and coin speed
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].speed = gameSpeed;
}
for (var j = 0; j < coins.length; j++) {
coins[j].speed = gameSpeed;
}
lastDifficultyIncrease = distance;
}
}
// Main game update function
game.update = function () {
if (!gameActive) return;
// Update road
road.update();
// Update motorcycle
motorcycle.update();
// Update all obstacles
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].update();
}
// Update all coins
for (var j = 0; j < coins.length; j++) {
coins[j].update();
}
// Spawn new obstacles
if (LK.ticks % obstacleSpawnRate === 0) {
spawnObstacle();
}
// Spawn new coins
if (LK.ticks % coinSpawnRate === 0) {
spawnCoin();
}
// Check collisions
checkCollisions();
// Update distance
distance += 1;
distanceTxt.setText("Distance: " + Math.floor(distance / 10) + "m");
// Update score based on distance
if (LK.ticks % 10 === 0) {
score += 1;
scoreTxt.setText("Score: " + score);
LK.setScore(score);
}
// Increase difficulty over time
increaseDifficulty();
}; ===================================================================
--- original.js
+++ change.js
@@ -59,8 +59,14 @@
self.targetX = self.lanePositions[self.lane];
self.isMoving = true;
}
};
+ // Adding free movement for any direction except backward
+ self.freeMove = function (targetX) {
+ // Don't allow moving backwards (above current Y)
+ self.targetX = targetX;
+ self.isMoving = true;
+ };
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
@@ -143,8 +149,10 @@
var coinSpawnRate = 120; // Frames between coin spawns
var difficultyIncreaseRate = 1000; // Distance between difficulty increases
var gameSpeed = 15;
var lastDifficultyIncrease = 0;
+// Play background music
+LK.playMusic('backround');
// Set up score display
var scoreTxt = new Text2('Score: 0', {
size: 70,
fill: 0xFFFFFF
@@ -167,13 +175,19 @@
motorcycle.x = 1024; // Center lane
motorcycle.y = 2200; // Near bottom of screen
// Handle touches for motorcycle control
game.down = function (x, y, obj) {
- // Left side touch moves left, right side touch moves right
- if (x < 1024) {
- motorcycle.moveLeft();
- } else {
- motorcycle.moveRight();
+ // Allow free horizontal movement but prevent going backward
+ if (x >= 0 && x <= 2048) {
+ // Restrict to screen width
+ if (x < motorcycle.lanePositions[0]) {
+ motorcycle.targetX = motorcycle.lanePositions[0]; // Left boundary
+ } else if (x > motorcycle.lanePositions[2]) {
+ motorcycle.targetX = motorcycle.lanePositions[2]; // Right boundary
+ } else {
+ motorcycle.targetX = x;
+ }
+ motorcycle.isMoving = true;
}
};
// Helper functions
function spawnObstacle() {
coin. In-Game asset. 2d. High contrast. No shadows
what appears from the upper side motorcycle. In-Game asset. 2d. High contrast. No shadows
the stone. In-Game asset. 2d. High contrast. No shadows
let there be a house and let the house be surrounded by lawns and flowers. In-Game asset. 2d. High contrast. No shadows
tree. In-Game asset. 2d. High contrast. No shadows