The idea for Noah’s Nightmare came about because I wanted to create a platform game with randomized levels. It’s an endless runner where you kind of know what to expect but the layout should be fresh with each play through. This is a tall order and what I’ve ended up with is a combination of hand designed components with randomized elements within them. This ensures a game that is fun and playable but that will still feel different each time it is played.
The procedural structure I’ve used it taken from the wonderful Spelunky. For anyone interested, this tutorial gives a fantastic step by step guide to how a Spelunky dungeon is made. Fortunately, Noah’s Nightmare is a little simpler because it is only one screen wide (one room wide in terms of the Spelunky tutorial). This means that it only needs to account for an entrance at the bottom and an exit at the top. I could give the rooms more than one entrance or exit but to keep the number of template types down I have decided to stick to one entrance and one exit, either of which can be at the left, middle or right.
This design leads to the following five template types that can be stacked on top of one another to give an endless dungeon:
– “LR” templates have an entrance at the bottom left and an exit at the top right.
– “RR” templates have an entrance at the bottom right and an exit at the top right.
– “MR” templates have an entrance at the bottom middle and an exit at the top right.
– “MM” templates have an entrance at the bottom middle and an exit at the top middle.
– “RM” templates have an entrance at the bottom right and an exit at the top middle.
All other configurations can be created by flipping any one of the above templates. With enough designs for every template type as well as randomization within the template designs (obstacle blocks and random tiles), the dungeon can appear to be completely procedural whilst still retaining that hand-designed element.
All the code needs to do when creating the next template up is to match up the new entrance to the exit below, pick a corresponding template type, pick a design from the chosen template type and then create the new dungeon room from the design.
Here’s a sample dungeon schematic that is currently five rooms high. The letters down the right correspond to the template types to be used.
In reality, only three rooms are ever in existence at any one time. Otherwise, the game would slow considerably as new rooms get created but old rooms stay in memory. For this reason, all entrances (the gaps at the bottom of rooms) are one way only. I don’t want the player to be able to backtrack to a previous room and there shouldn’t be any reason to either. I consider every room to be a small, self-contained puzzle. Once it is solved, it’s solved and you move on.