How do I Generate a random dungeon layout?

1 favourites
  • 11 posts
From the Asset Store
A procedurally generated infinite runner in 3D for Construct 3!
  • I remember watching a simple youtube tutorial (not specific to Construct), explaining how to randomly generate dungeons like this, where there is a guaranteed route through all rooms from start to finish.

    Basically, the algorithm determined how many passages/doors will be in each room and where they will be located.

    Unfortunately, I lost that video.

    Does anyone have a link to that tutorial or know the algorithm to generate such levels?

  • Probably can do it with a maze generating algorithm. Or something like that.

    en.m.wikipedia.org/wiki/Maze_generation_algorithm

    Edit:

    One possible way using prim's algo.

    dropbox.com/s/58l1kqgcdlse96x/primsAlgo.capx

  • I don't know the video or specific algorithm you might be referring to, but the first approach I would try would be with a random walker algorithm, where the walkers are not allowed to move into existing tiles (or out of the bounds of the map). If the walker "traps" itself or reaches the exit, then start over, following the same previous path until there is a valid tile to branch into, and continue from there. You can add the constraint of not allowing 4 way rooms, but if you don't allow 3 way rooms either that would be difficult to always arrive at a specific end tile, and it may not be solvable at if there is a requirement for every tile to be filled in. Repeat until all possible tiles are filled or unreachable.

    This should result in a map where all tiles are reachable from both the entrance and exit. By keeping track of the number of existing exits from each room, additional constraints can be added, like only one exit for the entrance and exit rooms.

    So at each step, generate a list of valid tiles/exits to walk to, and pick one randomly, until there are no more valid exits. Then start over from the beginning until a valid exit is found to make a branch.

    The blue x on the second iteration represents the constraint where the first room can only have 1 exit, so a branch cannot be made there. The red x on the third iteration is the constraint that a room cannot have 4 exits, so it can't branch there and continues until it finds a valid tile to branch into.

  • R0J0hound Thanks, your example is what I need! Although I have a feeling they used the Wave Function Collapse in that video... Maybe I'm wrong.

    oosyrag Interesting method, but a bit over complicated. And as I understand, it may create impossible configurations, which means it will need to be repeated until a good solution is found.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Idk, using a wave collapse function doesn't seem to keep everything connected.

    Here's an experiment with it. I don't think I provided enough tile cases since it can't resolve a few tiles. It was interesting to mess around with though. It probably could be made to erase those dead ends to try again. It would also be nice to give some tiles more weight than others.

    dropbox.com/s/grb9i41yhpy8uhp/waveFunctionCollapse.capx

  • I have been trying my hand at autogenerator things the last few days, and figured I try this one too.

    I set off with trying to find my own method for connecting rooms, but it got sloppy and rather cumbersome ... So .. I borrowed prims method from what R0j0 posted, and played around with it.

    One of the things I pondered with how this could work and most importantly, be applied in game.

    Here I took the extra step of creating portals in the interconnected rooms.

    I added a delay between the creation steps, so you can see how the map gets build.

    In the end the rooms get repositioned, this with the idea that you could eventually place the room anywhere on your layout, and still get connected to the proper rooms. This lends itself for a variety of extra options.

    The repositioning is done so the visual aspects still shows where rooms doors point to atm.

    Now, the rooms have no solid walls atm, and the player is a simple move8 which can just cross over walls atm. In a worked out scenario, the rooms will have extra walls with solids or what not.

    edit: added some walling with solids and pushout

    The test is to use the portals with the player.

    boomtanium.com/construct/Dungeon_generator

    I liked creating this, if you have feedback or suggestions for adaption, feel free.

  • XHXIAIEIN These links are amazing, thank you! Yeah, that video tutorial definitely explained one of these algorithms, it doesn't matter which one now :)

  • My addiction 'for' loop drives me to create recursive room generator to be tested:

    dropbox.com/s/bdwbztvqalda546/recursive_dungeon_room.capx

    The pattern recursion based on 4^n_division that generates multiplication by 1, 4, 16 and so on. I called this quad division. 3/4 passage generated for each cross section and shifted randomly during division to fit middle wall.

  • I found the following maze tutorial on Youtube which explains a recursive maze creation method:

    https://www.youtube.com/watch?v=Y37-gB83HKE

  • Subscribe to Construct videos now

    enjoy

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)