Mercurial > touhou
comparison pytouhou/game/effect.py @ 304:f3099ebf4f61
Update attribute names to reflect the actual interface.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Tue, 13 Mar 2012 18:38:14 +0100 |
parents | 9f58e2a6e950 |
children | 56523a16db1d |
comparison
equal
deleted
inserted
replaced
303:647bde10353d | 304:f3099ebf4f61 |
---|---|
20 | 20 |
21 | 21 |
22 | 22 |
23 class Effect(object): | 23 class Effect(object): |
24 def __init__(self, pos, index, anm_wrapper): | 24 def __init__(self, pos, index, anm_wrapper): |
25 self._sprite = Sprite() | 25 self.sprite = Sprite() |
26 self._anmrunner = ANMRunner(anm_wrapper, index, self._sprite) | 26 self.anmrunner = ANMRunner(anm_wrapper, index, self.sprite) |
27 self._anmrunner.run_frame() | 27 self.anmrunner.run_frame() |
28 self._removed = False | 28 self.removed = False |
29 | 29 |
30 self.x, self.y = pos | 30 self.x, self.y = pos |
31 | 31 |
32 | 32 |
33 def update(self): | 33 def update(self): |
34 if self._anmrunner and not self._anmrunner.run_frame(): | 34 if self.anmrunner and not self.anmrunner.run_frame(): |
35 self._anmrunner = None | 35 self.anmrunner = None |
36 | 36 |
37 if self._sprite: | 37 if self.sprite: |
38 if self._sprite._removed: | 38 if self.sprite.removed: |
39 self._sprite = None | 39 self.sprite = None |
40 | |
40 | 41 |
41 | 42 |
42 class Particle(object): | 43 class Particle(object): |
43 def __init__(self, start_pos, index, anm_wrapper, size, amp, game): | 44 def __init__(self, start_pos, index, anm_wrapper, size, amp, game): |
44 self._sprite = Sprite() | |
45 self._sprite.anm, self._sprite.texcoords = anm_wrapper.get_sprite(index) | |
46 self._game = game | 45 self._game = game |
47 self._removed = False | 46 |
47 self.sprite = Sprite() | |
48 self.sprite.anm, self.sprite.texcoords = anm_wrapper.get_sprite(index) | |
49 self.removed = False | |
48 | 50 |
49 self.x, self.y = start_pos | 51 self.x, self.y = start_pos |
50 self.frame = 0 | 52 self.frame = 0 |
51 self._sprite.alpha = 128 | 53 self.sprite.alpha = 128 |
52 self._sprite.blendfunc = 1 | 54 self.sprite.blendfunc = 1 |
53 self._sprite.rescale = (size, size) | 55 self.sprite.rescale = (size, size) |
54 | 56 |
55 self.pos_interpolator = None | 57 self.pos_interpolator = None |
56 self.scale_interpolator = None | 58 self.scale_interpolator = None |
57 self.rotations_interpolator = None | 59 self.rotations_interpolator = None |
58 | 60 |
63 end_pos = (self.x + amp * self._game.prng.rand_double() - amp/2, | 65 end_pos = (self.x + amp * self._game.prng.rand_double() - amp/2, |
64 self.y + amp * self._game.prng.rand_double() - amp/2) | 66 self.y + amp * self._game.prng.rand_double() - amp/2) |
65 | 67 |
66 self.pos_interpolator = Interpolator((self.x, self.y), 0, | 68 self.pos_interpolator = Interpolator((self.x, self.y), 0, |
67 end_pos, 24, formula=(lambda x: 2. * x - x ** 2)) | 69 end_pos, 24, formula=(lambda x: 2. * x - x ** 2)) |
68 self.scale_interpolator = Interpolator(self._sprite.rescale, 0, | 70 self.scale_interpolator = Interpolator(self.sprite.rescale, 0, |
69 (0., 0.), 24) | 71 (0., 0.), 24) |
70 self.rotations_interpolator = Interpolator(self._sprite.rotations_3d, 0, | 72 self.rotations_interpolator = Interpolator(self.sprite.rotations_3d, 0, |
71 (0., 0., 2*pi), 24) | 73 (0., 0., 2*pi), 24) |
72 | 74 |
73 | 75 |
74 def update(self): | 76 def update(self): |
75 if self.frame == 0: | 77 if self.frame == 0: |
78 if self.pos_interpolator: | 80 if self.pos_interpolator: |
79 self.pos_interpolator.update(self.frame) | 81 self.pos_interpolator.update(self.frame) |
80 self.x, self.y = self.pos_interpolator.values | 82 self.x, self.y = self.pos_interpolator.values |
81 | 83 |
82 self.scale_interpolator.update(self.frame) | 84 self.scale_interpolator.update(self.frame) |
83 self._sprite.rescale = self.scale_interpolator.values | 85 self.sprite.rescale = self.scale_interpolator.values |
84 | 86 |
85 self.rotations_interpolator.update(self.frame) | 87 self.rotations_interpolator.update(self.frame) |
86 self._sprite.rotations_3d = self.rotations_interpolator.values | 88 self.sprite.rotations_3d = self.rotations_interpolator.values |
87 | 89 |
88 self._sprite._changed = True | 90 self.sprite.changed = True |
89 | 91 |
90 if self.frame == 24: | 92 if self.frame == 24: |
91 self._removed = True | 93 self.removed = True |
92 | 94 |
93 self.frame += 1 | 95 self.frame += 1 |
96 |