forked from ayte/PinmikPanik
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
from gamedata.objects.base import BaseObject
|
|
|
|
class Particle(BaseObject):
|
|
|
|
def __init__(self,game,sprites,posx,posy,velx=0,vely=0,modvelx=0,modvely=0,flipx=False,flipy=False,fps=15):
|
|
|
|
super().__init__(posx,posy,game)
|
|
self.vel = [velx,vely]
|
|
self.mod = [modvelx,modvely]
|
|
self.timer = game.lib.Timer(1/fps) # Les particules s'animent en 15 FPS par défaut
|
|
|
|
self.sprites = []
|
|
self.offsets = []
|
|
for i in sprites:
|
|
self.sprites.append(game.pygame.transform.flip(i,flipx,flipy))
|
|
w,h = i.get_size()
|
|
self.offsets.append([w/2,h/2])
|
|
|
|
self.alpha = 1
|
|
|
|
def step(self):
|
|
|
|
game = self.game
|
|
|
|
for j in range(2):
|
|
self.rect[j]+=self.vel[j]*game.dt*60
|
|
self.vel[j]+=self.mod[j]*game.dt*60
|
|
|
|
self.timer.tick(game.dt)
|
|
if self.timer.getloops()>=len(self.sprites): # Je me supprimme une fois l'animation finie
|
|
game.gameloop.delid(self.id)
|
|
|
|
self.alpha = max(1-(((self.timer.getloops()+1-self.timer.getratio())/len(self.sprites)))**3,0)
|
|
|
|
|
|
def draw(self):
|
|
|
|
game = self.game
|
|
|
|
spriteindex = self.timer.getloops()
|
|
posx,posy = self.rect[:2]
|
|
offx,offy = self.offsets[spriteindex]
|
|
pos = posx-offx-game.globals["camerax"],posy-offy-game.globals["cameray"]
|
|
self.sprites[spriteindex].set_alpha(self.alpha*255)
|
|
game.window.blit(self.sprites[spriteindex],pos)
|
|
self.sprites[spriteindex].set_alpha(255)
|