/**** * Classes ****/ // The assets will be automatically created and loaded by the LK engine. // Create a 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 = 0; self.gravity = 0.5; self.lift = -15; self.update = function () { self.speed += self.gravity; self.y += self.speed; if (self.y > 2732) { self.y = 2732; self.speed = 0; } if (self.y < 0) { self.y = 0; self.speed = 0; } }; self.up = function () { self.speed += self.lift; }; }); // Create a Pipe class var Pipe = Container.expand(function () { var self = Container.call(this); var pipeGraphics = self.attachAsset('pipe', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; self.update = function () { self.x -= self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb // Sky blue background }); /**** * Game Code ****/ var bird = game.addChild(new Bird()); bird.x = 512; bird.y = 1366; var pipes = []; game.update = function () { if (LK.ticks % 120 == 0) { var pipe = new Pipe(); pipe.x = 2048; pipe.y = Math.random() * (2048 - 512) + 512; pipes.push(pipe); game.addChild(pipe); } for (var i = pipes.length - 1; i >= 0; i--) { if (pipes[i].x < -pipes[i].width) { pipes[i].destroy(); pipes.splice(i, 1); } if (bird.intersects(pipes[i])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } }; game.down = function (x, y, obj) { bird.up(); };
/****
* Classes
****/
// The assets will be automatically created and loaded by the LK engine.
// Create a 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 = 0;
self.gravity = 0.5;
self.lift = -15;
self.update = function () {
self.speed += self.gravity;
self.y += self.speed;
if (self.y > 2732) {
self.y = 2732;
self.speed = 0;
}
if (self.y < 0) {
self.y = 0;
self.speed = 0;
}
};
self.up = function () {
self.speed += self.lift;
};
});
// Create a Pipe class
var Pipe = Container.expand(function () {
var self = Container.call(this);
var pipeGraphics = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 2;
self.update = function () {
self.x -= self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb // Sky blue background
});
/****
* Game Code
****/
var bird = game.addChild(new Bird());
bird.x = 512;
bird.y = 1366;
var pipes = [];
game.update = function () {
if (LK.ticks % 120 == 0) {
var pipe = new Pipe();
pipe.x = 2048;
pipe.y = Math.random() * (2048 - 512) + 512;
pipes.push(pipe);
game.addChild(pipe);
}
for (var i = pipes.length - 1; i >= 0; i--) {
if (pipes[i].x < -pipes[i].width) {
pipes[i].destroy();
pipes.splice(i, 1);
}
if (bird.intersects(pipes[i])) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
};
game.down = function (x, y, obj) {
bird.up();
};