comparison pytouhou/game/game.py @ 335:2350147cf043

Fix bullet cancellation and removal
author Thibaut Girka <thib@sitedethib.com>
date Sun, 01 Jul 2012 11:43:38 +0200
parents 56523a16db1d
children 72ef7e24b373
comparison
equal deleted inserted replaced
334:4eca6130f118 335:2350147cf043
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
16
15 from pytouhou.utils.random import Random 17 from pytouhou.utils.random import Random
16 18
17 from pytouhou.vm.eclrunner import ECLMainRunner 19 from pytouhou.vm.eclrunner import ECLMainRunner
18 from pytouhou.vm.msgrunner import MSGRunner 20 from pytouhou.vm.msgrunner import MSGRunner
19 21
22 from pytouhou.game.bullet import LAUNCHED, CANCELLED
20 from pytouhou.game.enemy import Enemy 23 from pytouhou.game.enemy import Enemy
21 from pytouhou.game.item import Item 24 from pytouhou.game.item import Item
22 from pytouhou.game.effect import Effect 25 from pytouhou.game.effect import Effect
23 from pytouhou.game.effect import Particle 26 from pytouhou.game.effect import Particle
24 from pytouhou.game.text import Text 27 from pytouhou.game.text import Text
140 for item in self.items: 143 for item in self.items:
141 if not item.player: 144 if not item.player:
142 item.autocollect(player) 145 item.autocollect(player)
143 146
144 147
148 def cancel_bullets(self):
149 for bullet in self.bullets:
150 bullet.cancel()
151 for laser in self.lasers:
152 laser.cancel()
153
154
145 def change_bullets_into_star_items(self): 155 def change_bullets_into_star_items(self):
146 player = self.players[0] #TODO 156 player = self.players[0] #TODO
147 item_type = self.item_types[6] 157 item_type = self.item_types[6]
148 self.items.extend(Item((bullet.x, bullet.y), 6, item_type, self, player=player) 158 self.items.extend(Item((bullet.x, bullet.y), 6, item_type, self, player=player)
149 for bullet in self.bullets) 159 for bullet in self.bullets)
323 player.state.score += 500 #TODO 333 player.state.score += 500 #TODO
324 self.modify_difficulty(+6) #TODO 334 self.modify_difficulty(+6) #TODO
325 self.new_particle((px, py), 0, .8, 192) #TODO 335 self.new_particle((px, py), 0, .8, 192) #TODO
326 336
327 for bullet in self.bullets: 337 for bullet in self.bullets:
338 if bullet.state != LAUNCHED:
339 continue
340
328 half_size = bullet.hitbox_half_size 341 half_size = bullet.hitbox_half_size
329 bx, by = bullet.x, bullet.y 342 bx, by = bullet.x, bullet.y
330 bx1, bx2 = bx - half_size[0], bx + half_size[0] 343 bx1, bx2 = bx - half_size[0], bx + half_size[0]
331 by1, by2 = by - half_size[1], by + half_size[1] 344 by1, by2 = by - half_size[1], by + half_size[1]
332 345
370 # Filter out-of-screen enemy 383 # Filter out-of-screen enemy
371 enemy.removed = True 384 enemy.removed = True
372 385
373 self.enemies = [enemy for enemy in self.enemies if not enemy.removed] 386 self.enemies = [enemy for enemy in self.enemies if not enemy.removed]
374 387
388 # Update cancelled bullets
389 self.cancelled_bullets = [b for b in chain(self.cancelled_bullets,
390 self.bullets,
391 self.players_bullets)
392 if b.state == CANCELLED and not b.removed]
375 # Filter out-of-scren bullets 393 # Filter out-of-scren bullets
376 self.bullets = [bullet for bullet in self.bullets 394 self.bullets = [bullet for bullet in self.bullets
377 if not bullet.removed] 395 if not bullet.removed and bullet.state != CANCELLED]
378 self.players_bullets = [bullet for bullet in self.players_bullets 396 self.players_bullets = [bullet for bullet in self.players_bullets
379 if not bullet.removed] 397 if not bullet.removed and bullet.state != CANCELLED]
380 for i, laser in enumerate(self.players_lasers): 398 for i, laser in enumerate(self.players_lasers):
381 if laser and laser.removed: 399 if laser and laser.removed:
382 self.players_lasers[i] = None 400 self.players_lasers[i] = None
383 self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets
384 if not bullet.removed]
385 self.effects = [effect for effect in self.effects if not effect.removed] 401 self.effects = [effect for effect in self.effects if not effect.removed]
386 402
387 # Filter “timed-out” lasers 403 # Filter “timed-out” lasers
388 self.lasers = [laser for laser in self.lasers if not laser.removed] 404 self.lasers = [laser for laser in self.lasers if not laser.removed]
389 405