Fix a bug where the generator could crash by trying to place the starting room out of bounds; starting room position is now random

This commit is contained in:
Charles Peyrat 2021-01-08 15:06:38 +01:00
parent fab1bee8d8
commit 8d7e264381

View File

@ -159,7 +159,9 @@ class Generator:
# the starting room must have no corridor
mem, self.params["corridor_chance"] = self.params["corridor_chance"], 0
starting_room, _, _, _, _ = self.create_random_room()
self.place_room(level, height//2, width//2, starting_room, 0, 0)
dim_v, dim_h = len(starting_room), len(starting_room[0])
pos_y, pos_x = randint(0, height-dim_v-1), randint(0, width-dim_h-1)
self.place_room(level, pos_y, pos_x, starting_room, 0, 0)
level[0][0] = Tile.EMPTY
self.params["corridor_chance"] = mem