/**** * 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.speedY = 0; self.gravity = 0.5; self.update = function () { self.y += self.speedY; self.speedY += self.gravity; if (self.y > 2732) { self.y = 2732; self.speedY = 0; } if (self.y < 0) { self.y = 0; self.speedY = 0; } }; self.flap = function () { self.speedY = -10; }; }); // 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.speedX = -5; self.update = function () { self.x += self.speedX; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ var bird = game.addChild(new Bird()); bird.x = 1024; bird.y = 1366; var pipes = []; game.update = function () { if (LK.ticks % 120 == 0) { var pipeGap = 400; var pipeY = Math.random() * (2732 - pipeGap); var upperPipe = game.addChild(new Pipe()); upperPipe.x = 2048; upperPipe.y = pipeY; var lowerPipe = game.addChild(new Pipe()); lowerPipe.x = 2048; lowerPipe.y = pipeY + pipeGap; pipes.push(upperPipe); pipes.push(lowerPipe); } 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.showGameOver(); } } }; game.down = function (x, y, obj) { bird.flap(); };
/****
* 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.speedY = 0;
self.gravity = 0.5;
self.update = function () {
self.y += self.speedY;
self.speedY += self.gravity;
if (self.y > 2732) {
self.y = 2732;
self.speedY = 0;
}
if (self.y < 0) {
self.y = 0;
self.speedY = 0;
}
};
self.flap = function () {
self.speedY = -10;
};
});
// 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.speedX = -5;
self.update = function () {
self.x += self.speedX;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
var bird = game.addChild(new Bird());
bird.x = 1024;
bird.y = 1366;
var pipes = [];
game.update = function () {
if (LK.ticks % 120 == 0) {
var pipeGap = 400;
var pipeY = Math.random() * (2732 - pipeGap);
var upperPipe = game.addChild(new Pipe());
upperPipe.x = 2048;
upperPipe.y = pipeY;
var lowerPipe = game.addChild(new Pipe());
lowerPipe.x = 2048;
lowerPipe.y = pipeY + pipeGap;
pipes.push(upperPipe);
pipes.push(lowerPipe);
}
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.showGameOver();
}
}
};
game.down = function (x, y, obj) {
bird.flap();
};