===================================================================
--- original.js
+++ change.js
@@ -1,61 +1,85 @@
-/****
+/****
* 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());
- };
+ 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());
+ };
});
+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
+ backgroundColor: 0x87CEEB // Sky blue background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize score text
var scoreTxt = new Text2('0', {
- size: 150,
- fill: "#ffffff"
+ size: 150,
+ fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Array to keep track of birds
var birds = [];
+// Array to keep track of bushes
+var bushes = [];
// 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);
+ 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();
- }
+ // Update logic for birds
+ for (var i = birds.length - 1; i >= 0; i--) {
+ birds[i].update();
+ }
+ // Update logic for bushes
+ for (var j = bushes.length - 1; j >= 0; j--) {
+ bushes[j].update();
+ }
};
+// 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();
\ No newline at end of file
+spawnBird();
+spawnBushes();
\ No newline at end of file