changeset 290:18e4ed141dd8

Display lasers' “launch anim”.
author Thibaut Girka <thib@sitedethib.com>
date Wed, 15 Feb 2012 18:37:52 +0100
parents e7f40bff72fc
children f6b8483a990d
files pytouhou/game/game.py pytouhou/game/laser.py pytouhou/game/lasertype.py
diffstat 3 files changed, 36 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/game.py
+++ b/pytouhou/game/game.py
@@ -160,7 +160,7 @@ class Game(object):
 
         # 2. Filter out destroyed enemies
         self.enemies = [enemy for enemy in self.enemies if not enemy._removed]
-        self.effects = [enemy for enemy in self.effects if not enemy._removed]
+        self.effects = [effect for effect in self.effects if not effect._removed]
         self.bullets = [bullet for bullet in self.bullets if not bullet._removed]
         self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets if not bullet._removed]
         self.items = [item for item in self.items if not item._removed]
@@ -307,6 +307,7 @@ class Game(object):
                             if not bullet._removed]
         self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets
                             if not bullet._removed]
+        self.effects = [effect for effect in self.effects if not effect._removed]
 
         # Filter “timed-out” lasers
         self.lasers = [laser for laser in self.lasers if not laser._removed]
--- a/pytouhou/game/laser.py
+++ b/pytouhou/game/laser.py
@@ -21,6 +21,34 @@ from pytouhou.game.sprite import Sprite
 STARTING, STARTED, STOPPING = range(3)
 
 
+class LaserLaunchAnim(object):
+    def __init__(self, laser, anm_wrapper, index):
+        self._laser = laser
+        self._sprite = Sprite()
+        self._sprite.anm, self._sprite.texcoords = anm_wrapper.get_sprite(index)
+        self._sprite.blendfunc = 1
+        self._removed = False
+        self.x, self.y = 0, 0
+
+
+    def update(self):
+        laser = self._laser
+        length = min(laser.end_offset - laser.start_offset, laser.max_length)
+        offset = laser.end_offset - length
+        dx, dy = cos(laser.angle), sin(laser.angle)
+
+        self.x = laser.base_pos[0] + offset * dx
+        self.y = laser.base_pos[1] + offset * dy
+
+        scale = laser.width / 10. - (offset - laser.start_offset)
+        self._sprite.rescale = (scale, scale)
+        self._sprite._changed = True
+
+        if laser._removed or scale <= 0.:
+            self._removed = True
+
+
+
 class Laser(object):
     def __init__(self, base_pos, laser_type, sprite_idx_offset,
                        angle, speed, start_offset, end_offset, max_length, width,
@@ -28,7 +56,10 @@ class Laser(object):
                        grazing_delay, grazing_extra_duration,
                        game):
         self._game = game
-        #TODO: aux sprite
+        launch_anim = LaserLaunchAnim(self, laser_type.anm_wrapper,
+                                      laser_type.launch_anim_offsets[sprite_idx_offset]
+                                      + laser_type.launch_sprite_idx)
+        self._game.effects.append(launch_anim)
         self._sprite = None
         self._anmrunner = None
         self._removed = False
--- a/pytouhou/game/lasertype.py
+++ b/pytouhou/game/lasertype.py
@@ -1,6 +1,8 @@
 class LaserType(object):
     def __init__(self, anm_wrapper, anim_index,
+                 launch_sprite_idx=140,
                  launch_anim_offsets=(0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 0)):
         self.anm_wrapper = anm_wrapper
         self.anim_index = anim_index
+        self.launch_sprite_idx = launch_sprite_idx
         self.launch_anim_offsets = launch_anim_offsets