Game Development Reference
In-Depth Information
if (nextX + orb.size > canvas.width) {
nextX = canvas.width - orb.size;
orb.speed *= -1;
}
else if (nextX - orb.size < 0) {
nextX = orb.size;
orb.speed *= -1;
}
orb.nextX = nextX;
}
}
p.render = function () {
var i, orb;
var len = this.orbContainer.getNumChildren();
for (i = 0; i < len; i++) {
orb = this.orbContainer.getChildAt(i);
orb.x = orb.nextX;
}
this.msgTxt.text = "ORBS LEFT: " +
this.orbContainer.getNumChildren();
}
p.checkGame = function () {
if (!this.orbContainer.getNumChildren()) {
this.dispatchEvent(game.GameStateEvents.GAME_OVER);
}
}
p.run = function (tickEvent) {
this.update();
this.render();
this.checkGame();
}
window.game.Game = Game;
}(window));
You'll notice that like the game menu, the game class utilizes the run function, which is called from the game loop
in the main application. This is used to constantly animate all orbs in the container. The msgTxt text object is updated
within the render function, and will reflect the number of remaining children in orbContainer . Figure 10-2 shows the
game in action.
 
Search WWH ::




Custom Search