/**** * Classes ****/ //<Assets used in the game will automatically appear here> // 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.flapStrength = -10; self.update = function () { self.speedY += self.gravity; self.y += self.speedY; }; self.flap = function () { self.speedY = self.flapStrength; }; }); // Coin class var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.speedX = -5; self.update = function () { self.x += self.speedX; }; }); // Pole class var Pole = Container.expand(function () { var self = Container.call(this); var poleGraphics = self.attachAsset('pole', { 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 = 300; bird.y = 1366; // Center vertically var coins = []; var poles = []; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); game.down = function (x, y, obj) { bird.flap(); }; game.update = function () { bird.update(); // Add new coins and poles if (LK.ticks % 100 == 0) { var newCoin = new Coin(); newCoin.x = 2048; newCoin.y = Math.random() * 2732; coins.push(newCoin); game.addChild(newCoin); var newPole = new Pole(); newPole.x = 2048; newPole.y = Math.random() * 2732; poles.push(newPole); game.addChild(newPole); } // Update coins and poles for (var i = coins.length - 1; i >= 0; i--) { coins[i].update(); if (coins[i].intersects(bird)) { score += 1; scoreTxt.setText(score); coins[i].destroy(); coins.splice(i, 1); } else if (coins[i].x < -50) { coins[i].destroy(); coins.splice(i, 1); } } for (var j = poles.length - 1; j >= 0; j--) { poles[j].update(); if (poles[j].intersects(bird)) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } else if (poles[j].x < -50) { poles[j].destroy(); poles.splice(j, 1); } } // Check if bird is out of bounds if (bird.y < 0 || bird.y > 2732) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// 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.flapStrength = -10;
self.update = function () {
self.speedY += self.gravity;
self.y += self.speedY;
};
self.flap = function () {
self.speedY = self.flapStrength;
};
});
// Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = -5;
self.update = function () {
self.x += self.speedX;
};
});
// Pole class
var Pole = Container.expand(function () {
var self = Container.call(this);
var poleGraphics = self.attachAsset('pole', {
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 = 300;
bird.y = 1366; // Center vertically
var coins = [];
var poles = [];
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
game.down = function (x, y, obj) {
bird.flap();
};
game.update = function () {
bird.update();
// Add new coins and poles
if (LK.ticks % 100 == 0) {
var newCoin = new Coin();
newCoin.x = 2048;
newCoin.y = Math.random() * 2732;
coins.push(newCoin);
game.addChild(newCoin);
var newPole = new Pole();
newPole.x = 2048;
newPole.y = Math.random() * 2732;
poles.push(newPole);
game.addChild(newPole);
}
// Update coins and poles
for (var i = coins.length - 1; i >= 0; i--) {
coins[i].update();
if (coins[i].intersects(bird)) {
score += 1;
scoreTxt.setText(score);
coins[i].destroy();
coins.splice(i, 1);
} else if (coins[i].x < -50) {
coins[i].destroy();
coins.splice(i, 1);
}
}
for (var j = poles.length - 1; j >= 0; j--) {
poles[j].update();
if (poles[j].intersects(bird)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
} else if (poles[j].x < -50) {
poles[j].destroy();
poles.splice(j, 1);
}
}
// Check if bird is out of bounds
if (bird.y < 0 || bird.y > 2732) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
};
Yallow gold coin. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
catching net. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Yallow animated flying bird right side. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.