Particle-Klasse für animierte Partikel hinzufügen
This commit is contained in:
parent
bb9cdacae2
commit
18c392d822
2 changed files with 36 additions and 1 deletions
2
game.py
2
game.py
|
|
@ -40,7 +40,7 @@ class Game:
|
||||||
"player/jump": Animation(load_images("entities/player/jump")),
|
"player/jump": Animation(load_images("entities/player/jump")),
|
||||||
"player/slide": Animation(load_images("entities/player/slide")),
|
"player/slide": Animation(load_images("entities/player/slide")),
|
||||||
"player/wall_slide": Animation(load_images("entities/player/wall_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))
|
self.player: Player = Player(self, (50, 50), (8, 15))
|
||||||
|
|
||||||
|
|
|
||||||
35
scripts/particle.py
Normal file
35
scripts/particle.py
Normal 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,
|
||||||
|
))
|
||||||
Loading…
Reference in a new issue