Mercurial > touhou
annotate pytouhou/game/effect.pyx @ 612:73f134f84c7f
Request a RGB888 context, since SDL2’s default of RGB332 sucks.
On X11/GLX, it will select the first config available, that is the best
one, while on EGL it will iterate over them to select the one closest
to what the application requested.
Of course, anything lower than RGB888 looks bad and we really don’t
want that.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 26 Mar 2015 20:20:37 +0100 |
parents | e35bef07290d |
children | cd8a2baf468c |
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 |
443
cae83b963695
Make pytouhou.game.effect an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
15 from pytouhou.game.sprite cimport Sprite |
547
e35bef07290d
Always import runners from pytouhou.vm, to allow their replacement.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
509
diff
changeset
|
16 from pytouhou.vm import ANMRunner |
173
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
17 |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
443
diff
changeset
|
18 from pytouhou.game.game cimport Game |
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
443
diff
changeset
|
19 |
173
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
20 |
443
cae83b963695
Make pytouhou.game.effect an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
21 cdef class Effect(Element): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
388
diff
changeset
|
22 def __init__(self, pos, index, anm): |
440
b9d2db93972f
Add a base Element class for every object in pytouhou.game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
433
diff
changeset
|
23 Element.__init__(self, pos) |
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) |
173
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
26 |
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
|
27 |
443
cae83b963695
Make pytouhou.game.effect an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
28 cpdef update(self): |
cae83b963695
Make pytouhou.game.effect an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
29 if self.anmrunner is not None and not self.anmrunner.run_frame(): |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
193
diff
changeset
|
30 self.anmrunner = None |
173
35d850502d1f
Move effects where they should be.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 |
443
cae83b963695
Make pytouhou.game.effect an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
32 if self.sprite is not None: |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
193
diff
changeset
|
33 if self.sprite.removed: |
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
193
diff
changeset
|
34 self.sprite = None |
332 | 35 self.removed = True |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
193
diff
changeset
|
36 |
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
|
37 |
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
|
38 |
443
cae83b963695
Make pytouhou.game.effect an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
39 cdef class Particle(Effect): |
447
78e1c3864e73
Make pytouhou.game.game an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
443
diff
changeset
|
40 def __init__(self, pos, index, anm, long amp, Game game, bint reverse=False, long duration=24): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
388
diff
changeset
|
41 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
|
42 |
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
|
43 self.frame = 0 |
388
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
44 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
|
45 |
509
292fea5c584e
Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
447
diff
changeset
|
46 random_pos = (self.x + amp * game.prng.rand_double() - amp / 2, |
292fea5c584e
Some more type optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
447
diff
changeset
|
47 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
|
48 |
388
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
49 if not reverse: |
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
50 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
|
51 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
|
52 else: |
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
53 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
|
54 (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
|
55 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
|
56 |
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
|
57 |
443
cae83b963695
Make pytouhou.game.effect an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
440
diff
changeset
|
58 cpdef update(self): |
388
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
59 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
|
60 |
388
ac2891afb0bb
Make particles behave as in the original game.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
61 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
|
62 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
|
63 |
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 self.frame += 1 |