Remove _draw_partially_hidden_in_tunnel clipping
The clipping logic that sliced the rat sprite when entering/leaving a single-entrance tunnel produced a jarring half-rat visual. Removed it entirely: a rat on a single-entrance tunnel cell is now simply not drawn (it disappears into the tunnel) instead of being partially clipped. Internal tunnel passages are unchanged and still render the rat normally.
This commit is contained in:
+3
-54
@@ -194,11 +194,9 @@ class Rat(Unit):
|
||||
|
||||
if self.game.map.in_bounds(cell_x, cell_y):
|
||||
if self.game.map.is_tunnel(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
|
||||
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.
|
||||
@@ -213,55 +211,6 @@ class Rat(Unit):
|
||||
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 _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:
|
||||
return False
|
||||
|
||||
frame = min(3, int(self.partial_move * 4))
|
||||
actual_source_x = source_x + (frame * image_size[0])
|
||||
|
||||
self.game.render_engine.draw_image(
|
||||
self.render_x if draw_x is None else draw_x,
|
||||
self.render_y if draw_y is None else draw_y,
|
||||
image,
|
||||
anchor="nw",
|
||||
tag="unit",
|
||||
source_rect=(actual_source_x, source_y, width, height),
|
||||
dest_size=(width, height),
|
||||
)
|
||||
return True
|
||||
|
||||
if direction == "UP":
|
||||
visible_ratio = max(0.0, min(1.0, (cell_size - local_y) / cell_size))
|
||||
visible_height = int(round(image_size[1] * visible_ratio))
|
||||
return draw_slice(0, 0, image_size[0], visible_height)
|
||||
|
||||
if direction == "DOWN":
|
||||
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
|
||||
return draw_slice(0, source_y, image_size[0], visible_height, draw_y=draw_y)
|
||||
|
||||
if direction == "LEFT":
|
||||
visible_ratio = max(0.0, min(1.0, (cell_size - local_x) / cell_size))
|
||||
visible_width = int(round(image_size[0] * visible_ratio))
|
||||
return draw_slice(0, 0, visible_width, image_size[1])
|
||||
|
||||
if direction == "RIGHT":
|
||||
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
|
||||
return draw_slice(source_x, 0, visible_width, image_size[1], draw_x=draw_x)
|
||||
|
||||
return False
|
||||
|
||||
def _get_tunnel_entrance_direction(self, cell_x, cell_y):
|
||||
directions = [
|
||||
("UP", 0, -1),
|
||||
|
||||
Reference in New Issue
Block a user