Most efficient way to procedurally generate rooms and corridors

Godot Version

Godot 4

Question

Hi people of the forum! I’m working on a vampire survivors-like game with procedural generation of the map and cod zombies-like quests and Easter eggs.

So I am early in development and I’m trying to understand how I will be able to make procedural generation of corridors and open spaces that lead to premade rooms with a randomised position. I heard of the Gaea plugin, but I don’t know if it will be useful for the
type of visual my game has (I don’t know how it’s called it’s not a top down but it doesn’t have “horizontal” view either, for reference I’m leaving an image of vampire survivors.


Or at least, I don’t think it’s top down as the characters are seen from side.

Are there other, maybe better ways to do procedural generation other than that plugin for what I’m trying to do?

And for the ones that may think “but in vampire survivors the map is an open space, what do you need procedural generation for?” yeah I thought of doing something different, having each game be in a procedurally generated dungeon with restricted (but not too much) space.

Sorry if my questions are kind of dumb or not clear.

A lot of the answer is going to depend on what you mean by “dungeon”? There’s a whole spectrum of possible answers here from “I want the occasional decoration tile scattered through my sea of grass tiles so it doesn’t look quite so griddy” to “I want a Dungeons & Dragons style corridors and rooms dungeon-crawl, randomized”.

At the simplest, you can have some set of grass tiles, say 8 variations. At level start, do something like:

# note: unoptimized, untested, lots of assumptions
# tiles is an array of Vector2i atlas coords of tiles

func randomize_floor(floor: TileMapLayer, floor_size: Vector2i, tiles: Array):
    for y in floor_size.y:
        for x in floor_size.x:
            floor.set_cell(Vector2i(x, y), 0, tiles[randi_range(0, tiles.size())])

You shouldn’t even have to do that by hand; Godot’s autotiling can handle it, I think.

You might instead want something a little more complex; maybe actual terrains, so some places are grass, some are forest, some pond… In that case, there are several ways to do it, but one of the popular ones is to use a 2D noise function to generate a heightmap, and pull values from he heightmap to populate the terrain. Maybe say that any cell below a height of 0.2 is water, 0.2..0.6 is grass, anything above that is forest.

At the most complex (and arguably highest quality) end, instead of working at the tile level, you have a set of hand-built, decorated rooms and corridors. Have all of them be enclosed, with marked entrances. When you go to make a level, place a room or corridor, and then connect a random room or corridor to each exit, recursively, being careful not to overlap; you’ll probably need small dead-end rooms to aid with this.

There are lots of other options; terrain and maze generation are a problem that games have been tackling since the 1970s, and a lot of ingenuity has been thrown at it.

2 Likes

Thank you. I am sorry I didn’t really explain my self with the word “dungeon”. I mean randomly generate corridors that lead to premade rooms that have a random position.

I haven’t messed with it, but you might be interested in:

You should be able to use those to hold rooms and corridors, though you might need to keep some separate metadata to track where entrance/exits are.

1 Like

Thanks I’ll look into that.