Game Development Reference
In-Depth Information
Planning the Terrain class
Before we jump to coding the Terrain class, we need to discuss a few things regarding
randomness.
It is a very common mistake among game developers to confuse randomness with variable-
ness, and very important to know when you need what.
A random number can be anything. 1234 is a random series of numbers. And the next time
you want a random series of numbers and you once again get 1234 this will be just as ran-
dom as the previous one. But not varied.
If you decide to build a random terrain, you will probably be disappointed in the result as it
won't necessarily be varied. Also, remember that we need to make the terrain the key chal-
lenge of the game; but this means it can be neither too easy nor too difficult. True random-
ness would not allow us enough control here, or worse, we would end up with a long list of
conditionals to make sure we have the correct combination of blocks, and that would result
in at least one recurrent function inside our main loop, which is not a good idea.
We need instead to control the results and their variableness by applying our own patterns
to them.
So we'll apply this logic of patterns to our _terrain object, forming a kind of pool of
proper random choices. We'll use four arrays to store possible results in our decision mak-
ing, and we'll shuffle three of these arrays during the game to add the "randomness" feel to
our terrain.
These arrays are:
int patterns[] = {1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,3,3,3};
This holds the information of how many buildings ( Blocks ) we have in a row, between
gaps.
You can easily change the patterns value just by adding new values or by increasing or
reducing the number of times one value appears. So here we're making a terrain with far
more groupings of two buildings between gaps, than groups of three or one.
Next, consider the following lines:
Search WWH ::




Custom Search