Level GenerationAfter some tinkering I think I have a decent enough algorithm, and I'll try to explain the thought process behind it.
As I explained some posts ago, I want the individual rooms to be handcrafted. This means that
the algorithm has the only task of placing and connecting a combination of these rooms. In my opinion this is the perfect blend of well-thought design and replayability! Inspiration for this idea comes from games like Spelunky and Enter the Gungeon.
Another goal I'm aiming for is to have secret or
special zones in the level, where exploration and risk-taking are rewarded. This means that the level has to have some
optional paths that hide
some delicious loot! In the end the player could just look for the end of the level and rush to it, but he would be definitely be missing some great stuff
The algorithm starts by placing an starting room (green) and connecting 4 rooms, one for each exits.
This way we ensure the player doesn't encounter a dead-end too soon. Then we start expanding the level by connecting new rooms to previous ones. In order to make the level more balanced,
the closest a room is to the starting one, the higher the chance it has of spawning a new room. This will avoid large corridors of rooms, and instead we'll generate a tree-like layout.
Bear in mind that we don't add arbitrary rooms!
Each new room is selected from a list of hand-crafted templates. This means that we might add a room with an open exit that is too close to another one. We'll fix this in later steps
For now we continue to expand the level. Remember the special areas I talked to you about? Time to randomly start them! When we reach a determined number of spawned rooms
we'll spawn a special one (red).
Every room that we expand from this one will be part of that special path. The other will be just regular ones. We'll just keep adding rooms until we reach the number of rooms we want.
Cool! We have finished our level, let's pack things up and go home...
WAIT! We can't leave this mess, there are a lot of rooms with open exits that lead nowhere. Hell, we don't even have a goal in the level! Time to close the open exits then. First
we'll find a place for the goal/end room (yellow).
This seems like a cool place to put the goal! Now we'll proceed to
close the rest of the paths with some juicy loot rooms (purple). This way, even if the player reaches a dead end, he might encounter some interesting stuff in there
Neat-o! This looks more like it! However we still have the problem we mentioned earlier,
there are some rooms that can't possibly be closed without overlaping Well... since we can't close them by connecting a room to them, we'll just have to
replace them with a different room with the number of exits we want
And with this last step, we already have our magnificent level complete with loot rooms, special dangerous paths and, most importantly, a goal!
This is all for today. Now time to port this to C and test it with real, handcrafted rooms which we can play through!