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; }); var Scenery = Container.expand(function () { var self = Container.call(this); self.speed = 15; self.items = []; self.nextItemTime = 0; // Scenery types self.types = ['tree', 'house', 'flower']; self.createTree = function (side, y) { var tree = new Container(); // Create trunk var trunk = tree.addChild(LK.getAsset('treeTrunk', { anchorX: 0.5, anchorY: 1.0, x: 0, y: 0 })); // Create foliage var foliage = tree.addChild(LK.getAsset('tree', { anchorX: 0.5, anchorY: 1.0, x: 0, y: -trunk.height })); // Position tree tree.x = side === 'left' ? 350 : 1700; tree.y = y; self.addChild(tree); self.items.push({ element: tree, type: 'tree' }); return tree; }; self.createHouse = function (side, y) { var house = new Container(); // Create house body var houseBody = house.addChild(LK.getAsset('house', { anchorX: 0.5, anchorY: 1.0, x: 0, y: 0 })); // Create house roof var houseRoof = house.addChild(LK.getAsset('houseRoof', { anchorX: 0.5, anchorY: 1.0, x: 0, y: -houseBody.height })); // Position house house.x = side === 'left' ? 350 : 1700; house.y = y; self.addChild(house); self.items.push({ element: house, type: 'house' }); return house; }; self.createFlower = function (side, y) { var flowerGroup = new Container(); // Create a cluster of flowers for (var i = 0; i < 5; i++) { var flower = flowerGroup.addChild(LK.getAsset('flower', { anchorX: 0.5, anchorY: 0.5, x: Math.random() * 150 - 75, y: Math.random() * 50 - 25 })); // Random color for variety var colors = [0xff88ff, 0xffff44, 0xff4444, 0x4488ff, 0xffffff]; flower.tint = colors[Math.floor(Math.random() * colors.length)]; } // Position flowers flowerGroup.x = side === 'left' ? 400 : 1650; flowerGroup.y = y; self.addChild(flowerGroup); self.items.push({ element: flowerGroup, type: 'flower' }); return flowerGroup; }; self.addRandomScenery = function () { var side = Math.random() > 0.5 ? 'left' : 'right'; var type = self.types[Math.floor(Math.random() * self.types.length)]; switch (type) { case 'tree': self.createTree(side, -200); break; case 'house': self.createHouse(side, -200); break; case 'flower': self.createFlower(side, -100); break; } }; self.update = function () { // Update existing scenery items for (var i = self.items.length - 1; i >= 0; i--) { var item = self.items[i]; item.element.y += self.speed; // Remove items that have moved off screen if (item.element.y > 2832) { item.element.destroy(); self.items.splice(i, 1); } } // Add new scenery based on timing if (LK.ticks > self.nextItemTime) { self.addRandomScenery(); // Random interval for next scenery self.nextItemTime = LK.ticks + 30 + Math.floor(Math.random() * 60); } }; self.setSpeed = function (newSpeed) { self.speed = newSpeed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Game variables // Game assets var road; var motorcycle; var scenery; 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 = 100; // Distance between difficulty increases (in meters) var gameSpeed = 15; var lastDifficultyIncrease = 0; var level = 1; var levelTxt; // 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 level display levelTxt = new Text2('Level: 1', { size: 70, fill: 0xFFFFFF }); levelTxt.anchor.set(0.5, 0); LK.gui.top.addChild(levelTxt); // Create scenery scenery = game.addChild(new Scenery()); // 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() { // Check if we've traveled 100 meters since the last difficulty increase var currentDistanceMeters = Math.floor(distance / 10); if (currentDistanceMeters - lastDifficultyIncrease >= difficultyIncreaseRate) { // Increase game level level++; levelTxt.setText("Level: " + level); // Play level up sound LK.getSound('levelUp').play(); // Flash screen effect for level up LK.effects.flashScreen(0x00FF00, 500); // Increase game speed gameSpeed += 2; // Decrease spawn rates (make obstacles appear more frequently) obstacleSpawnRate = Math.max(30, obstacleSpawnRate - 10); coinSpawnRate = Math.max(50, coinSpawnRate - 8); // Update road line speed road.lineSpeed = gameSpeed; // Update scenery speed scenery.setSpeed(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; } // Record the distance where we last increased difficulty lastDifficultyIncrease = currentDistanceMeters; } } // Main game update function game.update = function () { if (!gameActive) return; // Update scenery scenery.update(); // 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(); };
/****
* 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;
});
var Scenery = Container.expand(function () {
var self = Container.call(this);
self.speed = 15;
self.items = [];
self.nextItemTime = 0;
// Scenery types
self.types = ['tree', 'house', 'flower'];
self.createTree = function (side, y) {
var tree = new Container();
// Create trunk
var trunk = tree.addChild(LK.getAsset('treeTrunk', {
anchorX: 0.5,
anchorY: 1.0,
x: 0,
y: 0
}));
// Create foliage
var foliage = tree.addChild(LK.getAsset('tree', {
anchorX: 0.5,
anchorY: 1.0,
x: 0,
y: -trunk.height
}));
// Position tree
tree.x = side === 'left' ? 350 : 1700;
tree.y = y;
self.addChild(tree);
self.items.push({
element: tree,
type: 'tree'
});
return tree;
};
self.createHouse = function (side, y) {
var house = new Container();
// Create house body
var houseBody = house.addChild(LK.getAsset('house', {
anchorX: 0.5,
anchorY: 1.0,
x: 0,
y: 0
}));
// Create house roof
var houseRoof = house.addChild(LK.getAsset('houseRoof', {
anchorX: 0.5,
anchorY: 1.0,
x: 0,
y: -houseBody.height
}));
// Position house
house.x = side === 'left' ? 350 : 1700;
house.y = y;
self.addChild(house);
self.items.push({
element: house,
type: 'house'
});
return house;
};
self.createFlower = function (side, y) {
var flowerGroup = new Container();
// Create a cluster of flowers
for (var i = 0; i < 5; i++) {
var flower = flowerGroup.addChild(LK.getAsset('flower', {
anchorX: 0.5,
anchorY: 0.5,
x: Math.random() * 150 - 75,
y: Math.random() * 50 - 25
}));
// Random color for variety
var colors = [0xff88ff, 0xffff44, 0xff4444, 0x4488ff, 0xffffff];
flower.tint = colors[Math.floor(Math.random() * colors.length)];
}
// Position flowers
flowerGroup.x = side === 'left' ? 400 : 1650;
flowerGroup.y = y;
self.addChild(flowerGroup);
self.items.push({
element: flowerGroup,
type: 'flower'
});
return flowerGroup;
};
self.addRandomScenery = function () {
var side = Math.random() > 0.5 ? 'left' : 'right';
var type = self.types[Math.floor(Math.random() * self.types.length)];
switch (type) {
case 'tree':
self.createTree(side, -200);
break;
case 'house':
self.createHouse(side, -200);
break;
case 'flower':
self.createFlower(side, -100);
break;
}
};
self.update = function () {
// Update existing scenery items
for (var i = self.items.length - 1; i >= 0; i--) {
var item = self.items[i];
item.element.y += self.speed;
// Remove items that have moved off screen
if (item.element.y > 2832) {
item.element.destroy();
self.items.splice(i, 1);
}
}
// Add new scenery based on timing
if (LK.ticks > self.nextItemTime) {
self.addRandomScenery();
// Random interval for next scenery
self.nextItemTime = LK.ticks + 30 + Math.floor(Math.random() * 60);
}
};
self.setSpeed = function (newSpeed) {
self.speed = newSpeed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Game variables
// Game assets
var road;
var motorcycle;
var scenery;
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 = 100; // Distance between difficulty increases (in meters)
var gameSpeed = 15;
var lastDifficultyIncrease = 0;
var level = 1;
var levelTxt;
// 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 level display
levelTxt = new Text2('Level: 1', {
size: 70,
fill: 0xFFFFFF
});
levelTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(levelTxt);
// Create scenery
scenery = game.addChild(new Scenery());
// 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() {
// Check if we've traveled 100 meters since the last difficulty increase
var currentDistanceMeters = Math.floor(distance / 10);
if (currentDistanceMeters - lastDifficultyIncrease >= difficultyIncreaseRate) {
// Increase game level
level++;
levelTxt.setText("Level: " + level);
// Play level up sound
LK.getSound('levelUp').play();
// Flash screen effect for level up
LK.effects.flashScreen(0x00FF00, 500);
// Increase game speed
gameSpeed += 2;
// Decrease spawn rates (make obstacles appear more frequently)
obstacleSpawnRate = Math.max(30, obstacleSpawnRate - 10);
coinSpawnRate = Math.max(50, coinSpawnRate - 8);
// Update road line speed
road.lineSpeed = gameSpeed;
// Update scenery speed
scenery.setSpeed(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;
}
// Record the distance where we last increased difficulty
lastDifficultyIncrease = currentDistanceMeters;
}
}
// Main game update function
game.update = function () {
if (!gameActive) return;
// Update scenery
scenery.update();
// 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();
};
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