User prompt
Do not show a car above the track
User prompt
Show car above the track like coins
User prompt
Show a celebration after every 100 points
User prompt
Show a starting message in start of game saying " Collect all treasures "
User prompt
Add collecting coins also in game to gain more points
Initial prompt
Beast racing
===================================================================
--- original.js
+++ change.js
@@ -1,113 +1,142 @@
-/****
+/****
* Classes
-****/
+****/
//<Assets used in the game will automatically appear here>
// Car class representing the player's car
var Car = Container.expand(function () {
- var self = Container.call(this);
- var carGraphics = self.attachAsset('car', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = 0;
- self.maxSpeed = 10;
- self.acceleration = 0.2;
- self.deceleration = 0.1;
- self.update = function () {
- self.y -= self.speed;
- if (self.speed > 0) {
- self.speed -= self.deceleration;
- }
- };
+ var self = Container.call(this);
+ var carGraphics = self.attachAsset('car', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = 0;
+ self.maxSpeed = 10;
+ self.acceleration = 0.2;
+ self.deceleration = 0.1;
+ self.update = function () {
+ self.y -= self.speed;
+ if (self.speed > 0) {
+ self.speed -= self.deceleration;
+ }
+ };
});
+// Coin class representing coins on the track
+var Coin = Container.expand(function () {
+ var self = Container.call(this);
+ var coinGraphics = self.attachAsset('coin', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ self.y += 5; // Move coin downwards
+ };
+});
// 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.update = function () {
- self.y += 5; // Move obstacle downwards
- };
+ var self = Container.call(this);
+ var obstacleGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ self.y += 5; // Move obstacle downwards
+ };
});
// Track class representing the racing track
var Track = Container.expand(function () {
- var self = Container.call(this);
- var trackGraphics = self.attachAsset('track', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Logic for moving the track to simulate car movement
- };
+ var self = Container.call(this);
+ var trackGraphics = self.attachAsset('track', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Logic for moving the track to simulate car movement
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000 //Init game with black background
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize game elements
var playerCar = game.addChild(new Car());
playerCar.x = 2048 / 2;
playerCar.y = 2732 - 200;
var track = game.addChild(new Track());
track.x = 2048 / 2;
track.y = 2732 / 2;
var obstacles = [];
+var coins = [];
var score = 0;
var scoreTxt = new Text2('0', {
- size: 150,
- fill: "#ffffff"
+ size: 150,
+ fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to handle car movement
function handleMove(x, y, obj) {
- playerCar.x = x;
+ playerCar.x = x;
}
// Function to update game state
game.update = function () {
- playerCar.update();
- track.update();
- // Update obstacles
- for (var i = obstacles.length - 1; i >= 0; i--) {
- obstacles[i].update();
- if (obstacles[i].y > 2732) {
- obstacles[i].destroy();
- obstacles.splice(i, 1);
- }
- if (playerCar.intersects(obstacles[i])) {
- LK.effects.flashScreen(0xff0000, 1000);
- LK.showGameOver();
- }
- }
- // Spawn new obstacles
- if (LK.ticks % 60 == 0) {
- var newObstacle = new Obstacle();
- newObstacle.x = Math.random() * 2048;
- newObstacle.y = -50;
- obstacles.push(newObstacle);
- game.addChild(newObstacle);
- }
- // Update score
- score += 1;
- scoreTxt.setText(score);
+ playerCar.update();
+ track.update();
+ // Update obstacles
+ for (var i = obstacles.length - 1; i >= 0; i--) {
+ obstacles[i].update();
+ if (obstacles[i].y > 2732) {
+ obstacles[i].destroy();
+ obstacles.splice(i, 1);
+ }
+ if (playerCar.intersects(obstacles[i])) {
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.showGameOver();
+ }
+ }
+ // Spawn new obstacles
+ if (LK.ticks % 60 == 0) {
+ var newObstacle = new Obstacle();
+ newObstacle.x = Math.random() * 2048;
+ newObstacle.y = -50;
+ obstacles.push(newObstacle);
+ game.addChild(newObstacle);
+ var newCoin = new Coin();
+ newCoin.x = Math.random() * 2048;
+ newCoin.y = -50;
+ coins.push(newCoin);
+ game.addChild(newCoin);
+ }
+ // Update coins
+ for (var i = coins.length - 1; i >= 0; i--) {
+ coins[i].update();
+ if (coins[i].y > 2732) {
+ coins[i].destroy();
+ coins.splice(i, 1);
+ }
+ if (playerCar.intersects(coins[i])) {
+ coins[i].destroy();
+ coins.splice(i, 1);
+ score += 10; // Increase score by 10 when player collects a coin
+ }
+ }
+ // Update score
+ scoreTxt.setText(score);
};
// Event listeners for touch controls
game.down = function (x, y, obj) {
- handleMove(x, y, obj);
+ handleMove(x, y, obj);
};
game.move = function (x, y, obj) {
- handleMove(x, y, obj);
+ handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
- // Stop car acceleration
- playerCar.speed = 0;
+ // Stop car acceleration
+ playerCar.speed = 0;
};
\ No newline at end of file
A sports car from top view (2d). Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A stone from top view (2d). Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A chest for 2d game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.