Mercurial > touhou
comparison pytouhou/game/effect.pyx @ 443:cae83b963695
Make pytouhou.game.effect an extension type.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 17 Aug 2013 02:36:05 +0200 |
parents | pytouhou/game/effect.py@b9d2db93972f |
children | 78e1c3864e73 |
comparison
equal
deleted
inserted
replaced
442:6b4c3e250bd6 | 443:cae83b963695 |
---|---|
1 # -*- encoding: utf-8 -*- | |
2 ## | |
3 ## Copyright (C) 2011 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | |
4 ## | |
5 ## This program is free software; you can redistribute it and/or modify | |
6 ## it under the terms of the GNU General Public License as published | |
7 ## by the Free Software Foundation; version 3 only. | |
8 ## | |
9 ## This program is distributed in the hope that it will be useful, | |
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 ## GNU General Public License for more details. | |
13 ## | |
14 | |
15 from pytouhou.game.sprite cimport Sprite | |
16 from pytouhou.vm.anmrunner import ANMRunner | |
17 | |
18 | |
19 cdef class Effect(Element): | |
20 def __init__(self, pos, index, anm): | |
21 Element.__init__(self, pos) | |
22 self.sprite = Sprite() | |
23 self.anmrunner = ANMRunner(anm, index, self.sprite) | |
24 | |
25 | |
26 cpdef update(self): | |
27 if self.anmrunner is not None and not self.anmrunner.run_frame(): | |
28 self.anmrunner = None | |
29 | |
30 if self.sprite is not None: | |
31 if self.sprite.removed: | |
32 self.sprite = None | |
33 self.removed = True | |
34 | |
35 | |
36 | |
37 cdef class Particle(Effect): | |
38 def __init__(self, pos, index, anm, long amp, game, bint reverse=False, long duration=24): | |
39 Effect.__init__(self, pos, index, anm) | |
40 | |
41 self.frame = 0 | |
42 self.duration = duration | |
43 | |
44 random_pos = (self.x + amp * <double>game.prng.rand_double() - amp / 2, | |
45 self.y + amp * <double>game.prng.rand_double() - amp / 2) | |
46 | |
47 if not reverse: | |
48 self.pos_interpolator = Interpolator((self.x, self.y), 0, | |
49 random_pos, duration, formula=(lambda x: 2. * x - x ** 2)) | |
50 else: | |
51 self.pos_interpolator = Interpolator(random_pos, 0, | |
52 (self.x, self.y), duration, formula=(lambda x: 2. * x - x ** 2)) | |
53 self.x, self.y = random_pos | |
54 | |
55 | |
56 cpdef update(self): | |
57 Effect.update(self) | |
58 | |
59 self.pos_interpolator.update(self.frame) | |
60 self.x, self.y = self.pos_interpolator.values | |
61 | |
62 self.frame += 1 |