Game Development Reference
In-Depth Information
In the update method of the Level class, you check whether the level was completed. If so, you call
the levelFinished method in the Player class, which plays the “celebration” animation:
if (this.completed && timer.running) {
player.levelFinished();
timer.running = false;
window.LEVELS[this._levelIndex].solved = true;
}
You also stop the timer, because the player is done. Furthermore, you set the solved status of this
level to true so that the next time the player starts the game, the browser will remember. In the
PlayingState class, you deal with switching to other states depending on the state of the level. Here
are the corresponding lines of code in the update method of that class:
PlayingState.prototype.update = function (delta) {
this.currentLevel.update(delta);
if (this.currentLevel.gameOver)
powerupjs.GameStateManager.switchTo(ID.game_state_gameover);
else if (this.currentLevel.completed)
powerupjs.GameStateManager.switchTo(ID.game_state_levelfinished);
};
The code to deal with transitions between levels is fairly straightforward and is almost a copy of the
code used in the Penguin Pairs game. Have a look at the code in the TickTickFinal example to see
how this is done.
You've now seen how to build a platform game with commonly occurring elements such as
collecting items, avoiding enemies, game physics, going from one level to another, and so on. Does
it end here? Well, that depends on you. To make Tick Tick a game that is commercially viable, a lot
of work still needs to be done. You probably want to define more of everything: more levels, more
enemies, more different items to pick up, more challenges, more sounds. You may also want to
introduce a few things that I didn't address: playing with other players over a network, side scrolling,
maintaining a high-score list, playing in-game movies between levels, and other things you can think
of that would be interesting to add. Use the Tick Tick game as a starting point for your own game.
The final part of this topic covers a few more things that are useful to know when you're developing
games and applications in general in JavaScript. I discuss documentation in more detail, as well as a
few ways to protect your game code and let players download your game more quickly.
What You Have Learned
In this chapter, you have learned:
How to add a timer to a level
How to create animated backgrounds consisting of mountains and clouds
 
Search WWH ::




Custom Search