We’re only a few days from the competition deadline now, so things are getting hectic enough that we just haven’t had time to upload a new build. To tide you over until the next update, here’s a nice, boring article about programming!
If you read my first post about Drillboid’s level generator, you may recall that I mentioned that the generator works in three steps. I’ve covered the first step, which is choosing where all the rooms fit together, but those rooms need to be filled with something, which is what steps two and three are. Today, I’ll explain a bit about how that works.
So, when the first step is done, we have something that looks like this. Every cell in that grid has two pieces of information: whether the cell is active, and from which directions it can be entered. For example, the topmost cells can only be entered from their top and bottom. Using that, the generator picks from a list of possible rooms given the directions it needs to go in. Here’s one of the rooms that you probably see quite frequently in the game, whether you noticed or not:
You might find the shape of this room faintly familiar. Considering that this room can show up 20 times in a single level, you’d think that you’d remember it better. Part of the reason is that the camera zooms in a fair amount, so you might not know where one room starts and the other ends, or what the overall shape of the room is. The other reason is that this room could show up as this:
They’re a similar room, but there’s just enough variation that you probably didn’t notice it while you were playing! These variations are the product of certain tiles in the room having a chance of being erased. All of the pink-coloured tiles in the following picture have a 50% chance of being erased when the room is placed:
However, this room is also special in that in can be placed running in any of the four possible directions. This makes it easy to fill a level up with rooms – we just add certain blocks into a special group that erases itself when the generator tells the room that it’s being entered from a certain direction. So, with that in mind, the room could also look like this:
Or even this:
Outside of that, there’s one other trick up the generator’s sleeve. A good example of it is another room you probably recognize:
In order to keep things interesting, those three pink chunks are randomly erase, making a different maze-like pathway each time. However, it doesn’t just randomly erase them, because there would be a chance that none of them get erased, and it would appear to be a dead end when it could very well be the only passageway into the rest of the level! To clear up this problem, the three chunks of dirt are in a special group that randomly picks between one and three of them, then erases them. That way, you’re guaranteed to have at least one path through, but it could be on a different side.
The one step left is to place enemies. Originally, every tile had a small chance of placing an enemy on top of it, but we realized that it sometimes lead to long periods with no enemies. To fix that, the generator gets a tally of all the rooms in the level, multiplies that by a random factor, then “distributes” the enemies randomly to each room in the level. This way, the enemies are more consistently placed throughout the level, and there’s the added bonus that we just run the first step of the generator, which takes less than a second, and know approximately how many enemies will be in the level (although this doesn’t account for secret rooms and rooms with enemies built into them).
And that’s really all there is to the generator! For those who are curious, the version of the game currently on the site uses 12 different room prefabs for the caves, including the room that the orb spawns in, and the ruins use 9 different room prefabs, also including the orb room. You might notice that the ruins rooms are more easily recognizable from each other, and this is on purpose – it gives it a more modular, planned-out feel than the caves, which you’d expect from a high-tech building, and it also makes it feel fresh and varied after having explored the much messier, sprawling caves. Those kinds of careful considerations are put into every room in the game, which is why with a fairly small number of pieces, the caves tend to feel different every time.
Hopefully this article was interesting to you! Leave a comment or send us an email to drillboid[at]mildlydisconcerting[dot]com if you have any questions.