Game Development Reference
In-Depth Information
If local storage has not yet been set for the game, it is created by using the dataTemplate object within the
setLocalStorage method and is then set to the player property. Figure 14-5 shows some saved data in local storage
by using a Local Storage Manager extension for Chrome.
Figure 14-5. The player stats stored in local storage
With the data set for the game, player stats, and the enemies, it's time to build the Enemy and Hero classes.
Building the Enemies and Hero
All enemies will use the same Enemy class. It should simply take a data object, retrieved by the EnemyData object, and
appear and function accordingly. The Hero class will simply represent the current stats in PlayerData and will be used
to play the level. Both classes will be built in this section.
Creating the Enemy Class
The Enemy class will be a container that holds two consistant display objects. One is a sprite for the enemy sprite sheet
frame, and the other is for its health meter, which will be its own container class as well. The Enemy class has a few
other elements and a number of things going on so I'll break it down into a few parts, starting with the properties and
initialize method (see Listing 14-9).
 
Search WWH ::




Custom Search