/**** * 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.update = function () { // Birds don't move in this game, so no update logic needed }; self.down = function (x, y, obj) { // Remove bird when tapped self.destroy(); // Update score LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Initialize score text var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Array to keep track of birds var birds = []; // Function to spawn a bird function spawnBird() { var bird = new Bird(); bird.x = Math.random() * 2048; bird.y = Math.random() * 2732; birds.push(bird); game.addChild(bird); } // Set interval to spawn birds every 5 seconds LK.setInterval(spawnBird, 5000); // Game update function game.update = function () { // Update logic for birds for (var i = birds.length - 1; i >= 0; i--) { birds[i].update(); } }; // Initial bird spawn spawnBird();
/****
* 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.update = function () {
// Birds don't move in this game, so no update logic needed
};
self.down = function (x, y, obj) {
// Remove bird when tapped
self.destroy();
// Update score
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Initialize score text
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Array to keep track of birds
var birds = [];
// Function to spawn a bird
function spawnBird() {
var bird = new Bird();
bird.x = Math.random() * 2048;
bird.y = Math.random() * 2732;
birds.push(bird);
game.addChild(bird);
}
// Set interval to spawn birds every 5 seconds
LK.setInterval(spawnBird, 5000);
// Game update function
game.update = function () {
// Update logic for birds
for (var i = birds.length - 1; i >= 0; i--) {
birds[i].update();
}
};
// Initial bird spawn
spawnBird();