From 18c392d822b437c1c937f68967e8dc065a4615a0 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Mon, 11 May 2026 18:26:26 +0200 Subject: [PATCH] =?UTF-8?q?Particle-Klasse=20f=C3=BCr=20animierte=20Partik?= =?UTF-8?q?el=20hinzuf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.py | 2 +- scripts/particle.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 scripts/particle.py diff --git a/game.py b/game.py index d2306a2..92d6fa8 100644 --- a/game.py +++ b/game.py @@ -40,7 +40,7 @@ class Game: "player/jump": Animation(load_images("entities/player/jump")), "player/slide": Animation(load_images("entities/player/slide")), "player/wall_slide": Animation(load_images("entities/player/wall_slide")), - "particles/leaf": Animation(load_images("particles/leaf"), 20, False), + "particles/leaf": Animation(load_images("particles/leaf"), image_duration=20, loop=False), } self.player: Player = Player(self, (50, 50), (8, 15)) diff --git a/scripts/particle.py b/scripts/particle.py new file mode 100644 index 0000000..9ed40da --- /dev/null +++ b/scripts/particle.py @@ -0,0 +1,35 @@ +import pygame + +from scripts.animation import Animation + + +class Particle: + def __init__(self, game, p_type, pos: tuple, velocity=[0, 0], frame=0): + self.game = game + self.p_type = p_type + self.pos = list(pos) + self.velocity = list(velocity) + self.frame = frame + + self.animation: Animation = self.game.assets["particles/" + self.p_type].copy() + self.animation.frame = frame + + def update(self) -> bool: + + kill = 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)): + 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, + )) \ No newline at end of file