/**** * Classes ****/ // The assets will be automatically created and loaded by the LK engine // Create a class for the Drift Car var DriftCar = Container.expand(function () { var self = Container.call(this); var carGraphics = self.attachAsset('driftCar', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.direction = 1; // 1 for right, -1 for left self.update = function () { self.x += self.speed * self.direction; }; self.changeDirection = function () { self.direction *= -1; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize the Drift Car var driftCar = game.addChild(new DriftCar()); driftCar.x = 1024; // Center of the screen driftCar.y = 2732 - 200; // Near the bottom of the screen // Handle click/touch events on the game screen game.down = function (x, y, obj) { driftCar.changeDirection(); }; // Update the game state game.update = function () { // Check if the car is out of bounds if (driftCar.x < 0 || driftCar.x > 2048) { // Game over LK.showGameOver(); } };
/****
* Classes
****/
// The assets will be automatically created and loaded by the LK engine
// Create a class for the Drift Car
var DriftCar = Container.expand(function () {
var self = Container.call(this);
var carGraphics = self.attachAsset('driftCar', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.direction = 1; // 1 for right, -1 for left
self.update = function () {
self.x += self.speed * self.direction;
};
self.changeDirection = function () {
self.direction *= -1;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize the Drift Car
var driftCar = game.addChild(new DriftCar());
driftCar.x = 1024; // Center of the screen
driftCar.y = 2732 - 200; // Near the bottom of the screen
// Handle click/touch events on the game screen
game.down = function (x, y, obj) {
driftCar.changeDirection();
};
// Update the game state
game.update = function () {
// Check if the car is out of bounds
if (driftCar.x < 0 || driftCar.x > 2048) {
// Game over
LK.showGameOver();
}
};