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

35 lines
1 KiB
Python
Raw Permalink Normal View History

import pygame
from scripts.animation import Animation
class Particle:
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)
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
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,
),
)