changeset 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 6b4c3e250bd6
children f26c8ab57257
files pytouhou/game/effect.pxd pytouhou/game/effect.py pytouhou/game/effect.pyx pytouhou/game/enemy.pyx
diffstat 3 files changed, 23 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/pytouhou/game/effect.pxd
@@ -0,0 +1,12 @@
+from pytouhou.game.element cimport Element
+from pytouhou.utils.interpolator cimport Interpolator
+
+cdef class Effect(Element):
+    cpdef update(self)
+
+
+cdef class Particle(Effect):
+    cdef long frame, duration
+    cdef Interpolator pos_interpolator
+
+    cpdef update(self)
rename from pytouhou/game/effect.py
rename to pytouhou/game/effect.pyx
--- a/pytouhou/game/effect.py
+++ b/pytouhou/game/effect.pyx
@@ -12,41 +12,37 @@
 ## GNU General Public License for more details.
 ##
 
-
-from pytouhou.game.element import Element
-from pytouhou.game.sprite import Sprite
+from pytouhou.game.sprite cimport Sprite
 from pytouhou.vm.anmrunner import ANMRunner
-from pytouhou.utils.interpolator import Interpolator
 
 
-
-class Effect(Element):
+cdef class Effect(Element):
     def __init__(self, pos, index, anm):
         Element.__init__(self, pos)
         self.sprite = Sprite()
         self.anmrunner = ANMRunner(anm, index, self.sprite)
 
 
-    def update(self):
-        if self.anmrunner and not self.anmrunner.run_frame():
+    cpdef update(self):
+        if self.anmrunner is not None and not self.anmrunner.run_frame():
             self.anmrunner = None
 
-        if self.sprite:
+        if self.sprite is not None:
             if self.sprite.removed:
                 self.sprite = None
                 self.removed = True
 
 
 
-class Particle(Effect):
-    def __init__(self, pos, index, anm, amp, game, reverse=False, duration=24):
+cdef class Particle(Effect):
+    def __init__(self, pos, index, anm, long amp, game, bint reverse=False, long duration=24):
         Effect.__init__(self, pos, index, anm)
 
         self.frame = 0
         self.duration = duration
 
-        random_pos = (self.x + amp * game.prng.rand_double() - amp / 2,
-                      self.y + amp * game.prng.rand_double() - amp / 2)
+        random_pos = (self.x + amp * <double>game.prng.rand_double() - amp / 2,
+                      self.y + amp * <double>game.prng.rand_double() - amp / 2)
 
         if not reverse:
             self.pos_interpolator = Interpolator((self.x, self.y), 0,
@@ -57,11 +53,10 @@ class Particle(Effect):
             self.x, self.y = random_pos
 
 
-    def update(self):
+    cpdef update(self):
         Effect.update(self)
 
         self.pos_interpolator.update(self.frame)
         self.x, self.y = self.pos_interpolator.values
 
         self.frame += 1
-
--- a/pytouhou/game/enemy.pyx
+++ b/pytouhou/game/enemy.pyx
@@ -18,7 +18,7 @@ from pytouhou.vm.anmrunner import ANMRun
 from pytouhou.game.sprite import Sprite
 from pytouhou.game.bullet import Bullet, LAUNCHED
 from pytouhou.game.laser import Laser
-from pytouhou.game.effect import Effect
+from pytouhou.game.effect cimport Effect
 
 
 cdef class Enemy(Element):