Random Dungeon


This is my random dungeon generator. It’s very simple, it spawns 150 connected tiles and places a chest somewhere in the maze. Have fun looking for it.

The generator is about 60 lines long, but also look at the tiles, there’s some magic hidden in them.

Download Link:
sendspace.com/file/zd9jwj

Added some new tiles (there are 18 now), I’ll probably upload something playable and more complete soon, for now just a bad quality video:
youtube.com/watch?v=K1btqsuhcDE

Cool! I like )
I also made the generator before, but used a slightly different principle - based on rooms.

Old screen (without effects and doors):

Everyone should write a random dungeongenerator at some point :smiley:

Most generators work with rooms, at least the rouglike ones do. At first that’s what I wanted to do, but I didn’t have any ideas on how to connect the rooms once I have them. I’ve also seen one that uses just a wall and a floor and then ‘sprays’ the level
with ‘features’ (pillars, chests, junk, etc).
My generator could make use of rooms (tiles that are bigger then 1 tile) but one would have to tell it how big is the room and mark the space it uses as …well used (and first check if it’s free). I’m using a set to check what is free, I was told it has the fastes membership tests as far as python goes so it should still be fast if a few more tests needs to be done. For now I think I’ll stay with the maze-like design.

If someone want’s to use my code be warned:
-if you have tiles without a roof (like mine) and you want to add tiles that go up or down(so that the level is not flat), skip the z coordinate in the set used for testing if the space is free -there won’t be tiles on top of other tiles.
-there are still some phantom one-way walls, not sure why or when they appear, it could be an error in the tiles I’ve made or a bug in the cap-holes algorithm.
-2 times it did hang my python interpreter, maybe when it creates a maze that can’t be expanded before reaching the limit of tiles set. Some sort of fail-safe should be added.
-if one wants to put lots and lots of tiles (like 500+) flattening it all to one node can be a bad idea. Some sort of tree structure or space partition could work.
-you can have some control over the look of the level by putting more or less of some types of tiles (if you put many ‘open floor’ type tiles you end up with quasi-rooms with pillars, many ‘tunel’ types will make a maze, if you put only ‘left turn’ you’ll get a spiral)

The code for my generator is simple, but not all that obvious, if someone want’s me to explain I’d be more then happy to do it.

Both of those generators seem rather cool! :slight_smile:

Heh, I made a random dungeon generator once upon a time, before I started using Panda, as I recall. :slight_smile:

In my case I think that I first created rooms, then for each room selected an edge tile in that room and a target room, then started advancing in the general direction from one to the other, occasionally changing direction arbitrarily and limiting the minimum number of tiles between direction changes and the maximum number of tiles in a straight section – or something like that; it has been quite some time, I fear! ^^;

I seem to recall that it produced decent-enough dungeons in a vein similar to those in Rogue.

slightly different principle - based on rooms. :mrgreen: :mrgreen:

In the spirit of the thread, this is one output of a quick-and-dirty dungeon generator that I built recently. The dungeons that it produces are linear and very simple, but on the other hand it only took a few days to build.

I haven’t made a lot of progress and there’s some really, really crazy/experimental stuff in there, but it sort of works and it’s not flat anymore.

Known issues:
-the walkmap is somewhat wrong, height doesn’t match, some coordinate (X+?) is one unit off, it’s limited to +/-64 units in Z and +/- 256 in X and Y, but tiles could get generated beyond these limits
-you have to move (press W) to get a valid start location

Here’s a video:
youtube.com/watch?v=1bCpkjY6mgk

Here’s the source+models packed in a zip:
sendspace.com/file/zd9jwj

License-wise the code is WTFPL the tiles CC-BY-SA

I like the improvements that you’ve made!

One thing that wasn’t clear to me in the video: can your dungeons have walkable areas above other walkable areas?

Another question: are you planning on incorporating rooms, or are your dungeons only to be corridor mazes?

No rooms above other rooms… at least not with the current version. I’m doing a ‘screenshot’ of the level from above with a black-white gradient projected onto it - what I get is a height map, plus areas of total black are considered not walkable. I’m only doing this because I have exteriors in my game that use a heightmap + walkmap and I’ve made a AI that knows how to navigate such a setup - checking the color of a pixel seams simpler then casting collision rays in various places on-demand.

As for the rooms… yes, in a way. At this point I have one type of ‘connection’ (two thick pillars on both sides of the passage - that’s why you see these double pillars all over the place) in the future I’ll add more types, like narrow passage, thin round pillars (I think I’ve packed some of this type as ytile_*.egg in the zip), tiles that only have one wall and open floors. If I get them right rooms should appear naturally.

For example if I make a tile like this (red ==wall, green == floor):

then the only way to connect them is to form a square room:

Now to connect these to my typical ‘thick column’ tile, that look like this (blue==thick wall):

I need a meta-tile that has the blue-thick on one side and room-like-red on the other (think domino):

Then I can connect it all something like this:

TADA! ROOM!

Adding and mixing some other connection types and tile shapes can give all sorts of results - it’s kind of a emergent system- can’t really predict the outcome.

Your room-tile idea seems interesting – I look forward to seeing what results it produces!

I’ve re-uploaded the demo with the source:
sendspace.com/file/zd9jwj

The chest is placed at one of the tiles that have been generated, it’s random.
I have a list of coordinates where tiles are placed (self.used_tiles), then I just:
chest_pos=random.sample(self.used_tiles, 1)

I’ve done some experiments with this generator, but I don’t really have anything more usable then that first demo.

I want to use this but the download link won’t work. Please re-upload!

I’m afraid I’ve lost the working version. I still got all the tiles and some code, but the levels generated by that code are all wrong. I’ll try to make it work again.

Hoping that you get it working again. I was looking forward to learning from your example.