Game Development Reference
In-Depth Information
Building the terrain object
So every time we need to create a new block, we'll set it up based on the information con-
tained in these arrays.
This gives us far more control over the terrain, so that we don't create impossible combina-
tions of obstacles for the player: a common mistake in randomly-built terrain for dash
games.
But at the same time, we can easily expand this logic to fit every possible need. For in-
stance, we could apply level logic to our game by creating multiple versions of these ar-
rays, so as the game gets harder, we begin sampling data from arrays that contain particu-
larly hard combinations of values.
And we can still use a conditional loop to refine results even further and I'll give you at
least one example of this.
The values you saw in the patterns arrays will be stored inside the lists called
_blockPattern , _blockWidths , _blockHeights , and _blockTypes .
The Terrain class then takes care of building the game's terrain in three stages. First we
initialize the _terrain object, creating among other things a pool for Block objects.
Then we add the first blocks to the _terrain object until a minimum width is reached to
ensure the whole screen is populated with Blocks . And finally we distribute the various
block objects.
Search WWH ::




Custom Search