Add new PNG images for clean and preview outputs
- Added `image_clean.png` to the output directory for the clean image representation. - Added `image_clean_preview.png` for the preview of the clean image. - Introduced `image_svg_clean.png` for the SVG clean image representation.
This commit is contained in:
@@ -123,6 +123,9 @@ class Explosion(Bomb):
|
||||
self.die()
|
||||
|
||||
def draw(self):
|
||||
if self.game.map.is_tunnel(*self.position):
|
||||
return
|
||||
|
||||
image = self.game.assets["BMP_EXPLOSION"]
|
||||
image_size = self.game.render_engine.get_image_size(image)
|
||||
partial_x, partial_y = 0, 0
|
||||
|
||||
+130
-6
@@ -40,15 +40,27 @@ class Rat(Unit):
|
||||
def find_next_position(self):
|
||||
neighbors = []
|
||||
x, y = self.position
|
||||
while not neighbors:
|
||||
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
|
||||
nx, ny = x + dx, y + dy
|
||||
if not self.game.map.in_bounds(nx, ny):
|
||||
continue
|
||||
if self.game.map.is_empty(nx, ny) and (nx, ny) != self.position_before:
|
||||
neighbors.append((nx, ny))
|
||||
|
||||
if not neighbors:
|
||||
for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
|
||||
nx, ny = x + dx, y + dy
|
||||
if not self.game.map.matrix[ny][nx] and not (nx, ny) == self.position_before:
|
||||
if not self.game.map.in_bounds(nx, ny):
|
||||
continue
|
||||
if self.game.map.is_empty(nx, ny):
|
||||
neighbors.append((nx, ny))
|
||||
if not neighbors:
|
||||
self.position_before = self.position
|
||||
self.position_before = self.position
|
||||
return neighbors[random.randint(0, len(neighbors) - 1)]
|
||||
|
||||
if not neighbors:
|
||||
print(f"[flow] rat fallback: no empty neighbors from position={self.position}", flush=True)
|
||||
return self.position
|
||||
|
||||
self.position_before = self.position
|
||||
return random.choice(neighbors)
|
||||
|
||||
def choked(self):
|
||||
self.game.render_engine.play_sound("CHOKE.WAV")
|
||||
@@ -152,6 +164,7 @@ class Rat(Unit):
|
||||
|
||||
# Rat-specific behavior: spawn points
|
||||
if score not in [None, 0]:
|
||||
self.game.add_point(score)
|
||||
self.game.spawn_unit(Point, death_position, value=score)
|
||||
|
||||
# Add blood stain directly to background
|
||||
@@ -161,15 +174,126 @@ class Rat(Unit):
|
||||
"""Optimized draw using pre-calculated positions from move()"""
|
||||
sex = self.sex if self.age > AGE_THRESHOLD else "BABY"
|
||||
image = self.game.rat_assets_textures[sex][self.direction]
|
||||
image_size = self.game.rat_image_sizes[sex][self.direction]
|
||||
|
||||
# Calculate render position if not yet set (first frame)
|
||||
if not hasattr(self, 'render_x'):
|
||||
self._calculate_render_position()
|
||||
|
||||
# Match the original game: the visibility test uses the rat's center point,
|
||||
# not the sprite's top-left corner.
|
||||
center_x = int(self.render_x + image_size[0] / 2)
|
||||
center_y = int(self.render_y + image_size[1] / 2)
|
||||
cell_x = center_x // self.game.cell_size
|
||||
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._draw_partially_hidden_in_tunnel(image, image_size, center_x, center_y, cell_x, cell_y):
|
||||
return
|
||||
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")
|
||||
# bbox already updated in _update_render_position()
|
||||
#self.game.render_engine.draw_rectangle(self.bbox[0], self.bbox[1], self.bbox[2] - self.bbox[0], self.bbox[3] - self.bbox[1], "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
|
||||
|
||||
local_x = center_x - cell_x * self.game.cell_size
|
||||
local_y = center_y - cell_y * self.game.cell_size
|
||||
half_cell = self.game.cell_size / 2
|
||||
|
||||
if direction == "UP":
|
||||
visible_ratio = max(0.0, min(1.0, (half_cell - local_y) / half_cell))
|
||||
visible_height = int(round(image_size[1] * visible_ratio))
|
||||
if visible_height <= 0:
|
||||
return False
|
||||
self.game.render_engine.draw_image(
|
||||
self.render_x,
|
||||
self.render_y,
|
||||
image,
|
||||
anchor="nw",
|
||||
tag="unit",
|
||||
source_rect=(0, 0, image_size[0], visible_height),
|
||||
dest_size=(image_size[0], visible_height),
|
||||
)
|
||||
return True
|
||||
|
||||
if direction == "DOWN":
|
||||
visible_ratio = max(0.0, min(1.0, (local_y - half_cell) / half_cell))
|
||||
visible_height = int(round(image_size[1] * visible_ratio))
|
||||
if visible_height <= 0:
|
||||
return False
|
||||
source_y = image_size[1] - visible_height
|
||||
draw_y = self.render_y + source_y
|
||||
self.game.render_engine.draw_image(
|
||||
self.render_x,
|
||||
draw_y,
|
||||
image,
|
||||
anchor="nw",
|
||||
tag="unit",
|
||||
source_rect=(0, source_y, image_size[0], visible_height),
|
||||
dest_size=(image_size[0], visible_height),
|
||||
)
|
||||
return True
|
||||
|
||||
if direction == "LEFT":
|
||||
visible_ratio = max(0.0, min(1.0, (half_cell - local_x) / half_cell))
|
||||
visible_width = int(round(image_size[0] * visible_ratio))
|
||||
if visible_width <= 0:
|
||||
return False
|
||||
self.game.render_engine.draw_image(
|
||||
self.render_x,
|
||||
self.render_y,
|
||||
image,
|
||||
anchor="nw",
|
||||
tag="unit",
|
||||
source_rect=(0, 0, visible_width, image_size[1]),
|
||||
dest_size=(visible_width, image_size[1]),
|
||||
)
|
||||
return True
|
||||
|
||||
visible_ratio = max(0.0, min(1.0, (local_x - half_cell) / half_cell))
|
||||
visible_width = int(round(image_size[0] * visible_ratio))
|
||||
if visible_width <= 0:
|
||||
return False
|
||||
source_x = image_size[0] - visible_width
|
||||
draw_x = self.render_x + source_x
|
||||
self.game.render_engine.draw_image(
|
||||
draw_x,
|
||||
self.render_y,
|
||||
image,
|
||||
anchor="nw",
|
||||
tag="unit",
|
||||
source_rect=(source_x, 0, visible_width, image_size[1]),
|
||||
dest_size=(visible_width, image_size[1]),
|
||||
)
|
||||
return True
|
||||
|
||||
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)"""
|
||||
|
||||
Reference in New Issue
Block a user