User prompt
decrease the score by 1 point when hitting obstacles
User prompt
do not destroy the previous backround until it is out of the screen
User prompt
the background should move down and loop
User prompt
change the score text color to black and make it larger
User prompt
the rivals' and obstacles' speed should not increase when mouse button is held down
User prompt
let there be infinite rivals and obstacles
User prompt
the obstacles and rivals should start from the bottom
User prompt
the obstacles and rivals should move in the opposite direction
User prompt
decrease the score by one point when player collides with an obstacle
User prompt
display the score on the top right corner
User prompt
player should get points when colliding with rivals. player should lose points when colliding with obstacles. obstacles are destroyed in one hit/collision. rivals require two hits/collisions to be destroyed
User prompt
use the background asset for background
User prompt
let the cars y position revert back to original when mouse button is not held
User prompt
increase the cars y position upto the center of screen when mouse button is held
User prompt
the cars y position should not decrease beyond the lower area of the background
User prompt
the car should move up towards the center of the background when mouse button is held down
User prompt
the car should move up and the background should go down faster when mouse button is held down
User prompt
increase the speed of the player car when mouse button is held down
Initial prompt
racing game
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Car class representing the player's vehicle
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
self.update = function () {
if (mouseDown) {
// Increase the car's y position up to the center of the screen
if (self.y > 2732 / 2) {
self.y -= self.speed;
}
self.speed = 20;
} else {
// Revert the car's y position back to original when mouse button is not held
if (self.y < 2400) {
self.y += self.speed;
}
self.speed = 10;
}
};
});
// Obstacle class representing obstacles on the track
var Obstacle = Container.expand(function () {
var self = Container.call(this);
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100; // Reset position to top
}
};
});
// Rival class representing rival cars
var Rival = Container.expand(function () {
var self = Container.call(this);
var rivalGraphics = self.attachAsset('rival', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 8;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100; // Reset position to top
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize player car
var playerCar = game.addChild(new Car());
playerCar.x = 1024; // Center horizontally
playerCar.y = 2400; // Near the bottom
// Initialize obstacles
var obstacles = [];
for (var i = 0; i < 5; i++) {
var obstacle = new Obstacle();
obstacle.x = Math.random() * 2048;
obstacle.y = Math.random() * -2732;
obstacles.push(obstacle);
game.addChild(obstacle);
}
// Initialize rivals
var rivals = [];
for (var i = 0; i < 3; i++) {
var rival = new Rival();
rival.x = Math.random() * 2048;
rival.y = Math.random() * -2732;
rivals.push(rival);
game.addChild(rival);
}
// Handle player car movement
var mouseDown = false;
game.move = function (x, y, obj) {
playerCar.x = x;
};
game.down = function (x, y, obj) {
mouseDown = true;
};
game.up = function (x, y, obj) {
mouseDown = false;
};
// Update game logic
game.update = function () {
// Update obstacles
for (var i = 0; i < obstacles.length; i++) {
if (mouseDown) {
obstacles[i].speed = 10;
} else {
obstacles[i].speed = 5;
}
obstacles[i].update();
if (playerCar.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update rivals
for (var i = 0; i < rivals.length; i++) {
if (mouseDown) {
rivals[i].speed = 16;
} else {
rivals[i].speed = 8;
}
rivals[i].update();
if (playerCar.intersects(rivals[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -18,8 +18,12 @@
self.y -= self.speed;
}
self.speed = 20;
} else {
+ // Revert the car's y position back to original when mouse button is not held
+ if (self.y < 2400) {
+ self.y += self.speed;
+ }
self.speed = 10;
}
};
});