Game Development Reference
In-Depth Information
Planning for random code/generation
A key point of any good game design when you even start to think about adding random
code/generation to your game is to stop/look and listen. Never rush into using random sys-
tems in your game, else you will end up rewriting it at least three times before you're
done, and even then you won't be absolutely happy with the result.
Start working from a simple base and ask yourself:
• Do I actually need it to be random or will it get configured?
This is the first and most important question: are you trying to add random code/
generation because it's easier to throw in, and will a fixed configuration be more
suitable (is it really random you're after)?
Never use randomization lightly, even when it is just a range of numbers you
want to pick from; always question whether it is the right tool for the job. Inevit-
ably, using randomization is always going to be more expensive in terms of pro-
cessing (especially with more complex systems with deepening levels of recur-
sion or noise generation) than a simple mathematical equation to approximate the
values you are after. Do your research.
• Where in your design do you see the need for randomization?
Be specific! What do you actually need to be randomized or sampled?
For example, in this RPG project for the random battle events on the map, we
need to figure out the following:
◦ The chance of an event occurring on a journey
◦ Where on the journey the event will occur
◦ What will be the starting condition of the battle, number of enemies, their
strength, and who fights first
• In each area, how frequently will you need a random sample?
Because of the cost of random selection, you need to decide when and where the
generation will take place. If you need a single random for each frame, that might
be okay (depending on what else is happening in each frame); but if you have
many, then it may be better to prefill an array of random numbers at the start of
the scene and perform a predictive selection of numbers in that array (either step-
ping through or selection based on other factors).
• What level of complexity does the random sampling/generation need?
Search WWH ::




Custom Search