/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Car class
var Car = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('car', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.direction = 0; // 0: right, 1: down, 2: left, 3: up
self.update = function () {
switch (self.direction) {
case 0:
self.x += self.speed;
break;
case 1:
self.y += self.speed;
break;
case 2:
self.x -= self.speed;
break;
case 3:
self.y -= self.speed;
break;
}
};
self.turnLeft = function () {
self.direction = (self.direction + 3) % 4; // Turn left
};
self.turnRight = function () {
self.direction = (self.direction + 1) % 4; // Turn right
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Add background image
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(background);
// Initialize points and highest score
var points = 0;
var highestScore = 0;
if (typeof localStorage !== 'undefined' && localStorage.getItem('highestScore') !== null) {
highestScore = parseInt(localStorage.getItem('highestScore'), 10);
}
// Initialize car
var car = game.addChild(new Car());
car.x = 2048 / 2;
car.y = 2732 / 2;
// Display points
var pointsTxt = new Text2('Points: 0', {
size: 100,
fill: "#ffffff"
});
pointsTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(pointsTxt);
// Display highest score
var highestScoreTxt = new Text2('Highest Score: 0', {
size: 100,
fill: "#ffffff"
});
highestScoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(highestScoreTxt);
highestScoreTxt.y = 150; // Position below points
// Handle touch events for turning
game.down = function (x, y, obj) {
if (x < 2048 / 2) {
car.turnLeft();
} else {
car.turnRight();
}
};
// Update game state
game.update = function () {
car.update();
// Update points
points += 1;
pointsTxt.setText('Points: ' + points);
// Update highest score
if (points > highestScore) {
highestScore = points;
highestScoreTxt.setText('Highest Score: ' + highestScore);
if (typeof localStorage !== 'undefined') {
if (typeof localStorage !== 'undefined') {
localStorage.setItem('highestScore', highestScore);
}
}
}
// Check for collisions with track boundaries
if (car.x < 0 || car.x > 2048 || car.y < 0 || car.y > 2732) {
LK.showGameOver();
if (points > highestScore) {
highestScore = points;
localStorage.setItem('highestScore', highestScore);
}
points = 0;
pointsTxt.setText('Points: ' + points);
highestScoreTxt.setText('Highest Score: ' + highestScore);
}
};
An black background with text "car race with reverse controls" in white colour in the top left corner very simple and small text. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A super racing car like Porsche. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.