New tiles and level generation

After lots and lots of dirty hacks and ugly workarounds, I got new partitioner working (and then cleaned to a degree). Now it is possible to have levels, where rooms don’t form uniform grid, but form more interesting shapes.

If you recall from previous blog posts, level generation is split into multiple steps. One of the very first ones is dividing the level into square sections that are randomly linked together. Rooms are then placed within those sections and linked together with corridors. Previously sections formed uniform grid that produced somewhat uninteresting results.

The new routine starts by dividing the level in two sections. The split is done randomly in either horizontal or in vertical line. Resulting two sections are then split into two and this is repeated until they are small enough. After that sections are randomly linked together and level generation proceeds as before.

The routine used to link sections together is simple. First a random section is chosen. Then one of the neighbours that has not been connected is selected and connected to. Same is repeated to the neighbour that we just connected to, thus building a chain of linked sections. When new connection is not possible, we check if there are any sections that have been linked and have unconnected neighbours. If one is found, a new path is built from it, otherwise the routine terminates.

Results are pretty good already. At later time, I’ll add more routines for partitioning level, which hopefully will make environment more interesting.


2 thoughts on “New tiles and level generation

  1. Check out Brogue, which has all rooms directly touching one another. It seems to me that the dungeon feels more natural that way, like it could be cut out from the inside of a mountain. The source code is freely available, so you could always check it out for some ideas or direction.

    • Thanks for the reply. I actually have been thinking of writing some levels where rooms would be touching each other. I’m cleaning up the mess and hacks that I did to get the level generation working with new partitioner, but after it’s done, I’m planning to have a look at that. I should have a look at Brogue’s code though, I would probably get lots of new ideas from that.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s