diff pytouhou/game/effect.py @ 181:184196480f59

Don’t use the useless eff00.anm and implement particles (grazing, death, and more).
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 23 Oct 2011 14:50:44 -0700
parents 35d850502d1f
children dbe6b7b2d3fc
line wrap: on
line diff
--- a/pytouhou/game/effect.py
+++ b/pytouhou/game/effect.py
@@ -15,6 +15,8 @@
 
 from pytouhou.game.sprite import Sprite
 from pytouhou.vm.anmrunner import ANMRunner
+from pytouhou.utils.interpolator import Interpolator
+from math import pi
 
 
 
@@ -27,6 +29,7 @@ class Effect(object):
 
         self.x, self.y = pos
 
+
     def update(self):
         if self._anmrunner and not self._anmrunner.run_frame():
             self._anmrunner = None
@@ -34,3 +37,41 @@ class Effect(object):
         if self._sprite:
             if self._sprite._removed:
                 self._sprite = None
+
+
+class Particle(object):
+    def __init__(self, start_pos, index, anm_wrapper, size, end_pos):
+        self._sprite = Sprite()
+        self._sprite.anm, self._sprite.texcoords = anm_wrapper.get_sprite(index)
+        self._removed = False
+
+        self.x, self.y = start_pos
+        self.frame = 0
+        self._sprite.alpha = 128
+        self._sprite.blendfunc = 1
+
+        self.pos_interpolator = Interpolator(start_pos, 0,
+                                             end_pos, 24, formula=(lambda x: 2. * x - x ** 2))
+        self.scale_interpolator = Interpolator((size, size), 0,
+                                               (0., 0.), 24)
+        self.rotations_interpolator = Interpolator((0., 0., 0.), 0,
+                                                   (0., 0., 2*pi), 24)
+        self._sprite._changed = True
+
+
+    def update(self):
+        self.pos_interpolator.update(self.frame)
+        self.x, self.y = self.pos_interpolator.values
+
+        self.scale_interpolator.update(self.frame)
+        self._sprite.rescale = self.scale_interpolator.values
+
+        self.rotations_interpolator.update(self.frame)
+        self._sprite.rotations_3d = self.rotations_interpolator.values
+
+        self._sprite._changed = True
+
+        if self.frame == 24:
+            self._removed = True
+
+        self.frame += 1