/****
* 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 = 0;
self.gravity = 0.5;
self.update = function () {
self.y += self.speed;
self.speed += self.gravity;
if (self.y > 2732) {
self.y = 2732;
self.speed = 0;
}
if (self.y < 0) {
self.y = 0;
self.speed = 0;
}
};
self.flap = function () {
self.speed = -10;
};
});
// Wall class
var Wall = Container.expand(function () {
var self = Container.call(this);
var wallGraphics = self.attachAsset('wall', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speed;
if (self.x < -100) {
self.destroy();
}
};
});
/****
* 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 walls = [];
game.update = function () {
if (LK.ticks % 120 == 0) {
var gapPosition = Math.random() * (2048 - 400) + 200;
var topWall = game.addChild(new Wall());
topWall.x = 2732;
topWall.y = gapPosition - 600;
var bottomWall = game.addChild(new Wall());
bottomWall.x = 2732;
bottomWall.y = gapPosition + 600;
walls.push(topWall);
walls.push(bottomWall);
}
for (var i = walls.length - 1; i >= 0; i--) {
if (walls[i].x < -100) {
walls[i].destroy();
walls.splice(i, 1);
} else if (bird.intersects(walls[i])) {
LK.showGameOver();
}
}
};
game.down = function (x, y, obj) {
bird.flap();
}; /****
* 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 = 0;
self.gravity = 0.5;
self.update = function () {
self.y += self.speed;
self.speed += self.gravity;
if (self.y > 2732) {
self.y = 2732;
self.speed = 0;
}
if (self.y < 0) {
self.y = 0;
self.speed = 0;
}
};
self.flap = function () {
self.speed = -10;
};
});
// Wall class
var Wall = Container.expand(function () {
var self = Container.call(this);
var wallGraphics = self.attachAsset('wall', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speed;
if (self.x < -100) {
self.destroy();
}
};
});
/****
* 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 walls = [];
game.update = function () {
if (LK.ticks % 120 == 0) {
var gapPosition = Math.random() * (2048 - 400) + 200;
var topWall = game.addChild(new Wall());
topWall.x = 2732;
topWall.y = gapPosition - 600;
var bottomWall = game.addChild(new Wall());
bottomWall.x = 2732;
bottomWall.y = gapPosition + 600;
walls.push(topWall);
walls.push(bottomWall);
}
for (var i = walls.length - 1; i >= 0; i--) {
if (walls[i].x < -100) {
walls[i].destroy();
walls.splice(i, 1);
} else if (bird.intersects(walls[i])) {
LK.showGameOver();
}
}
};
game.down = function (x, y, obj) {
bird.flap();
};