changeset 631:cd8a2baf468c

Move Particle to its own module, to not pollute pytouhou.game.effect.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 05 May 2015 14:49:22 +0200
parents 6c40f5840a06
children 2d695ac78c94
files pytouhou/game/effect.pxd pytouhou/game/effect.pyx pytouhou/game/game.pyx pytouhou/game/particle.pxd pytouhou/game/particle.pyx
diffstat 5 files changed, 52 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/effect.pxd
+++ b/pytouhou/game/effect.pxd
@@ -1,12 +1,4 @@
 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)
--- a/pytouhou/game/effect.pyx
+++ b/pytouhou/game/effect.pyx
@@ -15,8 +15,6 @@
 from pytouhou.game.sprite cimport Sprite
 from pytouhou.vm import ANMRunner
 
-from pytouhou.game.game cimport Game
-
 
 cdef class Effect(Element):
     def __init__(self, pos, index, anm):
@@ -33,32 +31,3 @@ cdef class Effect(Element):
             if self.sprite.removed:
                 self.sprite = None
                 self.removed = True
-
-
-
-cdef class Particle(Effect):
-    def __init__(self, pos, index, anm, long amp, Game 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)
-
-        if not reverse:
-            self.pos_interpolator = Interpolator((self.x, self.y), 0,
-                                                 random_pos, duration, formula=(lambda x: 2. * x - x ** 2))
-        else:
-            self.pos_interpolator = Interpolator(random_pos, 0,
-                                                 (self.x, self.y), duration, formula=(lambda x: 2. * x - x ** 2))
-            self.x, self.y = random_pos
-
-
-    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/game.pyx
+++ b/pytouhou/game/game.pyx
@@ -18,7 +18,7 @@ from pytouhou.game.element cimport Eleme
 from pytouhou.game.bullet cimport Bullet, LAUNCHED, CANCELLED
 from pytouhou.game.enemy cimport Enemy
 from pytouhou.game.item cimport Item
-from pytouhou.game.effect cimport Particle
+from pytouhou.game.particle cimport Particle
 from pytouhou.game.laser cimport Laser, PlayerLaser
 from pytouhou.game.face import Face
 
new file mode 100644
--- /dev/null
+++ b/pytouhou/game/particle.pxd
@@ -0,0 +1,8 @@
+from pytouhou.game.effect cimport Effect
+from pytouhou.utils.interpolator cimport Interpolator
+
+cdef class Particle(Effect):
+    cdef long frame, duration
+    cdef Interpolator pos_interpolator
+
+    cpdef update(self)
new file mode 100644
--- /dev/null
+++ b/pytouhou/game/particle.pyx
@@ -0,0 +1,43 @@
+# -*- encoding: utf-8 -*-
+##
+## Copyright (C) 2015 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published
+## by the Free Software Foundation; version 3 only.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+
+from pytouhou.game.game cimport Game
+
+
+cdef class Particle(Effect):
+    def __init__(self, pos, index, anm, long amp, Game 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)
+
+        if not reverse:
+            self.pos_interpolator = Interpolator((self.x, self.y), 0,
+                                                 random_pos, duration, formula=(lambda x: 2. * x - x ** 2))
+        else:
+            self.pos_interpolator = Interpolator(random_pos, 0,
+                                                 (self.x, self.y), duration, formula=(lambda x: 2. * x - x ** 2))
+            self.x, self.y = random_pos
+
+
+    cpdef update(self):
+        Effect.update(self)
+
+        self.pos_interpolator.update(self.frame)
+        self.x, self.y = self.pos_interpolator.values
+
+        self.frame += 1