===================================================================
--- original.js
+++ change.js
@@ -1,21 +1,7 @@
/****
* 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);
@@ -56,22 +42,38 @@
self.destroy();
}
};
});
-var Parrot = Container.expand(function () {
+// Obstacle class
+var Obstacle = Container.expand(function () {
var self = Container.call(this);
- var parrotGraphics = self.attachAsset('parrot', {
+ var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -5;
self.update = function () {
self.x += self.speed;
- if (self.x < -parrotGraphics.width / 2) {
+ if (self.x < -obstacleGraphics.width / 2) {
self.destroy();
}
};
});
+// Rod class
+var Rod = Container.expand(function () {
+ var self = Container.call(this);
+ var rodGraphics = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = -5;
+ self.update = function () {
+ self.x += self.speed;
+ if (self.x < -rodGraphics.width / 2) {
+ self.destroy();
+ }
+ };
+});
/****
* Initialize Game
****/
@@ -81,15 +83,8 @@
/****
* 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 = [];
@@ -100,22 +95,15 @@
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
-function spawnBird() {
- var bird = new Bird();
- bird.x = 2048 + bird.width / 2;
- bird.y = Math.random() * (2732 - bird.height) + bird.height / 2;
- obstacles.push(bird);
- game.addChild(bird);
+function spawnObstacle() {
+ var obstacle = new Obstacle();
+ obstacle.x = 2048 + obstacle.width / 2;
+ obstacle.y = Math.random() * (2732 - obstacle.height) + obstacle.height / 2;
+ obstacles.push(obstacle);
+ game.addChild(obstacle);
}
-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;
@@ -125,8 +113,14 @@
game.down = function (x, y, obj) {
bird.flap();
};
game.update = function () {
+ if (LK.ticks % 150 == 0) {
+ var rod = new Rod();
+ rod.x = 2048 + rod.width / 2;
+ rod.y = 2732;
+ game.addChild(rod);
+ }
bird.update();
for (var i = obstacles.length - 1; i >= 0; i--) {
obstacles[i].update();
if (bird.intersects(obstacles[i])) {
@@ -143,13 +137,10 @@
coins.splice(j, 1);
}
}
if (LK.ticks % 120 == 0) {
- spawnAnimal();
+ spawnObstacle();
}
- if (LK.ticks % 240 == 0) {
- spawnParrot();
- }
if (LK.ticks % 180 == 0) {
spawnCoin();
}
};
\ No newline at end of file