Fix place_room and add missing argument

This commit is contained in:
Charles Peyrat 2021-01-08 06:58:02 +01:00
parent 9c252a2bbc
commit d362bdc949
1 changed files with 8 additions and 8 deletions

View File

@ -45,14 +45,14 @@ class Generator:
return True
@staticmethod
def place_room(level, y, x, door_y, door_x, room):
def place_room(level, y, x, room, door_y, door_x):
rh, rw = len(room), len(room[0])
# maybe place Tile.DOOR here ?
level[door_y][door_x] = Tile.FLOOR
level[y][x] = Tile.FLOOR
for ry in range(rh):
for rx in range(rw):
if room[ry][rx] == Tile.FLOOR:
level[y-door_y+ry][y-door_x+rx] = Tile.FLOOR
level[y-door_y+ry][x-door_x+rx] = Tile.FLOOR
@staticmethod
def place_walls(level):
@ -146,9 +146,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, 0, 0, starting_room)
self.place_room(level, height//2, width//2, starting_room, 0, 0)
self.params["corridor_chance"] = mem
# find a starting position
sy, sx = randint(0, height-1), randint(0, width-1)
while level[sy][sx] != Tile.FLOOR:
@ -159,13 +159,13 @@ class Generator:
while tries < self.params["tries"] and rooms_built < self.params["max_rooms"]:
room, door_y, door_x, dy, dx = self.create_random_room()
positions = [i for i in range()]
positions = [i for i in range(height * width)]
shuffle(positions)
for pos in positions:
y, x = pos // width, pos % width
if self.room_fits(level, y, x, room, door_y, door_x, dy, dx):
self.place_room(level, y, x, door_y, door_x, room)
self.place_room(level, y, x, room, door_y, door_x)
# post-processing
self.place_walls(level)