Fix place_room and add missing argument
This commit is contained in:
parent
9c252a2bbc
commit
d362bdc949
|
@ -45,14 +45,14 @@ class Generator:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@staticmethod
|
@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])
|
rh, rw = len(room), len(room[0])
|
||||||
# maybe place Tile.DOOR here ?
|
# maybe place Tile.DOOR here ?
|
||||||
level[door_y][door_x] = Tile.FLOOR
|
level[y][x] = Tile.FLOOR
|
||||||
for ry in range(rh):
|
for ry in range(rh):
|
||||||
for rx in range(rw):
|
for rx in range(rw):
|
||||||
if room[ry][rx] == Tile.FLOOR:
|
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
|
@staticmethod
|
||||||
def place_walls(level):
|
def place_walls(level):
|
||||||
|
@ -146,9 +146,9 @@ class Generator:
|
||||||
# the starting room must have no corridor
|
# the starting room must have no corridor
|
||||||
mem, self.params["corridor_chance"] = self.params["corridor_chance"], 0
|
mem, self.params["corridor_chance"] = self.params["corridor_chance"], 0
|
||||||
starting_room, _, _, _, _ = self.create_random_room()
|
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
|
self.params["corridor_chance"] = mem
|
||||||
|
|
||||||
# find a starting position
|
# find a starting position
|
||||||
sy, sx = randint(0, height-1), randint(0, width-1)
|
sy, sx = randint(0, height-1), randint(0, width-1)
|
||||||
while level[sy][sx] != Tile.FLOOR:
|
while level[sy][sx] != Tile.FLOOR:
|
||||||
|
@ -159,13 +159,13 @@ class Generator:
|
||||||
while tries < self.params["tries"] and rooms_built < self.params["max_rooms"]:
|
while tries < self.params["tries"] and rooms_built < self.params["max_rooms"]:
|
||||||
|
|
||||||
room, door_y, door_x, dy, dx = self.create_random_room()
|
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)
|
shuffle(positions)
|
||||||
for pos in positions:
|
for pos in positions:
|
||||||
y, x = pos // width, pos % width
|
y, x = pos // width, pos % width
|
||||||
if self.room_fits(level, y, x, room, door_y, door_x, dy, dx):
|
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
|
# post-processing
|
||||||
self.place_walls(level)
|
self.place_walls(level)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue