2026-05-11 16:26:26 +00:00
|
|
|
import pygame
|
|
|
|
|
|
|
|
|
|
from scripts.animation import Animation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Particle:
|
2026-05-20 15:57:59 +00:00
|
|
|
def __init__(self, game, p_type: str, pos: tuple[float, float], velocity: list[float] = [0, 0], frame: int = 0):
|
2026-05-11 16:26:26 +00:00
|
|
|
self.game = game
|
2026-05-20 15:57:59 +00:00
|
|
|
self.type: str = p_type
|
|
|
|
|
self.pos: list[float] = list(pos)
|
|
|
|
|
self.velocity: list[float] = list(velocity)
|
|
|
|
|
self.animation: Animation = self.game.assets['particles/' + p_type].copy()
|
2026-05-11 16:26:26 +00:00
|
|
|
self.animation.frame = frame
|
|
|
|
|
|
|
|
|
|
def update(self) -> bool:
|
2026-05-20 15:57:59 +00:00
|
|
|
kill: bool = False
|
2026-05-11 16:26:26 +00:00
|
|
|
if self.animation.done:
|
|
|
|
|
kill = True
|
|
|
|
|
|
|
|
|
|
self.pos[0] += self.velocity[0]
|
|
|
|
|
self.pos[1] += self.velocity[1]
|
2026-05-20 15:57:59 +00:00
|
|
|
|
2026-05-11 16:26:26 +00:00
|
|
|
self.animation.update()
|
|
|
|
|
|
|
|
|
|
return kill
|
|
|
|
|
|
2026-05-20 15:57:59 +00:00
|
|
|
def render(self, surface: pygame.Surface, offset: tuple[float, float] = (0, 0)) -> None:
|
2026-05-11 16:26:26 +00:00
|
|
|
img = self.animation.img()
|
2026-05-20 15:57:59 +00:00
|
|
|
surface.blit(
|
|
|
|
|
img,
|
|
|
|
|
(
|
|
|
|
|
self.pos[0] - offset[0] - img.get_width() // 2,
|
|
|
|
|
self.pos[1] - offset[1] - img.get_height() // 2,
|
|
|
|
|
),
|
|
|
|
|
)
|