It sounds like right now you’re spawning a set of initial room placements at the same time.
Typically this is done on a one by one basis with two functions, something like SpawnRoom
and OverlapsEntities
, where OverlapsEntities
returns a bool
if the next room to be generated would overlap with existing rooms.
I would also recommend that rooms be spawned with another room as a “root” for the new room.
Something like the following:
// psuedo
root = rooms.choose(1)
new_room = null
while(true):
new_room_location = transform_within_distance_of_location(root.transform, distance,
possible_rotational_offset = [0, 45, 90])
new_room = new Room(new_room_location)
valid = true
for room in rooms:
if overlaps_entities(new_room, room):
valid = false
if valid:
break;
The best generator I know of that is open source is the Donjon generator by Drow.
https://donjon.bin.sh/code/dungeon/dungeon.pl
That source may be helpful.
Good luck!