/**** * Classes ****/ // The assets will be automatically created and loaded by the LK engine. // Bird class var Bird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { self.y -= self.speed; if (self.y < 0) { self.y = 2732; } }; }); // 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 = 3; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.y = 0; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ var bird = game.addChild(new Bird()); bird.x = 1024; // Center of the screen bird.y = 1366; // Center of the screen 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); } game.update = function () { for (var i = 0; i < obstacles.length; i++) { if (bird.intersects(obstacles[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } }; game.down = function (x, y, obj) { bird.y -= 100; }; game.up = function (x, y, obj) { bird.y += 100; };
/****
* Classes
****/
// The assets will be automatically created and loaded by the LK engine.
// Bird class
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
self.y -= self.speed;
if (self.y < 0) {
self.y = 2732;
}
};
});
// 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 = 3;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = 0;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
var bird = game.addChild(new Bird());
bird.x = 1024; // Center of the screen
bird.y = 1366; // Center of the screen
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);
}
game.update = function () {
for (var i = 0; i < obstacles.length; i++) {
if (bird.intersects(obstacles[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
};
game.down = function (x, y, obj) {
bird.y -= 100;
};
game.up = function (x, y, obj) {
bird.y += 100;
};