Game Development Reference
In-Depth Information
Thanks to the proper implementation of the reset method everywhere throughout the game object
classes, resetting a level to its initial state is now really easy. You have to call the reset method on all
the game objects, and then you deal with resetting things in the Level class itself. The only thing you
need to do there is set the firstMoveMade variable to false so the player can view a hint again:
Level.prototype.reset = function () {
powerupjs.GameObjectList.prototype.reset.call(this);
this.firstMoveMade = false;
};
Note There are many ways in which the Penguin Pairs game can be extended. For example, can you write
code that determines whether a level is still solvable? You could extend the game by displaying a message to
the user if that happens. You might have your own ideas about how the game could be improved. Feel free to
try them by modifying and adding to the examples.
Moving to the Next Level
When the player finishes a level (hurray!), you would like to display an encouraging overlay
(see Figure 23-2 for a screenshot). When the player clicks or taps the screen, the next level is
shown. Because you created the GameStateManager class, let's profit from it by adding another
state: LevelFinishedState . The only thing this state does is display the overlay and react to a player
clicking. Because the overlay is displayed on top of the level, you still need to do something with the
playing state. Therefore, you store it in a member variable. In addition, you load an overlay, position it
in the center of the screen, and add it to the game world. Here is the complete constructor method:
function LevelFinishedState() {
powerupjs.GameObjectList.call(this);
this.playingState = powerupjs.GameStateManager.get(ID.game_state_playing);
this.overlay = new powerupjs.SpriteGameObject(sprites.level_finished, ID.layer_overlays);
this.overlay.position = this.overlay.screenCenter;
this.add(this.overlay);
}
 
Search WWH ::




Custom Search