comparison pytouhou/game/effect.py @ 181:184196480f59

Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 23 Oct 2011 14:50:44 -0700
parents 35d850502d1f
children dbe6b7b2d3fc
comparison
equal deleted inserted replaced
180:5a1533677a9a 181:184196480f59
13 ## 13 ##
14 14
15 15
16 from pytouhou.game.sprite import Sprite 16 from pytouhou.game.sprite import Sprite
17 from pytouhou.vm.anmrunner import ANMRunner 17 from pytouhou.vm.anmrunner import ANMRunner
18 from pytouhou.utils.interpolator import Interpolator
19 from math import pi
18 20
19 21
20 22
21 class Effect(object): 23 class Effect(object):
22 def __init__(self, pos, index, anm_wrapper): 24 def __init__(self, pos, index, anm_wrapper):
25 self._anmrunner.run_frame() 27 self._anmrunner.run_frame()
26 self._removed = False 28 self._removed = False
27 29
28 self.x, self.y = pos 30 self.x, self.y = pos
29 31
32
30 def update(self): 33 def update(self):
31 if self._anmrunner and not self._anmrunner.run_frame(): 34 if self._anmrunner and not self._anmrunner.run_frame():
32 self._anmrunner = None 35 self._anmrunner = None
33 36
34 if self._sprite: 37 if self._sprite:
35 if self._sprite._removed: 38 if self._sprite._removed:
36 self._sprite = None 39 self._sprite = None
40
41
42 class Particle(object):
43 def __init__(self, start_pos, index, anm_wrapper, size, end_pos):
44 self._sprite = Sprite()
45 self._sprite.anm, self._sprite.texcoords = anm_wrapper.get_sprite(index)
46 self._removed = False
47
48 self.x, self.y = start_pos
49 self.frame = 0
50 self._sprite.alpha = 128
51 self._sprite.blendfunc = 1
52
53 self.pos_interpolator = Interpolator(start_pos, 0,
54 end_pos, 24, formula=(lambda x: 2. * x - x ** 2))
55 self.scale_interpolator = Interpolator((size, size), 0,
56 (0., 0.), 24)
57 self.rotations_interpolator = Interpolator((0., 0., 0.), 0,
58 (0., 0., 2*pi), 24)
59 self._sprite._changed = True
60
61
62 def update(self):
63 self.pos_interpolator.update(self.frame)
64 self.x, self.y = self.pos_interpolator.values
65
66 self.scale_interpolator.update(self.frame)
67 self._sprite.rescale = self.scale_interpolator.values
68
69 self.rotations_interpolator.update(self.frame)
70 self._sprite.rotations_3d = self.rotations_interpolator.values
71
72 self._sprite._changed = True
73
74 if self.frame == 24:
75 self._removed = True
76
77 self.frame += 1