From 744c63bc8557c2951b93fb795e9d89f69c55a6c5 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 5 Mar 2023 14:26:20 -0800 Subject: [PATCH] Sort rooms before generating corridors between them --- erynrl/map/generator/corridor.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/erynrl/map/generator/corridor.py b/erynrl/map/generator/corridor.py index aa93b9d..13ce2ba 100644 --- a/erynrl/map/generator/corridor.py +++ b/erynrl/map/generator/corridor.py @@ -38,9 +38,12 @@ class ElbowCorridorGenerator(CorridorGenerator): ``` For each pair of rooms: 1. Find the midpoint of the bounding rect of each room - 2. Calculate an elbow point - 3. Draw a path from the midpoint of the first room to the elbow point - 4. Draw a path from the elbow point to the midpoint of the second room + 2. For each pair of rooms: + 1. Calculate an elbow point by taking the x coordinate of one 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: 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) self.corridors.append(corridor)