/**** * Classes ****/ // BirdSeed class representing the seed var BirdSeed = Container.expand(function () { var self = Container.call(this); var birdSeedGraphics = self.attachAsset('birdseed1', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for birdseed }; }); //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Pigeon class representing the player character var Pigeon = Container.expand(function () { var self = Container.call(this); var pigeonGraphics = self.attachAsset('pigeon', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.update = function () { // Update logic for pigeon }; self.down = function (x, y, obj) { // Handle touch down event self.x = x; self.y = y; // Check for collisions between pigeon and birdseeds for (var i = birdSeeds.length - 1; i >= 0; i--) { var birdSeed = birdSeeds[i]; if (self.intersects(birdSeed)) { LK.getSound('pigeonpeck1').play(); birdSeed.destroy(); birdSeeds.splice(i, 1); } // Check for proximity between pigeon and birdseeds else if (Math.abs(self.x - birdSeed.x) < 200 && Math.abs(self.y - birdSeed.y) < 200) { console.log("Pigeon is approaching the birdseed!"); } } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb // Init game with sky blue background }); /**** * Game Code ****/ // Initialize game variables var pigeon = game.addChild(new Pigeon()); pigeon.x = 2048 / 2; pigeon.y = 2732 - 200; var birdSeeds = []; var score = 0; // Spawn initial birdseed spawnBirdSeed(); // Function to spawn birdseeds at random positions function spawnBirdSeed() { var birdSeed = new BirdSeed(); birdSeed.x = Math.random() * 2048; birdSeed.y = Math.random() * 2732; birdSeeds.push(birdSeed); game.addChild(birdSeed); } // Handle game move event game.move = function (x, y, obj) { pigeon.x = x; pigeon.y = y; }; // Update game logic game.update = function () { // Check for collisions between pigeon and birdseeds for (var i = birdSeeds.length - 1; i >= 0; i--) { var birdSeed = birdSeeds[i]; if (pigeon.intersects(birdSeed)) { score += 100; // Award 100 points birdSeed.destroy(); birdSeeds.splice(i, 1); LK.setTimeout(spawnBirdSeed, 1000); // Spawn a new birdseed after 1 second LK.getSound('pigeonpeck1').play(); } } // Spawn new birdseed every 300 frames if (LK.ticks % 300 === 0) { spawnBirdSeed(); } }; // Display score var scoreTxt = new Text2('Score: 0', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Update score display function updateScore() { scoreTxt.setText('Score: ' + score); } // Call updateScore every frame game.update = function () { updateScore(); };
/****
* Classes
****/
// BirdSeed class representing the seed
var BirdSeed = Container.expand(function () {
var self = Container.call(this);
var birdSeedGraphics = self.attachAsset('birdseed1', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
// Update logic for birdseed
};
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Pigeon class representing the player character
var Pigeon = Container.expand(function () {
var self = Container.call(this);
var pigeonGraphics = self.attachAsset('pigeon', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
// Update logic for pigeon
};
self.down = function (x, y, obj) {
// Handle touch down event
self.x = x;
self.y = y;
// Check for collisions between pigeon and birdseeds
for (var i = birdSeeds.length - 1; i >= 0; i--) {
var birdSeed = birdSeeds[i];
if (self.intersects(birdSeed)) {
LK.getSound('pigeonpeck1').play();
birdSeed.destroy();
birdSeeds.splice(i, 1);
}
// Check for proximity between pigeon and birdseeds
else if (Math.abs(self.x - birdSeed.x) < 200 && Math.abs(self.y - birdSeed.y) < 200) {
console.log("Pigeon is approaching the birdseed!");
}
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb // Init game with sky blue background
});
/****
* Game Code
****/
// Initialize game variables
var pigeon = game.addChild(new Pigeon());
pigeon.x = 2048 / 2;
pigeon.y = 2732 - 200;
var birdSeeds = [];
var score = 0;
// Spawn initial birdseed
spawnBirdSeed();
// Function to spawn birdseeds at random positions
function spawnBirdSeed() {
var birdSeed = new BirdSeed();
birdSeed.x = Math.random() * 2048;
birdSeed.y = Math.random() * 2732;
birdSeeds.push(birdSeed);
game.addChild(birdSeed);
}
// Handle game move event
game.move = function (x, y, obj) {
pigeon.x = x;
pigeon.y = y;
};
// Update game logic
game.update = function () {
// Check for collisions between pigeon and birdseeds
for (var i = birdSeeds.length - 1; i >= 0; i--) {
var birdSeed = birdSeeds[i];
if (pigeon.intersects(birdSeed)) {
score += 100; // Award 100 points
birdSeed.destroy();
birdSeeds.splice(i, 1);
LK.setTimeout(spawnBirdSeed, 1000); // Spawn a new birdseed after 1 second
LK.getSound('pigeonpeck1').play();
}
}
// Spawn new birdseed every 300 frames
if (LK.ticks % 300 === 0) {
spawnBirdSeed();
}
};
// Display score
var scoreTxt = new Text2('Score: 0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Update score display
function updateScore() {
scoreTxt.setText('Score: ' + score);
}
// Call updateScore every frame
game.update = function () {
updateScore();
};