Sort rooms before generating corridors between them

This commit is contained in:
Eryn Wells 2023-03-05 14:26:20 -08:00
parent e3864d8468
commit 744c63bc85

View file

@ -38,9 +38,12 @@ class ElbowCorridorGenerator(CorridorGenerator):
``` ```
For each pair of rooms: For each pair of rooms:
1. Find the midpoint of the bounding rect of each room 1. Find the midpoint of the bounding rect of each room
2. Calculate an elbow point 2. For each pair of rooms:
3. Draw a path from the midpoint of the first room to the elbow point 1. Calculate an elbow point by taking the x coordinate of one room
4. Draw a path from the elbow point to the midpoint of the second room and the y coordinate of the other room, choosing which x and which
y at random.
2. Draw a path from the midpoint of the first room to the elbow point
3. Draw a path from the elbow point to the midpoint of the second room
``` ```
''' '''
@ -51,7 +54,9 @@ class ElbowCorridorGenerator(CorridorGenerator):
if len(rooms) < 2: if len(rooms) < 2:
return True return True
for (left_room, right_room) in pairwise(rooms): sorted_rooms = sorted(rooms, key=lambda r: r.bounds.origin)
for (left_room, right_room) in pairwise(sorted_rooms):
corridor = self._generate_corridor_between(left_room, right_room) corridor = self._generate_corridor_between(left_room, right_room)
self.corridors.append(corridor) self.corridors.append(corridor)