User prompt
The new birdseed appears after 1 second, in a new location.
User prompt
When the birdseed is eaten, a new one appears.
User prompt
The birdseed appears on screen at the start of the game. The pigeon pecks at the seed, when the user scrolls the pigeon nearby the birdseed, and the player gets 100 points.
User prompt
The birdseed appears on screen every 5 seconds.
User prompt
The pigeon is controlled by the user’s thumb on a mobile device. The bird generates a signal when the bird approaches nearby birdseed.
User prompt
The bird walks on screen and approaches. The user tosses out bird seed for the pigeon.
User prompt
I want the pigeon to peck at the seed.
Initial prompt
Pigeons and Friends
/**** * 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 }; }); // BreadCrumb class representing collectible items var BreadCrumb = Container.expand(function () { var self = Container.call(this); var breadCrumbGraphics = self.attachAsset('breadcrumb', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Update logic for breadcrumb }; }); //<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 birdseed 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); } } }; }); /**** * 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; // 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 += 1; birdSeed.destroy(); birdSeeds.splice(i, 1); } } // Spawn new birdseed every 60 frames if (LK.ticks % 60 === 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(); };
===================================================================
--- original.js
+++ change.js
@@ -1,94 +1,114 @@
-/****
+/****
* 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
+ };
+});
// BreadCrumb class representing collectible items
var BreadCrumb = Container.expand(function () {
- var self = Container.call(this);
- var breadCrumbGraphics = self.attachAsset('breadcrumb', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.update = function () {
- // Update logic for breadcrumb
- };
+ var self = Container.call(this);
+ var breadCrumbGraphics = self.attachAsset('breadcrumb', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ // Update logic for breadcrumb
+ };
});
//<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;
- };
+ 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 birdseed
+ 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);
+ }
+ }
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x87ceeb // Init game with sky blue background
+ 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 breadCrumbs = [];
+var birdSeeds = [];
var score = 0;
-// Function to spawn breadcrumbs at random positions
-function spawnBreadCrumb() {
- var breadCrumb = new BreadCrumb();
- breadCrumb.x = Math.random() * 2048;
- breadCrumb.y = Math.random() * 2732;
- breadCrumbs.push(breadCrumb);
- game.addChild(breadCrumb);
+// 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;
+ pigeon.x = x;
+ pigeon.y = y;
};
// Update game logic
game.update = function () {
- // Check for collisions between pigeon and breadcrumbs
- for (var i = breadCrumbs.length - 1; i >= 0; i--) {
- var breadCrumb = breadCrumbs[i];
- if (pigeon.intersects(breadCrumb)) {
- score += 1;
- breadCrumb.destroy();
- breadCrumbs.splice(i, 1);
- }
- }
- // Spawn new breadcrumb every 60 frames
- if (LK.ticks % 60 === 0) {
- spawnBreadCrumb();
- }
+ // 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 += 1;
+ birdSeed.destroy();
+ birdSeeds.splice(i, 1);
+ }
+ }
+ // Spawn new birdseed every 60 frames
+ if (LK.ticks % 60 === 0) {
+ spawnBirdSeed();
+ }
};
// Display score
var scoreTxt = new Text2('Score: 0', {
- size: 100,
- fill: 0xFFFFFF
+ size: 100,
+ fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Update score display
function updateScore() {
- scoreTxt.setText('Score: ' + score);
+ scoreTxt.setText('Score: ' + score);
}
// Call updateScore every frame
game.update = function () {
- updateScore();
+ updateScore();
};
\ No newline at end of file