diff --git a/squirrelbattle/mapgeneration/broguelike.py b/squirrelbattle/mapgeneration/broguelike.py index 143911c..b986b8f 100644 --- a/squirrelbattle/mapgeneration/broguelike.py +++ b/squirrelbattle/mapgeneration/broguelike.py @@ -89,18 +89,24 @@ class Generator: else: dx = -1 if random() < .5 else 1 - yxs = [i for i in range(len(room) * len(room[0]))] + rh, rw = len(room), len(room[0]) + yxs = [i for i in range(rh * rw)] shuffle(yxs) for pos in yxs: - y, x = pos // len(room[0]), pos % len(room[0]) + y, x = pos // rw, pos % rw if room[y][x] == Tile.EMPTY: - if room[y-dy][x-dx] == Tile.FLOOR: - build_here = True + # verify we are pointing away from a floor tile + if not(0 <= y-dy < rh and 0 <= x-dx < rw) or room[y-dy][x-dx] != Tile.FLOOR: + continue + # verify there's no other floor tile around us + for ny, nx in [[y+dy, x+dx], [y-dx, x-dy], [y+dx, x+dy]]: + if 0 <= ny < rh and 0 <= nx < rw and room[ny][nx] != Tile.EMPTY: + break + else: for i in range(l): if room[y+i*dy][x+i*dx] != Tile.EMPTY: - build_here = False break - if build_here: + else: for i in range(l): room[y+i*dy][x+i*dx] == Tile.FLOOR break @@ -147,6 +153,7 @@ class Generator: 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) + level[0][0] = Tile.EMPTY self.params["corridor_chance"] = mem # find a starting position