comparison pytouhou/game/effect.py @ 190:dbe6b7b2d3fc

Fix a few things about particles.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 27 Oct 2011 15:09:42 -0700
parents 184196480f59
children 9f58e2a6e950
comparison
equal deleted inserted replaced
189:ba3297ab3bde 190:dbe6b7b2d3fc
38 if self._sprite._removed: 38 if self._sprite._removed:
39 self._sprite = None 39 self._sprite = None
40 40
41 41
42 class Particle(object): 42 class Particle(object):
43 def __init__(self, start_pos, index, anm_wrapper, size, end_pos): 43 def __init__(self, start_pos, index, anm_wrapper, size, amp, delay, game):
44 self._sprite = Sprite() 44 self._sprite = Sprite()
45 self._sprite.anm, self._sprite.texcoords = anm_wrapper.get_sprite(index) 45 self._sprite.anm, self._sprite.texcoords = anm_wrapper.get_sprite(index)
46 self._game = game
46 self._removed = False 47 self._removed = False
47 48
48 self.x, self.y = start_pos 49 self.x, self.y = start_pos
49 self.frame = 0 50 self.frame = 0
50 self._sprite.alpha = 128 51 self._sprite.alpha = 128
51 self._sprite.blendfunc = 1 52 self._sprite.blendfunc = 1
53 self._sprite.rescale = (size, size)
52 54
53 self.pos_interpolator = Interpolator(start_pos, 0, 55 self.pos_interpolator = None
56 self.scale_interpolator = None
57 self.rotations_interpolator = None
58
59 self.delay = delay
60 self.amp = amp
61
62
63 def set_end_pos(self, amp):
64 end_pos = (self.x + amp * self._game.prng.rand_double() - amp/2,
65 self.y + amp * self._game.prng.rand_double() - amp/2)
66
67 self.pos_interpolator = Interpolator((self.x, self.y), 0,
54 end_pos, 24, formula=(lambda x: 2. * x - x ** 2)) 68 end_pos, 24, formula=(lambda x: 2. * x - x ** 2))
55 self.scale_interpolator = Interpolator((size, size), 0, 69 self.scale_interpolator = Interpolator(self._sprite.rescale, 0,
56 (0., 0.), 24) 70 (0., 0.), 24)
57 self.rotations_interpolator = Interpolator((0., 0., 0.), 0, 71 self.rotations_interpolator = Interpolator(self._sprite.rotations_3d, 0,
58 (0., 0., 2*pi), 24) 72 (0., 0., 2*pi), 24)
59 self._sprite._changed = True
60 73
61 74
62 def update(self): 75 def update(self):
63 self.pos_interpolator.update(self.frame) 76 if (self.frame == 0 and not self.delay) or (self.frame == 1 and self.delay):
64 self.x, self.y = self.pos_interpolator.values 77 self.set_end_pos(self.amp)
65 78
66 self.scale_interpolator.update(self.frame) 79 if self.pos_interpolator:
67 self._sprite.rescale = self.scale_interpolator.values 80 self.pos_interpolator.update(self.frame)
81 self.x, self.y = self.pos_interpolator.values
68 82
69 self.rotations_interpolator.update(self.frame) 83 self.scale_interpolator.update(self.frame)
70 self._sprite.rotations_3d = self.rotations_interpolator.values 84 self._sprite.rescale = self.scale_interpolator.values
71 85
72 self._sprite._changed = True 86 self.rotations_interpolator.update(self.frame)
87 self._sprite.rotations_3d = self.rotations_interpolator.values
88
89 self._sprite._changed = True
73 90
74 if self.frame == 24: 91 if self.frame == 24:
75 self._removed = True 92 self._removed = True
76 93
77 self.frame += 1 94 self.frame += 1