Mercurial > touhou
annotate pytouhou/game/effect.py @ 435:878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 07 Aug 2013 11:34:40 +0200 |
parents | 1222341ea22c |
children | b9d2db93972f |
rev | line source |
---|---|
173
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 ## |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 ## Copyright (C) 2011 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 ## |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 ## |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
13 ## |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
14 |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
15 |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
16 from pytouhou.game.sprite import Sprite |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 from pytouhou.vm.anmrunner import ANMRunner |
181
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
18 from pytouhou.utils.interpolator import Interpolator |
173
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
19 |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
21 |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
22 class Effect(object): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
388
diff
changeset
|
23 def __init__(self, pos, index, anm): |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
193
diff
changeset
|
24 self.sprite = Sprite() |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
388
diff
changeset
|
25 self.anmrunner = ANMRunner(anm, index, self.sprite) |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
193
diff
changeset
|
26 self.removed = False |
384
690b5faaa0e6
Make rendering of multiple-sprites elements work like single-sprites.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
332
diff
changeset
|
27 self.objects = [self] |
173
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
28 |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
29 self.x, self.y = pos |
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 |
181
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
31 |
173
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 def update(self): |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
193
diff
changeset
|
33 if self.anmrunner and not self.anmrunner.run_frame(): |
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
193
diff
changeset
|
34 self.anmrunner = None |
173
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
35 |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
193
diff
changeset
|
36 if self.sprite: |
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
193
diff
changeset
|
37 if self.sprite.removed: |
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
193
diff
changeset
|
38 self.sprite = None |
332 | 39 self.removed = True |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
193
diff
changeset
|
40 |
181
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
41 |
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
42 |
388
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
43 class Particle(Effect): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
388
diff
changeset
|
44 def __init__(self, pos, index, anm, amp, game, reverse=False, duration=24): |
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
388
diff
changeset
|
45 Effect.__init__(self, pos, index, anm) |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
193
diff
changeset
|
46 |
181
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
47 self.frame = 0 |
388
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
48 self.duration = duration |
181
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
49 |
388
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
50 random_pos = (self.x + amp * game.prng.rand_double() - amp / 2, |
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
51 self.y + amp * game.prng.rand_double() - amp / 2) |
190
dbe6b7b2d3fc
Fix a few things about particles.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
181
diff
changeset
|
52 |
388
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
53 if not reverse: |
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
54 self.pos_interpolator = Interpolator((self.x, self.y), 0, |
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
55 random_pos, duration, formula=(lambda x: 2. * x - x ** 2)) |
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
56 else: |
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
57 self.pos_interpolator = Interpolator(random_pos, 0, |
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
58 (self.x, self.y), duration, formula=(lambda x: 2. * x - x ** 2)) |
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
59 self.x, self.y = random_pos |
181
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
60 |
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
61 |
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
62 def update(self): |
388
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
63 Effect.update(self) |
181
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
64 |
388
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
65 self.pos_interpolator.update(self.frame) |
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
66 self.x, self.y = self.pos_interpolator.values |
181
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
67 |
184196480f59
Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
173
diff
changeset
|
68 self.frame += 1 |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
193
diff
changeset
|
69 |