===================================================================
--- original.js
+++ change.js
@@ -42,8 +42,22 @@
self.destroy();
}
};
});
+var Parrot = Container.expand(function () {
+ var self = Container.call(this);
+ var parrotGraphics = self.attachAsset('parrot', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -5;
+ self.update = function () {
+ self.x += self.speed;
+ if (self.x < -parrotGraphics.width / 2) {
+ self.destroy();
+ }
+ };
+});
/****
* Initialize Game
****/
@@ -72,8 +86,15 @@
bird.y = Math.random() * (2732 - bird.height) + bird.height / 2;
obstacles.push(bird);
game.addChild(bird);
}
+function spawnParrot() {
+ var parrot = new Parrot();
+ parrot.x = 2048 + parrot.width / 2;
+ parrot.y = Math.random() * (2732 - parrot.height) + parrot.height / 2;
+ obstacles.push(parrot);
+ game.addChild(parrot);
+}
function spawnCoin() {
var coin = new Coin();
coin.x = 2048 + coin.width / 2;
coin.y = Math.random() * (2732 - coin.height) + coin.height / 2;
@@ -103,8 +124,11 @@
}
if (LK.ticks % 120 == 0) {
spawnBird();
}
+ if (LK.ticks % 240 == 0) {
+ spawnParrot();
+ }
if (LK.ticks % 180 == 0) {
spawnCoin();
}
};
\ No newline at end of file