Saturday, August 24, 2013

Dungeon Generator

Let's talk a little about the algorithm we use to generate the dungeon itself.  

I'm talking about the dungeon not the meshes, lighting, etc.

Early on we decided that our little dungeons would have floors, walls, pits, and bridges as the main building blocks.  So whatever algorithm we use needs to generate those blocks.

Before starting this project, I Googled "dungeon generator".   Wow.  Lots of results and lots of interesting reading.  Try it yourself.

But in the end, I decided to punt and come up with what seemed like it would generate an interesting dungeon without being too terribly hard to code.   I'm certain it isn't unique or original, by any means, but I didn't use anyone else's source for it.   I'm not going to go into the specifics of the code right now, just the general algorithm.

So, how do we get started?

First, we need some corridors for our player to run around in, so let's generate a maze...


A plain maze would make running around in the dungeon a bit annoying, so we'll add some "extra" corridors.


Now that are base paths are generated, we can add big gaping chasms to it, just for variety...


... and rooms ...


Hmmm... maybe add a bit more "pit".


And finally, doors and columns.


And there you have it!

And I'll leave you with one more screenshot of a 1024x1024 dungeon (which runs just fine in Unity, by the way, but it takes several seconds to build all the meshes):


No comments:

Post a Comment