Game Development Reference
In-Depth Information
nrPairs : 1,
hint_arrow_x : 4,
hint_arrow_y : 3,
hint_arrow_direction : 3,
tiles : ["#########",
"#.......#",
"#...r...#",
"#.......#",
"#.......#",
"#.......#",
"#...r...#",
"#.......#",
"#########"]
});
This example is the first level. As you can see, the locked status of the first level is set to false so
the player is allowed to play this level. The locked status of all the other levels is set to true . When
the player finishes a level, you update this status. The levels are defined in the levels.js file. This
is a JavaScript file, but it's located in the assets folder of the PenguinPairs4 example, because this
data is more an asset than code. Also, this way a designer can work in the assets folder and change
sprites and level data without having to look at the game-running code.
The Playing State
In the previous chapter, you saw how to create multiple game states such as a title screen,
a level-choice menu, and an options menu. In this section, you add a playing state . The playing state
basically consists of a list of levels, each represented by its own game world. For states such as the
title screen and the options menu, you could create a subclass of GameObjectList . However, here
that doesn't make a lot of sense, because the playing state needs to switch between game worlds.
Therefore, you aren't going to inherit from GameObjectList . But you do want to define game-loop
methods such as update and draw . You can slightly change the software design to accommodate this
by introducing a new class, IGameLoopObject . The only thing this class does is provide the definition
of the methods that any object part of the game loop should have. Here is the complete class:
function IGameLoopObject() {
}
IGameLoopObject.prototype.handleInput = function (delta) {};
IGameLoopObject.prototype.update = function (delta) {};
IGameLoopObject.prototype.draw = function () {};
IGameLoopObject.prototype.reset = function () {};
This class is called IGameLoopObject instead of, for instance, GameLoopObject because such classes
are generally called interfaces in software design. Interfaces are very useful because they provide
programmers with information about the kinds of methods (or properties) that can be expected
when a class implements that interface (in other words, inherits from the interface class). Quite a few
programming languages have a special programming construct that lets you create these interfaces.
This isn't the case for JavaScript, but you can still use the concept to achieve the same results.
 
Search WWH ::




Custom Search