Procedurally generated levels
** Originally published on the 12th of June 2016 **
Most games come pre-rendered. The process is quite easy to understand: a level designer sits down, draws a level that fits the general story, and later turns into a something a game engine can read. He starts by creating the background (skies, mountains etc), moves on to creating the actual structures (buildings, walls, tunnels, doors and so on) and then adds all the minor items that makes a place "alive" (furniture, random items, junk etc). He then continues by adding monsters and interesting encounters (including scripted encounters), and finally - he adds special effects and cleanups.
Sounds easy enough, right?
The next stage is of course to load up the level to the game's engine - and run it. Each game has some kind of engine that "knows" how to handle levels. That engine can load up any proper level, and let you play it. If all goes well - you have a new level for your game!
Let the machine do it!
Pre-creating your levels have their own pros and cons. The biggest con of all - a level will always stay the same. When you enter that forest level - it will have the exact same shape; the enemies will be the same, and will wait for you at the exact same spot; the effects and scripts are always the same - there are no surprises.
So, some games have decided to go another way - procedurally-generated levels!
Procedurally-generated levels are levels that are created semi-randomly (more on that later), by the game, with each run, according to a set of rules. That means that on each play, things will be different. So, a procedurally-generated forest levels, may have the same background or theme, but may have a different shape, monsters will be different (and may change position) and so on.
Now that we know the difference between procedurally-generated levels, and other "normal" levels, it's time to discuss the "how": How do you actually create a procedurally-generated level?
Almost every time, a good solution to a problem, starts with some good research. So I did my research. Turns out, that although the field of procedurally-generated algorithms is not a new one, there's not a wealth of information out there. Even pages like
are not that encompassing, and provide only hints and general pointers.
Luckily, it turns out that the basic idea is not that hard. As you break the task into smaller and smaller tasks, it becomes easier. So, after some research, and some late-night brain-storming, I got this very basic algorithm:
To the future
Now that we have the basis of what we're going to do, I'm going to try and do it, week by week, according to the stages listed above. As I go along, I'll share with you guys, in this long series of posts, how each stage advances, what I've learned from each stage, as well as changes and fixes to the algorithm. At the same time, I'll share the basic code of each stage (in C#) as well as the assets and levels that I'm creating in Unity.
Hopefully, I'll be able to post a new post every week, so we're looking at at-least two and a half months, but I believe it'll take much longer, as with the recent move to Australia, and starting a new job, I'm guessing my schedule will be quite tight.
Stick with me next time, as we talk about the basics of the algorithm we've created, and write down the first function - ChooseSize()!