User prompt
The white lines shift the 90 degrees
User prompt
The white lines need to be roadlines and you get points when you avoid them, the road needs a city landscape around
User prompt
make the lines vertical and different lenghts
Code edit (1 edits merged)
Please save this source code
User prompt
Road Rhythm: Line Jump
Initial prompt
Design an engaging video game that showcases the front view of a car navigating through a variety of vibrant cityscapes. The primary objective of the game is for players to skillfully jump between different road lines as the car speeds along. To score points, players must click only when the car is traveling on sections of the road without any visible lines. Successfully timing these clicks will reward players with points, encouraging them to stay alert and focused. However, caution is key—if players mistakenly jump over the road lines, they will incur a point penalty. In addition to the basic mechanics, the game could introduce unique challenges and power-ups, such as changing environments or obstacles that require quick reflexes, adding layers of complexity and excitement to the gameplay.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Building = Container.expand(function () {
var self = Container.call(this);
var buildingGraphics = self.attachAsset('building', {
anchorX: 0.5,
anchorY: 0
});
// Randomize building properties
var shade = Math.floor(Math.random() * 40) + 40;
buildingGraphics.tint = shade << 16 | shade << 8 | shade;
buildingGraphics.height = Math.random() * 600 + 400;
buildingGraphics.width = Math.random() * 100 + 100;
self.speed = 10; // Default speed
self.update = function () {
self.y += self.speed;
// Reset building when it goes off screen
if (self.y > 2732 + buildingGraphics.height) {
self.y = -buildingGraphics.height;
self.x = Math.random() * 2048;
var shade = Math.floor(Math.random() * 40) + 40;
buildingGraphics.tint = shade << 16 | shade << 8 | shade;
buildingGraphics.height = Math.random() * 600 + 400;
buildingGraphics.width = Math.random() * 100 + 100;
}
};
return self;
});
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.jumping = false;
self.jumpHeight = 100;
self.originalY = 0;
self.jump = function () {
if (self.jumping) {
return;
}
self.jumping = true;
self.originalY = self.y;
// Jump animation using tween
tween(self, {
y: self.y - self.jumpHeight
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
// Fall back down
tween(self, {
y: self.originalY
}, {
duration: 300,
easing: tween.easeIn,
onFinish: function onFinish() {
self.jumping = false;
}
});
}
});
// Play jump sound
LK.getSound('jump').play();
};
self.down = function () {
self.jump();
};
return self;
});
var Line = Container.expand(function () {
var self = Container.call(this);
// Create vertical line with randomized length
var lineGraphics = self.attachAsset('line', {
anchorX: 0.5,
anchorY: 0.5
});
// Make the line vertical by rotating it 90 degrees
lineGraphics.rotation = Math.PI / 2;
// Randomize line length
lineGraphics.height = Math.random() * 400 + 200; // Random height between 200-600
lineGraphics.width = 40; // Keep the width consistent (this becomes thickness of vertical line)
self.speed = 15; // Default speed
self.active = true; // Whether the line is active for scoring
self.update = function () {
self.y += self.speed;
// Remove when off screen
if (self.y > 2732 + lineGraphics.width / 2) {
self.active = false;
}
};
return self;
});
var ScoreEffect = Container.expand(function () {
var self = Container.call(this);
var effectGraphics = self.attachAsset('scoreEffect', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.8
});
self.show = function (x, y, isPositive) {
self.x = x;
self.y = y;
if (!isPositive) {
effectGraphics.tint = 0xFF0000;
} else {
effectGraphics.tint = 0x00FF00;
}
// Animation for the effect
tween(self, {
alpha: 0,
y: y - 100
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
self.alpha = 1;
self.visible = false;
}
});
self.visible = true;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var car;
var lines = [];
var buildings = [];
var score = 0;
var scoreText;
var speedMultiplier = 1;
var lineSpawnRate = 60; // Frames between line spawns
var difficulty = 1;
var isGameActive = true;
var scoreEffects = [];
var effectIndex = 0;
var lastJumpScore = 0;
// Initialize the road
var road = game.addChild(LK.getAsset('road', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
}));
// Initialize score display
scoreText = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create buildings for background
for (var i = 0; i < 10; i++) {
var building = new Building();
building.x = Math.random() * 2048;
building.y = Math.random() * 2732;
buildings.push(building);
game.addChild(building);
}
// Create car
car = new Car();
car.x = 2048 / 2;
car.y = 2732 - 400;
game.addChild(car);
// Create score effects pool
for (var i = 0; i < 5; i++) {
var effect = new ScoreEffect();
effect.visible = false;
scoreEffects.push(effect);
game.addChild(effect);
}
// Game click handler
game.down = function (x, y, obj) {
if (!isGameActive) {
return;
}
// Check if car is already jumping
if (!car.jumping) {
car.jump();
// Check if car is over a line or intersects with a vertical line
var overLine = false;
for (var i = 0; i < lines.length; i++) {
// For vertical lines, we need to check both X and Y proximity
// The car should be within the vertical line's height range and close on X axis
if (lines[i].active && Math.abs(lines[i].y - car.y) < 50 && Math.abs(lines[i].x - car.x) < 100) {
overLine = true;
break;
}
}
// Score or penalty based on jump
if (overLine) {
// Penalty for jumping over a line
score = Math.max(0, score - 5);
// Show penalty effect
var effect = scoreEffects[effectIndex];
effectIndex = (effectIndex + 1) % scoreEffects.length;
effect.show(car.x, car.y - 50, false);
// Play penalty sound
LK.getSound('penalty').play();
} else {
// Points for jumping on empty road
var pointsGained = 10 * difficulty;
score += pointsGained;
lastJumpScore = pointsGained;
// Show score effect
var effect = scoreEffects[effectIndex];
effectIndex = (effectIndex + 1) % scoreEffects.length;
effect.show(car.x, car.y - 50, true);
// Play point sound
LK.getSound('point').play();
}
// Update score display
scoreText.setText(score);
LK.setScore(score);
}
};
// Game update function
game.update = function () {
if (!isGameActive) {
return;
}
// Update all lines
for (var i = lines.length - 1; i >= 0; i--) {
lines[i].update();
// Remove inactive lines
if (!lines[i].active) {
lines[i].destroy();
lines.splice(i, 1);
}
}
// Update all buildings
for (var i = 0; i < buildings.length; i++) {
buildings[i].speed = 5 * speedMultiplier;
buildings[i].update();
}
// Create new lines at intervals
if (LK.ticks % Math.floor(lineSpawnRate / speedMultiplier) === 0) {
var line = new Line();
// Position lines randomly across the road width
line.x = Math.random() * (2048 - 400) + 200; // Random X between 200 and 1648
line.y = -20;
line.speed = 15 * speedMultiplier;
lines.push(line);
game.addChild(line);
}
// Increase difficulty over time
if (LK.ticks % 600 === 0) {
// Every 10 seconds
difficulty += 0.1;
speedMultiplier = 1 + (difficulty - 1) * 0.5;
}
// Check for game over condition
if (score < 0) {
isGameActive = false;
LK.showGameOver();
}
// Check for win condition (arbitrary high score for demo)
if (score >= 500) {
isGameActive = false;
LK.showYouWin();
}
};
// Start background music
LK.playMusic('bgmusic', {
fade: {
start: 0,
end: 0.4,
duration: 1000
}
}); ===================================================================
--- original.js
+++ change.js
@@ -76,18 +76,24 @@
return self;
});
var Line = Container.expand(function () {
var self = Container.call(this);
+ // Create vertical line with randomized length
var lineGraphics = self.attachAsset('line', {
anchorX: 0.5,
anchorY: 0.5
});
+ // Make the line vertical by rotating it 90 degrees
+ lineGraphics.rotation = Math.PI / 2;
+ // Randomize line length
+ lineGraphics.height = Math.random() * 400 + 200; // Random height between 200-600
+ lineGraphics.width = 40; // Keep the width consistent (this becomes thickness of vertical line)
self.speed = 15; // Default speed
self.active = true; // Whether the line is active for scoring
self.update = function () {
self.y += self.speed;
// Remove when off screen
- if (self.y > 2732 + lineGraphics.height / 2) {
+ if (self.y > 2732 + lineGraphics.width / 2) {
self.active = false;
}
};
return self;
@@ -188,12 +194,14 @@
}
// Check if car is already jumping
if (!car.jumping) {
car.jump();
- // Check if car is over a line
+ // Check if car is over a line or intersects with a vertical line
var overLine = false;
for (var i = 0; i < lines.length; i++) {
- if (lines[i].active && Math.abs(lines[i].y - car.y) < 50) {
+ // For vertical lines, we need to check both X and Y proximity
+ // The car should be within the vertical line's height range and close on X axis
+ if (lines[i].active && Math.abs(lines[i].y - car.y) < 50 && Math.abs(lines[i].x - car.x) < 100) {
overLine = true;
break;
}
}
@@ -245,9 +253,10 @@
}
// Create new lines at intervals
if (LK.ticks % Math.floor(lineSpawnRate / speedMultiplier) === 0) {
var line = new Line();
- line.x = 2048 / 2;
+ // Position lines randomly across the road width
+ line.x = Math.random() * (2048 - 400) + 200; // Random X between 200 and 1648
line.y = -20;
line.speed = 15 * speedMultiplier;
lines.push(line);
game.addChild(line);