Use wall-only neighbor checks for wall border rendering
Previously regenerate_background() used occupied() (wall or tunnel) to choose wall border/corner tiles. This caused walls adjacent to tunnels to render with inner corners as if the tunnel were solid ground. Now wall border logic uses is_wall() so only actual wall neighbors influence the shape. Tunnel neighbor checks for flower-suppression are kept explicit.
This commit is contained in:
+50
-38
@@ -222,6 +222,7 @@ class Graphics:
|
||||
|
||||
def draw(surface, x, y):
|
||||
texture_tiles.append((surface, x, y))
|
||||
return True # allow callers to count successful draws
|
||||
|
||||
def draw_cave(surface, x, y, direction):
|
||||
self.cave_foreground_tiles.append((x // self.game.cell_size, y // self.game.cell_size, direction, surface, x, y))
|
||||
@@ -229,6 +230,9 @@ class Graphics:
|
||||
def occupied(x, y):
|
||||
return self.game.map.in_bounds(x, y) and self.game.map.get_cell(x, y) != maze.MAP_EMPTY
|
||||
|
||||
def is_wall(x, y):
|
||||
return self.game.map.in_bounds(x, y) and self.game.map.get_cell(x, y) == maze.MAP_WALL
|
||||
|
||||
def is_tunnel(x, y):
|
||||
return self.game.map.in_bounds(x, y) and self.game.map.get_cell(x, y) == maze.MAP_TUNNEL
|
||||
|
||||
@@ -252,26 +256,33 @@ class Graphics:
|
||||
continue
|
||||
|
||||
if cell == maze.MAP_WALL:
|
||||
if x == 0 or y == 0 or x == self.game.map.width - 1 or y == self.game.map.height - 1:
|
||||
draw(random_wall(), px, py)
|
||||
wall_tiles_drawn = 0
|
||||
|
||||
if x > 0 and y > 0 and (not occupied(x - 1, y - 1) or not occupied(x, y - 1) or not occupied(x - 1, y)):
|
||||
north = occupied(x, y - 1)
|
||||
west = occupied(x - 1, y)
|
||||
def draw_wall(surface, x, y):
|
||||
nonlocal wall_tiles_drawn
|
||||
draw(surface, x, y)
|
||||
wall_tiles_drawn += 1
|
||||
|
||||
if x == 0 or y == 0 or x == self.game.map.width - 1 or y == self.game.map.height - 1:
|
||||
draw_wall(random_wall(), px, py)
|
||||
|
||||
if x > 0 and y > 0 and (not is_wall(x - 1, y - 1) or not is_wall(x, y - 1) or not is_wall(x - 1, y)):
|
||||
north = is_wall(x, y - 1)
|
||||
west = is_wall(x - 1, y)
|
||||
if north or west:
|
||||
if north and west:
|
||||
draw(self.inner_corners["WN"], px, py)
|
||||
draw_wall(self.inner_corners["WN"], px, py)
|
||||
elif north and not west:
|
||||
draw(self.edges["W"], px, py)
|
||||
draw_wall(self.edges["W"], px, py)
|
||||
else:
|
||||
draw(self.edges["N"], px, py)
|
||||
draw_wall(self.edges["N"], px, py)
|
||||
else:
|
||||
draw(self.corners["NW"], px, py)
|
||||
draw_wall(self.corners["NW"], px, py)
|
||||
|
||||
if y < self.game.map.height - 1 and x < self.game.map.width - 1:
|
||||
south = occupied(x, y + 1)
|
||||
east = occupied(x + 1, y)
|
||||
southeast = occupied(x + 1, y + 1)
|
||||
south = is_wall(x, y + 1)
|
||||
east = is_wall(x + 1, y)
|
||||
southeast = is_wall(x + 1, y + 1)
|
||||
if southeast and south and east:
|
||||
if (
|
||||
random.randrange(10) != 0
|
||||
@@ -283,44 +294,48 @@ class Graphics:
|
||||
or is_tunnel(x, y + 1)
|
||||
or is_tunnel(x + 1, y + 1)
|
||||
):
|
||||
draw(random_wall(), px + half_cell, py + half_cell)
|
||||
draw_wall(random_wall(), px + half_cell, py + half_cell)
|
||||
else:
|
||||
draw(random_flower(), px + half_cell, py + half_cell)
|
||||
draw_wall(random_flower(), px + half_cell, py + half_cell)
|
||||
elif south or east:
|
||||
if south and east:
|
||||
draw(self.inner_corners["ES"], px + half_cell, py + half_cell)
|
||||
draw_wall(self.inner_corners["ES"], px + half_cell, py + half_cell)
|
||||
elif south and not east:
|
||||
draw(self.edges["E"], px + half_cell, py + half_cell)
|
||||
draw_wall(self.edges["E"], px + half_cell, py + half_cell)
|
||||
else:
|
||||
draw(self.edges["S"], px + half_cell, py + half_cell)
|
||||
draw_wall(self.edges["S"], px + half_cell, py + half_cell)
|
||||
else:
|
||||
draw(self.corners["SE"], px + half_cell, py + half_cell)
|
||||
draw_wall(self.corners["SE"], px + half_cell, py + half_cell)
|
||||
|
||||
if y > 0 and x < self.game.map.width - 1 and (not occupied(x + 1, y - 1) or not occupied(x, y - 1) or not occupied(x + 1, y)):
|
||||
north = occupied(x, y - 1)
|
||||
east = occupied(x + 1, y)
|
||||
if y > 0 and x < self.game.map.width - 1 and (not is_wall(x + 1, y - 1) or not is_wall(x, y - 1) or not is_wall(x + 1, y)):
|
||||
north = is_wall(x, y - 1)
|
||||
east = is_wall(x + 1, y)
|
||||
if north or east:
|
||||
if north and east:
|
||||
draw(self.inner_corners["EN"], px + half_cell, py)
|
||||
draw_wall(self.inner_corners["EN"], px + half_cell, py)
|
||||
elif north and not east:
|
||||
draw(self.edges["E"], px + half_cell, py)
|
||||
draw_wall(self.edges["E"], px + half_cell, py)
|
||||
else:
|
||||
draw(self.edges["N"], px + half_cell, py)
|
||||
draw_wall(self.edges["N"], px + half_cell, py)
|
||||
else:
|
||||
draw(self.corners["NE"], px + half_cell, py)
|
||||
draw_wall(self.corners["NE"], px + half_cell, py)
|
||||
|
||||
if y < self.game.map.height - 1 and x > 0 and (not occupied(x - 1, y + 1) or not occupied(x, y + 1) or not occupied(x - 1, y)):
|
||||
south = occupied(x, y + 1)
|
||||
west = occupied(x - 1, y)
|
||||
if y < self.game.map.height - 1 and x > 0 and (not is_wall(x - 1, y + 1) or not is_wall(x, y + 1) or not is_wall(x - 1, y)):
|
||||
south = is_wall(x, y + 1)
|
||||
west = is_wall(x - 1, y)
|
||||
if south or west:
|
||||
if south and west:
|
||||
draw(self.inner_corners["WS"], px, py + half_cell)
|
||||
draw_wall(self.inner_corners["WS"], px, py + half_cell)
|
||||
elif south and not west:
|
||||
draw(self.edges["W"], px, py + half_cell)
|
||||
draw_wall(self.edges["W"], px, py + half_cell)
|
||||
else:
|
||||
draw(self.edges["S"], px, py + half_cell)
|
||||
draw_wall(self.edges["S"], px, py + half_cell)
|
||||
else:
|
||||
draw(self.corners["SW"], px, py + half_cell)
|
||||
draw_wall(self.corners["SW"], px, py + half_cell)
|
||||
|
||||
# Fallback: isolated/surrounded wall cells must not show background color
|
||||
if wall_tiles_drawn == 0:
|
||||
draw(random_wall(), px, py)
|
||||
|
||||
elif cell == maze.MAP_TUNNEL:
|
||||
above = occupied(x, y - 1)
|
||||
@@ -332,19 +347,16 @@ class Graphics:
|
||||
if below:
|
||||
if left:
|
||||
if right:
|
||||
if random.randrange(10) != 0:
|
||||
draw_cave(random_wall_texture(), px + half_cell, py + half_cell, None)
|
||||
else:
|
||||
draw_cave(random_flower_texture(), px + half_cell, py + half_cell, None)
|
||||
# Internal tunnel passage: draw a neutral floor cap
|
||||
# so the grey background does not show through.
|
||||
draw_cave(random_wall_texture(), px + half_cell, py + half_cell, None)
|
||||
else:
|
||||
draw_cave(self.caves["RIGHT"], px, py, "RIGHT")
|
||||
else:
|
||||
draw(self.grasses[0], px + half_cell, py + half_cell)
|
||||
draw_cave(self.caves["LEFT"], px, py, "LEFT")
|
||||
else:
|
||||
draw_cave(self.caves["DOWN"], px, py, "DOWN")
|
||||
else:
|
||||
draw(self.grasses[0], px + half_cell, py + half_cell)
|
||||
draw_cave(self.caves["UP"], px, py, "UP")
|
||||
|
||||
# Blood stains now handled separately as overlay layer
|
||||
|
||||
Reference in New Issue
Block a user