changeset 255:a0d6b1915591

Fix bullet removal condition.
author Thibaut Girka <thib@sitedethib.com>
date Sun, 22 Jan 2012 19:47:40 +0100
parents 6bd565019f9a
children 507dfd6efe0c
files pytouhou/game/bullet.py pytouhou/game/game.py
diffstat 2 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/bullet.py
+++ b/pytouhou/game/bullet.py
@@ -30,6 +30,7 @@ class Bullet(object):
         self._removed = False
         self._launched = False
         self._bullet_type = bullet_type
+        self._was_visible = True
 
         if hitbox:
             self.hitbox_half_size = (hitbox[0] / 2., hitbox[1] / 2.)
--- a/pytouhou/game/game.py
+++ b/pytouhou/game/game.py
@@ -12,6 +12,7 @@
 ## GNU General Public License for more details.
 ##
 
+from itertools import chain
 
 from pytouhou.utils.random import Random
 
@@ -255,22 +256,32 @@ class Game(object):
 
     def cleanup(self):
         # Filter out non-visible enemies
-        for enemy in tuple(self.enemies):
+        for enemy in self.enemies:
             if enemy.is_visible(self.width, self.height):
                 enemy._was_visible = True
             elif enemy._was_visible:
                 # Filter out-of-screen enemy
                 enemy._removed = True
-                self.enemies.remove(enemy)
+
+        self.enemies = [enemy for enemy in self.enemies if not enemy._removed]
 
         # Filter out-of-scren bullets
-        # TODO: was_visible thing
+        # TODO: move to Bullet?
+        for bullet in chain(self.bullets, self.players_bullets):
+            if bullet.flags & 448:
+                bullet._was_visible = False
+            elif bullet.is_visible(self.width, self.height):
+                bullet._was_visible = True
+            elif bullet._was_visible:
+                # Filter out-of-screen bullets
+                bullet._removed = True
+
         self.bullets = [bullet for bullet in self.bullets
-                            if bullet.is_visible(self.width, self.height)]
+                            if not bullet._removed]
+        self.players_bullets = [bullet for bullet in self.players_bullets
+                            if not bullet._removed]
         self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets
                             if bullet.is_visible(self.width, self.height)]
-        self.players_bullets = [bullet for bullet in self.players_bullets
-                            if bullet.is_visible(self.width, self.height)]
 
         # Filter out-of-scren items
         items = []