===================================================================
--- original.js
+++ change.js
@@ -1,7 +1,21 @@
/****
* Classes
****/
+var Animal = Container.expand(function () {
+ var self = Container.call(this);
+ var animalGraphics = self.attachAsset('animal', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -5;
+ self.update = function () {
+ self.x += self.speed;
+ if (self.x < -animalGraphics.width / 2) {
+ self.destroy();
+ }
+ };
+});
// Assets will be automatically created and loaded during gameplay
// Bird class
var Bird = Container.expand(function () {
var self = Container.call(this);
@@ -67,8 +81,15 @@
/****
* Game Code
****/
+function spawnAnimal() {
+ var animal = new Animal();
+ animal.x = 2048 + animal.width / 2;
+ animal.y = Math.random() * (2732 - animal.height) + animal.height / 2;
+ obstacles.push(animal);
+ game.addChild(animal);
+}
var bird = game.addChild(new Bird());
bird.x = 2048 / 4;
bird.y = 2732 / 2;
var obstacles = [];
@@ -122,9 +143,9 @@
coins.splice(j, 1);
}
}
if (LK.ticks % 120 == 0) {
- spawnBird();
+ spawnAnimal();
}
if (LK.ticks % 240 == 0) {
spawnParrot();
}