/**** * 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) { // Play bird sound LK.getSound('sparrowchirping').play(); // Remove bird when tapped self.destroy(); // Update score LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); }; }); var Bomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = self.attachAsset('bomb', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Bombs don't move in this game, so no update logic needed }; self.down = function (x, y, obj) { // Play bomb sound LK.getSound('bang').play(); // Remove bomb when tapped self.destroy(); // Update score LK.setScore(LK.getScore() - 5); scoreTxt.setText(LK.getScore()); }; }); var BonusBird = Container.expand(function () { var self = Container.call(this); var birdGraphics = self.attachAsset('bonusBird', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Bonus birds don't move in this game, so no update logic needed }; self.down = function (x, y, obj) { // Play bonus bird sound LK.getSound('chirping').play(); // Remove bonus bird when tapped self.destroy(); // Update score LK.setScore(LK.getScore() + 15); scoreTxt.setText(LK.getScore()); }; }); // Function to spawn bonus bird var Bush = Container.expand(function () { var self = Container.call(this); var bushGraphics = self.attachAsset('bush' + (Math.floor(Math.random() * 5) + 1), { anchorX: 0.5, anchorY: 0.5 }); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Function to spawn bonus bird function spawnBonusBird() { var bonusBird = new BonusBird(); bonusBird.x = Math.random() * 2048; bonusBird.y = Math.random() * 2732; birds.push(bonusBird); game.addChild(bonusBird); // Remove bonus bird after 5 seconds LK.setTimeout(function () { bonusBird.destroy(); birds.splice(birds.indexOf(bonusBird), 1); }, 5000); } // Spawn bonus bird after 30 seconds LK.setTimeout(spawnBonusBird, 30000); // Function to spawn bomb function spawnBomb() { var bomb = new Bomb(); bomb.x = Math.random() * 2048; bomb.y = Math.random() * 2732; bombs.push(bomb); game.addChild(bomb); // Remove bomb after 4 seconds LK.setTimeout(function () { bomb.destroy(); bombs.splice(bombs.indexOf(bomb), 1); }, 4000); } // Spawn bomb every 10 seconds LK.setInterval(spawnBomb, 10000); // 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, including bonus birds var birds = []; // Array to keep track of bombs var bombs = []; // Array to keep track of bushes var bushes = []; // Function to spawn birds function spawnBird() { var bird1 = new Bird(); bird1.x = Math.random() * 2048; bird1.y = Math.random() * 2732; birds.push(bird1); game.addChild(bird1); var bird2 = new Bird(); bird2.x = Math.random() * 2048; bird2.y = Math.random() * 2732; birds.push(bird2); game.addChild(bird2); // Remove birds after 2 and 3 seconds for level 4 LK.setTimeout(function () { bird1.destroy(); birds.splice(birds.indexOf(bird1), 1); }, 2000); LK.setTimeout(function () { bird2.destroy(); birds.splice(birds.indexOf(bird2), 1); }, 3000); // Respawn birds after 5 seconds LK.setTimeout(spawnBird, 5000); } // Initial bird spawn is now handled within spawnBird // Game update function game.update = function () { // Update logic for birds for (var i = birds.length - 1; i >= 0; i--) { birds[i].update(); } // Update logic for bombs for (var i = bombs.length - 1; i >= 0; i--) { bombs[i].update(); } // Update logic for bushes // Bushes don't have an update method, so no update logic needed // Check if score reaches 85 to complete level 3 if (LK.getScore() >= 85) { LK.showLevelComplete(); // Show level complete screen } // Check if score reaches 120 to complete level 4 if (LK.getScore() >= 120) { LK.showLevelComplete(); // Show level complete screen } // Check if score reaches 100 to display winner sticker if (LK.getScore() >= 100) { // Display winner sticker var winnerSticker = new Text2('Winner!', { size: 200, fill: "#FFD700" // Gold color }); winnerSticker.anchor.set(0.5, 0.5); winnerSticker.x = 2048 / 2; winnerSticker.y = 2732 / 2; game.addChild(winnerSticker); } }; // Function to spawn bushes function spawnBushes() { for (var i = 0; i < 5; i++) { var bush = new Bush(); bush.x = Math.random() * 2048; bush.y = Math.random() * 2732; bushes.push(bush); game.addChild(bush); } } // Initial bird spawn spawnBird(); spawnBushes(); // Function to spawn bonus bird // Spawn bonus bird every 30 seconds LK.setInterval(spawnBonusBird, 30000);
/****
* 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) {
// Play bird sound
LK.getSound('sparrowchirping').play();
// Remove bird when tapped
self.destroy();
// Update score
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
};
});
var Bomb = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.attachAsset('bomb', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Bombs don't move in this game, so no update logic needed
};
self.down = function (x, y, obj) {
// Play bomb sound
LK.getSound('bang').play();
// Remove bomb when tapped
self.destroy();
// Update score
LK.setScore(LK.getScore() - 5);
scoreTxt.setText(LK.getScore());
};
});
var BonusBird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bonusBird', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Bonus birds don't move in this game, so no update logic needed
};
self.down = function (x, y, obj) {
// Play bonus bird sound
LK.getSound('chirping').play();
// Remove bonus bird when tapped
self.destroy();
// Update score
LK.setScore(LK.getScore() + 15);
scoreTxt.setText(LK.getScore());
};
});
// Function to spawn bonus bird
var Bush = Container.expand(function () {
var self = Container.call(this);
var bushGraphics = self.attachAsset('bush' + (Math.floor(Math.random() * 5) + 1), {
anchorX: 0.5,
anchorY: 0.5
});
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Function to spawn bonus bird
function spawnBonusBird() {
var bonusBird = new BonusBird();
bonusBird.x = Math.random() * 2048;
bonusBird.y = Math.random() * 2732;
birds.push(bonusBird);
game.addChild(bonusBird);
// Remove bonus bird after 5 seconds
LK.setTimeout(function () {
bonusBird.destroy();
birds.splice(birds.indexOf(bonusBird), 1);
}, 5000);
}
// Spawn bonus bird after 30 seconds
LK.setTimeout(spawnBonusBird, 30000);
// Function to spawn bomb
function spawnBomb() {
var bomb = new Bomb();
bomb.x = Math.random() * 2048;
bomb.y = Math.random() * 2732;
bombs.push(bomb);
game.addChild(bomb);
// Remove bomb after 4 seconds
LK.setTimeout(function () {
bomb.destroy();
bombs.splice(bombs.indexOf(bomb), 1);
}, 4000);
}
// Spawn bomb every 10 seconds
LK.setInterval(spawnBomb, 10000);
// 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, including bonus birds
var birds = [];
// Array to keep track of bombs
var bombs = [];
// Array to keep track of bushes
var bushes = [];
// Function to spawn birds
function spawnBird() {
var bird1 = new Bird();
bird1.x = Math.random() * 2048;
bird1.y = Math.random() * 2732;
birds.push(bird1);
game.addChild(bird1);
var bird2 = new Bird();
bird2.x = Math.random() * 2048;
bird2.y = Math.random() * 2732;
birds.push(bird2);
game.addChild(bird2);
// Remove birds after 2 and 3 seconds for level 4
LK.setTimeout(function () {
bird1.destroy();
birds.splice(birds.indexOf(bird1), 1);
}, 2000);
LK.setTimeout(function () {
bird2.destroy();
birds.splice(birds.indexOf(bird2), 1);
}, 3000);
// Respawn birds after 5 seconds
LK.setTimeout(spawnBird, 5000);
}
// Initial bird spawn is now handled within spawnBird
// Game update function
game.update = function () {
// Update logic for birds
for (var i = birds.length - 1; i >= 0; i--) {
birds[i].update();
}
// Update logic for bombs
for (var i = bombs.length - 1; i >= 0; i--) {
bombs[i].update();
}
// Update logic for bushes
// Bushes don't have an update method, so no update logic needed
// Check if score reaches 85 to complete level 3
if (LK.getScore() >= 85) {
LK.showLevelComplete(); // Show level complete screen
}
// Check if score reaches 120 to complete level 4
if (LK.getScore() >= 120) {
LK.showLevelComplete(); // Show level complete screen
}
// Check if score reaches 100 to display winner sticker
if (LK.getScore() >= 100) {
// Display winner sticker
var winnerSticker = new Text2('Winner!', {
size: 200,
fill: "#FFD700" // Gold color
});
winnerSticker.anchor.set(0.5, 0.5);
winnerSticker.x = 2048 / 2;
winnerSticker.y = 2732 / 2;
game.addChild(winnerSticker);
}
};
// Function to spawn bushes
function spawnBushes() {
for (var i = 0; i < 5; i++) {
var bush = new Bush();
bush.x = Math.random() * 2048;
bush.y = Math.random() * 2732;
bushes.push(bush);
game.addChild(bush);
}
}
// Initial bird spawn
spawnBird();
spawnBushes();
// Function to spawn bonus bird
// Spawn bonus bird every 30 seconds
LK.setInterval(spawnBonusBird, 30000);