2f8e3e8b28
- Move gas poisoning from Gas.move() to Gas.collisions() so all rats are registered in the collision system before the poison query runs. - Shrink gas and explosion bboxes so rats must be well inside the tile to be poisoned/killed. - Use AABB overlap instead of partial_move threshold for gas poisoning. - Draw mobile units first, then top-layer effects (gas, mines, bombs, explosions) so rats appear under the gas. - Add draw_on_top hint to Unit base class and top-layer units.
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
from .unit import Unit, UnitType
|
|
from engine.collision_system import CollisionLayer
|
|
import random
|
|
import uuid
|
|
|
|
# Costanti - Points disappear after ~1.5 seconds (90 frames at 60 FPS)
|
|
AGE_THRESHOLD = 90
|
|
|
|
|
|
class Point(Unit):
|
|
"""
|
|
Represents a collectible point in the game.
|
|
Appears when a rat dies and can be collected by the player.
|
|
"""
|
|
draw_on_top = True
|
|
draw_last = True
|
|
|
|
def __init__(self, game, position=(0,0), id=None, value=10):
|
|
super().__init__(game, position, id, collision_layer=CollisionLayer.POINT, unit_type=UnitType.POINT)
|
|
self.value = value
|
|
self.speed = 1 # Points don't move but need speed for draw timing
|
|
|
|
def move(self):
|
|
self.age += self.speed
|
|
if self.age == AGE_THRESHOLD:
|
|
self.die()
|
|
|
|
def collisions(self):
|
|
pass
|
|
|
|
def die(self, unit=None, score=None):
|
|
"""Handle point cleanup. Points just disappear when they expire."""
|
|
target_unit = unit if unit else self
|
|
# Use base class cleanup
|
|
super().die()
|
|
|
|
|
|
def draw(self):
|
|
image = self.game.graphics.assets[f"BMP_BONUS_{self.value}"]
|
|
image_size = self.game.render_engine.get_image_size(image)
|
|
self.rat_image = image
|
|
partial_x, partial_y = 0, 0
|
|
|
|
x_pos = self.position_before[0] * self.game.cell_size + (self.game.cell_size - image_size[0]) // 2 + partial_x
|
|
y_pos = self.position_before[1] * self.game.cell_size + (self.game.cell_size - image_size[1]) // 2 + partial_y
|
|
|
|
self.game.render_engine.draw_image(x_pos, y_pos, image, anchor="nw", tag="unit")
|