# HG changeset patch # User Thibaut Girka # Date 1327258060 -3600 # Node ID a0d6b1915591f12c58ff9f9a7bcf7fba5157ca27 # Parent 6bd565019f9acc5fb7c4d9aa9f446bd243aa1a45 Fix bullet removal condition. diff --git a/pytouhou/game/bullet.py b/pytouhou/game/bullet.py --- 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.) diff --git a/pytouhou/game/game.py b/pytouhou/game/game.py --- 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 = []