In the previous article, we saw how our Level Elements (Element of a Random Generated Level) were built. In this article, we will focus on the creation process itself.
Level generation is done in the following order:
- Find the entry point, generate the entrance
- Generate the main path to a given exit
- Generate secondary path if needed
- Record the enemy spawn points of the level for easier treatment later
- If a mission has started, place the required enemies in the right spot
- Place chests according to AI placement (better potential reward where enemies are powerful)
- Finalizing touch
Let’s detail all these parts.
Placing an entrance is the simplest thing. Entrance can be positioned on the grid extremity, or at center.
Building the main path
Now, we select an exit point on the entrance mesh. This will be the start of our main path. The main path connects the entrance and the exit of the level, it is the one sure path to the end area. In order to create that path, we check the Level Design parameter file:
In the previous article, we presented these main parameters:
- Number of rooms in the level
- Amount of Corridors, Stairs Up, Stairs Down
- Maze Factor of the level – Is the level supposed to look like a straight corridor or a maze
- Maximum size of each room
- Maximum level of each rooms
- Remember that our Level Element also has parameters, used during the generation, such as Frequency or Level. (see our previous article)
According to all these parameters, we will select and place Elements in our Level. When the maximum size of the level is reached, an exit point is selected. The boss of the level, is exists, will have high chance to spawn in here.
Building secondary path
Our Level Element may have several exit, and since we only generated the main path, most of the Level Element exit are still empty. That’s why we have a Secondary Path option.
Secondary paths will generate alternative path, usually not leading to the level exit. Usually, long alternative path will feature a nice reward for players who enjoy exploring our levels!
Each Randomized level have a secondary path min and max values, defining how long these secondary path should be: Of course if it is a long path, the reward will be even better.
Enemies and Furnitures Spawn Points
For performance reason, we don’t want to spawn all enemies in the beginning of the level. We will spawn them once a player is close enough, so we need to record all possible spawn points. We noticed that physicalized object, such a Destroyable Object also took a lot of resources if they were all loaded on the same time, so we will spawn them just like we spawn enemies.
It is also important to record where we want mission objectives to spawn. We do it at this phase.
This is an important part, which add some important visual and gameplay attribute to the level. We will describe it in a future article.
That’s it for today. In the next article, we will show the finalizing touch of our level !