/****
* 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 = 10;
self.update = function () {
// Car update logic
};
});
// Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Obstacle class
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.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize arrays and variables
var car;
var obstacles = [];
var coins = [];
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize car
car = game.addChild(new Car());
car.x = 2048 / 2;
car.y = 2732 - 200;
// Handle touch events for car movement
game.down = function (x, y, obj) {
car.x = x;
car.y = y;
};
game.move = function (x, y, obj) {
car.x = x;
car.y = y;
};
game.up = function (x, y, obj) {
// No action needed on touch up
};
// Update game logic
game.update = function () {
// Update car
car.update();
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
if (car.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Update coins
for (var j = coins.length - 1; j >= 0; j--) {
coins[j].update();
if (car.intersects(coins[j])) {
score += 1;
scoreTxt.setText(score);
coins[j].destroy();
coins.splice(j, 1);
}
}
// Spawn obstacles
if (LK.ticks % 60 == 0) {
var newObstacle = new Obstacle();
newObstacle.x = Math.random() * 2048;
newObstacle.y = -50;
obstacles.push(newObstacle);
game.addChild(newObstacle);
}
// Spawn coins
if (LK.ticks % 120 == 0) {
var newCoin = new Coin();
newCoin.x = Math.random() * 2048;
newCoin.y = -50;
coins.push(newCoin);
game.addChild(newCoin);
}
};
A car that looking upwards.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A single circle gold coins. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A single car looking upwards.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.