/**** * Classes ****/ // The assets will be automatically created and loaded by the LK engine // Create a 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.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = -100; } }; }); // Create an 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.y = -100; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize the car and the obstacles var car = game.addChild(new Car()); car.x = 2048 / 2; car.y = 2732 - 200; var obstacles = []; for (var i = 0; i < 5; i++) { var obstacle = game.addChild(new Obstacle()); obstacle.x = Math.random() * 2048; obstacle.y = Math.random() * 2732; obstacles.push(obstacle); } // Handle the game logic game.update = function () { // Check for collisions for (var i = 0; i < obstacles.length; i++) { if (car.intersects(obstacles[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } }; // Handle the touch events game.down = function (x, y, obj) { car.x = x; }; game.move = function (x, y, obj) { car.x = x; };
/****
* Classes
****/
// The assets will be automatically created and loaded by the LK engine
// Create a 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.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -100;
}
};
});
// Create an 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.y = -100;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize the car and the obstacles
var car = game.addChild(new Car());
car.x = 2048 / 2;
car.y = 2732 - 200;
var obstacles = [];
for (var i = 0; i < 5; i++) {
var obstacle = game.addChild(new Obstacle());
obstacle.x = Math.random() * 2048;
obstacle.y = Math.random() * 2732;
obstacles.push(obstacle);
}
// Handle the game logic
game.update = function () {
// Check for collisions
for (var i = 0; i < obstacles.length; i++) {
if (car.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
};
// Handle the touch events
game.down = function (x, y, obj) {
car.x = x;
};
game.move = function (x, y, obj) {
car.x = x;
};