Ninja-Jump-and-run/scripts/particle.py

45 lines
1.1 KiB
Python
Raw Normal View History

import pygame
from scripts.animation import Animation
class Particle:
2026-06-12 14:43:28 +00:00
def __init__(
self,
game,
p_type: str,
pos: tuple[float, float],
velocity: list[float] = [0, 0],
frame: int = 0,
):
self.game = game
self.type: str = p_type
self.pos: list[float] = list(pos)
self.velocity: list[float] = list(velocity)
2026-06-12 14:43:28 +00:00
self.animation: Animation = self.game.assets["particles/" + p_type].copy()
self.animation.frame = frame
def update(self) -> bool:
kill: bool = False
if self.animation.done:
kill = True
self.pos[0] += self.velocity[0]
self.pos[1] += self.velocity[1]
self.animation.update()
return kill
2026-06-12 14:43:28 +00:00
def render(
self, surface: pygame.Surface, offset: tuple[float, float] = (0, 0)
) -> None:
img = self.animation.img()
surface.blit(
img,
(
self.pos[0] - offset[0] - img.get_width() // 2,
self.pos[1] - offset[1] - img.get_height() // 2,
),
2026-06-12 14:43:28 +00:00
)