comparison pytouhou/game/game.py @ 166:dcf32488a2c9

Better enemy death, with animation and (hopefully) correct flags handling.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 18 Oct 2011 13:17:23 -0700
parents c8c60291c56f
children 2f3665a77f11
comparison
equal deleted inserted replaced
165:c8c60291c56f 166:dcf32488a2c9
33 self.item_types = item_types 33 self.item_types = item_types
34 self.characters = characters 34 self.characters = characters
35 35
36 self.players = [Player(player_state, characters[player_state.character]) for player_state in player_states] 36 self.players = [Player(player_state, characters[player_state.character]) for player_state in player_states]
37 self.enemies = [] 37 self.enemies = []
38 self.effects = []
38 self.bullets = [] 39 self.bullets = []
39 self.cancelled_bullets = [] 40 self.cancelled_bullets = []
40 self.players_bullets = [] 41 self.players_bullets = []
41 self.items = [] 42 self.items = []
42 43
79 # 1. VMs. 80 # 1. VMs.
80 self.ecl_runner.run_iter() 81 self.ecl_runner.run_iter()
81 82
82 # 2. Filter out destroyed enemies 83 # 2. Filter out destroyed enemies
83 self.enemies = [enemy for enemy in self.enemies if not enemy._removed] 84 self.enemies = [enemy for enemy in self.enemies if not enemy._removed]
85 self.effects = [enemy for enemy in self.effects if not enemy._removed]
84 self.bullets = [bullet for bullet in self.bullets if not bullet._removed] 86 self.bullets = [bullet for bullet in self.bullets if not bullet._removed]
85 self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets if not bullet._removed] 87 self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets if not bullet._removed]
86 self.items = [item for item in self.items if not item._removed] 88 self.items = [item for item in self.items if not item._removed]
87 89
88 # 3. Let's play! 90 # 3. Let's play!
99 player.state.y = 448.-16 101 player.state.y = 448.-16
100 102
101 for enemy in self.enemies: 103 for enemy in self.enemies:
102 enemy.update() 104 enemy.update()
103 105
106 for enemy in self.effects:
107 enemy.update()
108
104 for bullet in self.bullets: 109 for bullet in self.bullets:
105 bullet.update() 110 bullet.update()
106 111
107 for bullet in self.cancelled_bullets: 112 for bullet in self.cancelled_bullets:
108 bullet.update() 113 bullet.update()
138 bx1, bx2 = bx - half_size_x, bx + half_size_x 143 bx1, bx2 = bx - half_size_x, bx + half_size_x
139 by1, by2 = by - half_size_y, by + half_size_y 144 by1, by2 = by - half_size_y, by + half_size_y
140 145
141 if enemy.touchable and not (bx2 < px1 or bx1 > px2 146 if enemy.touchable and not (bx2 < px1 or bx1 > px2
142 or by2 < py1 or by1 > py2): 147 or by2 < py1 or by1 > py2):
143 enemy.collide() 148 enemy.on_collide()
144 player.collide() 149 player.collide()
145 150
146 for item in self.items: 151 for item in self.items:
147 half_size = item.hitbox_half_size 152 half_size = item.hitbox_half_size
148 bx, by = item.x, item.y 153 bx, by = item.x, item.y
166 by1, by2 = by - half_size, by + half_size 171 by1, by2 = by - half_size, by + half_size
167 172
168 if not (bx2 < ex1 or bx1 > ex2 173 if not (bx2 < ex1 or bx1 > ex2
169 or by2 < ey1 or by1 > ey2): 174 or by2 < ey1 or by1 > ey2):
170 bullet.collide() 175 bullet.collide()
171 enemy.life -= bullet._bullet_type.damage 176 enemy.on_attack(bullet)
172 177
173 # 5. Cleaning 178 # 5. Cleaning
174 self.cleanup() 179 self.cleanup()
175 180
176 self.frame += 1 181 self.frame += 1