Draw rat normally at tunnel entrances
Rats are now drawn fully (single animation frame) regardless of whether they are on an open cell, a tunnel entrance, or an internal tunnel passage. The only case where the rat is not drawn is when its center is inside a wall (non-empty, non-tunnel cell). Removed the now-unused _get_tunnel_entrance_direction helper.
This commit is contained in:
+4
-31
@@ -193,43 +193,16 @@ class Rat(Unit):
|
||||
cell_y = center_y // self.game.cell_size
|
||||
|
||||
if self.game.map.in_bounds(cell_x, cell_y):
|
||||
if self.game.map.is_tunnel(cell_x, cell_y):
|
||||
if self._get_tunnel_entrance_direction(cell_x, cell_y) is not None:
|
||||
# Single entrance/exit: the rat is entering/leaving the tunnel.
|
||||
# Don't draw it; it disappears into the tunnel.
|
||||
return
|
||||
# Internal tunnel passage or crossroad: draw the rat normally
|
||||
# so it stays visible while walking through the tunnel.
|
||||
frame = min(3, int(self.partial_move * 4))
|
||||
source_rect = (frame * image_size[0], 0, image_size[0], image_size[1])
|
||||
self.game.render_engine.draw_image(self.render_x, self.render_y, image, anchor="nw", tag="unit", source_rect=source_rect)
|
||||
return
|
||||
if not self.game.map.is_empty(cell_x, cell_y):
|
||||
if not self.game.map.is_tunnel(cell_x, cell_y) and not self.game.map.is_empty(cell_x, cell_y):
|
||||
# Inside a wall (or otherwise non-visible cell): don't draw the rat.
|
||||
return
|
||||
|
||||
# Draw the rat (single animation frame). Applies to open cells, tunnel
|
||||
# entrances, and internal tunnel passages alike.
|
||||
frame = min(3, int(self.partial_move * 4))
|
||||
source_rect = (frame * image_size[0], 0, image_size[0], image_size[1])
|
||||
self.game.render_engine.draw_image(self.render_x, self.render_y, image, anchor="nw", tag="unit", source_rect=source_rect)
|
||||
|
||||
def _get_tunnel_entrance_direction(self, cell_x, cell_y):
|
||||
directions = [
|
||||
("UP", 0, -1),
|
||||
("DOWN", 0, 1),
|
||||
("LEFT", -1, 0),
|
||||
("RIGHT", 1, 0),
|
||||
]
|
||||
|
||||
empty_neighbors = []
|
||||
for direction, dx, dy in directions:
|
||||
neighbor_x = cell_x + dx
|
||||
neighbor_y = cell_y + dy
|
||||
if self.game.map.in_bounds(neighbor_x, neighbor_y) and self.game.map.is_empty(neighbor_x, neighbor_y):
|
||||
empty_neighbors.append(direction)
|
||||
|
||||
if len(empty_neighbors) != 1:
|
||||
return None
|
||||
return empty_neighbors[0]
|
||||
|
||||
def _calculate_render_position(self):
|
||||
"""Calculate render position and bbox (used when render_x not yet set)"""
|
||||
sex = self.sex if self.age > AGE_THRESHOLD else "BABY"
|
||||
|
||||
Reference in New Issue
Block a user