Compare commits

...

3 commits

Author SHA1 Message Date
Benjamin
18c392d822 Particle-Klasse für animierte Partikel hinzufügen 2026-05-11 18:26:26 +02:00
Benjamin
bb9cdacae2 Animation-Asset für fallende Blätter laden 2026-05-11 18:10:42 +02:00
Benjamin
58aea455e9 Vor Partikeln Stand 2026-05-11 18:06:31 +02:00
3 changed files with 39 additions and 2 deletions

View file

@ -40,14 +40,17 @@ 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"), image_duration=20, loop=False),
}
self.player: Player = Player(self, (50, 50), (8, 15))
self.tilemap: Tilemap = Tilemap(self, 16)
try:
self.tilemap.load("map.json")
except FileNotFoundError:
pass
self.clouds: Clouds = Clouds(self.assets["clouds"], count=16)
self.isJumping: bool = False
self.scroll: list[float] = [0, 0]
@ -109,5 +112,4 @@ class Game:
game = Game()
game.run()

View file

@ -10,7 +10,7 @@ class Tile:
def grid_key(self) -> str:
"""Erzeugt den String-Key für die Tilemap."""
return f"{self.pos[0]};{self.pos[1]}"
def to_dict(self) -> dict:
"""Konvertiert zurück in ein Dict (für JSON-Speicherung)."""
return {

35
scripts/particle.py Normal file
View file

@ -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,
))