comparison pytouhou/game/game.py @ 255:a0d6b1915591

Fix bullet removal condition.
author Thibaut Girka <thib@sitedethib.com>
date Sun, 22 Jan 2012 19:47:40 +0100
parents 77b83064b57e
children 620134bc51f4
comparison
equal deleted inserted replaced
254:6bd565019f9a 255:a0d6b1915591
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details. 12 ## GNU General Public License for more details.
13 ## 13 ##
14 14
15 from itertools import chain
15 16
16 from pytouhou.utils.random import Random 17 from pytouhou.utils.random import Random
17 18
18 from pytouhou.vm.eclrunner import ECLMainRunner 19 from pytouhou.vm.eclrunner import ECLMainRunner
19 20
253 item.on_collect(player) 254 item.on_collect(player)
254 255
255 256
256 def cleanup(self): 257 def cleanup(self):
257 # Filter out non-visible enemies 258 # Filter out non-visible enemies
258 for enemy in tuple(self.enemies): 259 for enemy in self.enemies:
259 if enemy.is_visible(self.width, self.height): 260 if enemy.is_visible(self.width, self.height):
260 enemy._was_visible = True 261 enemy._was_visible = True
261 elif enemy._was_visible: 262 elif enemy._was_visible:
262 # Filter out-of-screen enemy 263 # Filter out-of-screen enemy
263 enemy._removed = True 264 enemy._removed = True
264 self.enemies.remove(enemy) 265
266 self.enemies = [enemy for enemy in self.enemies if not enemy._removed]
265 267
266 # Filter out-of-scren bullets 268 # Filter out-of-scren bullets
267 # TODO: was_visible thing 269 # TODO: move to Bullet?
270 for bullet in chain(self.bullets, self.players_bullets):
271 if bullet.flags & 448:
272 bullet._was_visible = False
273 elif bullet.is_visible(self.width, self.height):
274 bullet._was_visible = True
275 elif bullet._was_visible:
276 # Filter out-of-screen bullets
277 bullet._removed = True
278
268 self.bullets = [bullet for bullet in self.bullets 279 self.bullets = [bullet for bullet in self.bullets
269 if bullet.is_visible(self.width, self.height)] 280 if not bullet._removed]
281 self.players_bullets = [bullet for bullet in self.players_bullets
282 if not bullet._removed]
270 self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets 283 self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets
271 if bullet.is_visible(self.width, self.height)]
272 self.players_bullets = [bullet for bullet in self.players_bullets
273 if bullet.is_visible(self.width, self.height)] 284 if bullet.is_visible(self.width, self.height)]
274 285
275 # Filter out-of-scren items 286 # Filter out-of-scren items
276 items = [] 287 items = []
277 for item in self.items: 288 for item in self.items: