Render rats inside internal tunnel passages
Previously Rat.draw() hid any rat whose center fell inside a tunnel. The clipping helper only handled single-entrance cells and returned None for internal passages/crossroads, causing rats to vanish entirely. Now internal tunnel cells (those with 0 or 2+ open sides) draw the rat normally so it remains visible while walking through the tunnel. Single-entrance cells keep the partial clip effect. Also fix the visible-ratio math for DOWN/RIGHT clipping: the old formulas subtracted cell_size from a local coordinate, producing zero or negative visibility.
This commit is contained in:
+3
-3
@@ -347,9 +347,9 @@ class Graphics:
|
||||
if below:
|
||||
if left:
|
||||
if right:
|
||||
# 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)
|
||||
# Internal tunnel passage: leave it empty so it uses
|
||||
# the background fill color and stays visually open.
|
||||
pass
|
||||
else:
|
||||
draw_cave(self.caves["RIGHT"], px, py, "RIGHT")
|
||||
else:
|
||||
|
||||
+13
-12
@@ -190,25 +190,26 @@ class Rat(Unit):
|
||||
|
||||
if self.game.map.in_bounds(cell_x, cell_y):
|
||||
if self.game.map.is_tunnel(cell_x, cell_y):
|
||||
if self._draw_partially_hidden_in_tunnel(image, image_size, center_x, center_y, cell_x, cell_y):
|
||||
direction = self._get_tunnel_entrance_direction(cell_x, cell_y)
|
||||
if direction is not None:
|
||||
# Single entrance/exit: clip the sprite to simulate popping in/out.
|
||||
if self._draw_partially_hidden_in_tunnel(image, image_size, center_x, center_y, cell_x, cell_y, direction):
|
||||
return
|
||||
return
|
||||
# Internal tunnel passage or crossroad: draw the rat normally
|
||||
# so it stays visible while walking through the tunnel.
|
||||
self.game.render_engine.draw_image(self.render_x, self.render_y, image, anchor="nw", tag="unit")
|
||||
return
|
||||
if not self.game.map.is_empty(cell_x, cell_y):
|
||||
return
|
||||
|
||||
# Use pre-calculated positions
|
||||
self.game.render_engine.draw_image(self.render_x, self.render_y, image, anchor="nw", tag="unit")
|
||||
|
||||
def _draw_partially_hidden_in_tunnel(self, image, image_size, center_x, center_y, cell_x, cell_y):
|
||||
direction = self._get_tunnel_entrance_direction(cell_x, cell_y)
|
||||
if direction is None:
|
||||
return False
|
||||
|
||||
# Convert the sprite center to tunnel-local coordinates. The visible slice
|
||||
# is derived from how far that center has progressed across the tunnel cell.
|
||||
local_x = center_x - cell_x * self.game.cell_size
|
||||
local_y = center_y - cell_y * self.game.cell_size
|
||||
def _draw_partially_hidden_in_tunnel(self, image, image_size, center_x, center_y, cell_x, cell_y, direction):
|
||||
cell_size = self.game.cell_size
|
||||
local_x = center_x - cell_x * cell_size
|
||||
local_y = center_y - cell_y * cell_size
|
||||
|
||||
def draw_slice(source_x, source_y, width, height, draw_x=None, draw_y=None):
|
||||
if width <= 0 or height <= 0:
|
||||
@@ -231,7 +232,7 @@ class Rat(Unit):
|
||||
return draw_slice(0, 0, image_size[0], visible_height)
|
||||
|
||||
if direction == "DOWN":
|
||||
visible_ratio = max(0.0, min(1.0, (local_y - cell_size) / cell_size))
|
||||
visible_ratio = max(0.0, min(1.0, (local_y - 0) / cell_size))
|
||||
visible_height = int(round(image_size[1] * visible_ratio))
|
||||
source_y = image_size[1] - visible_height
|
||||
draw_y = self.render_y + source_y
|
||||
@@ -243,7 +244,7 @@ class Rat(Unit):
|
||||
return draw_slice(0, 0, visible_width, image_size[1])
|
||||
|
||||
if direction == "RIGHT":
|
||||
visible_ratio = max(0.0, min(1.0, (local_x - cell_size) / cell_size))
|
||||
visible_ratio = max(0.0, min(1.0, (local_x - 0) / cell_size))
|
||||
visible_width = int(round(image_size[0] * visible_ratio))
|
||||
source_x = image_size[0] - visible_width
|
||||
draw_x = self.render_x + source_x
|
||||
|
||||
Reference in New Issue
Block a user