Chapter 4. Procedurally Populating Game Environments
Now that we're comfortable using Random Number Generator (RNG) with core C++ data types, let's have a look at how to create a highly randomized environment. This will include the random generation and positioning of items, enemies, and more. We'll also touch upon random map generation in this chapter before tackling it head-on toward the end of the book.
The way in which objects are spawned will largely depend on the infrastructure of your level data. With most 2D games, you'll be able to take an approach that is similar, if not identical, to the one demonstrated in this chapter. However, a 3D game requires more work because there's an extra dimension to deal with, but the principles are still valid.
In this chapter, we'll cover the following topics:
- Obstacles with procedurally populating an environment
- Defining the spawn area
- Randomly selecting a game
tile
- Spawning items at a random location
- Procedurally...