comparison pytouhou/game/game.py @ 172:ea2ad94c33a0

Implement player death.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 21 Oct 2011 09:29:16 -0700
parents 2f3665a77f11
children 35d850502d1f
comparison
equal deleted inserted replaced
171:2f3665a77f11 172:ea2ad94c33a0
31 self.nb_bullets_max = nb_bullets_max 31 self.nb_bullets_max = nb_bullets_max
32 self.bullet_types = bullet_types 32 self.bullet_types = bullet_types
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], self) for player_state in player_states]
37 self.enemies = [] 37 self.enemies = []
38 self.effects = [] 38 self.effects = []
39 self.bullets = [] 39 self.bullets = []
40 self.cancelled_bullets = [] 40 self.cancelled_bullets = []
41 self.players_bullets = [] 41 self.players_bullets = []
52 'stg%denm2.anm' % stage)) 52 'stg%denm2.anm' % stage))
53 ecl = resource_loader.get_ecl('ecldata%d.ecl' % stage) 53 ecl = resource_loader.get_ecl('ecldata%d.ecl' % stage)
54 self.ecl_runner = ECLMainRunner(ecl, self) 54 self.ecl_runner = ECLMainRunner(ecl, self)
55 55
56 56
57 def drop_bonus(self, x, y, _type): 57 def drop_bonus(self, x, y, _type, end_pos=None):
58 player = self.players[0] #TODO 58 player = self.players[0] #TODO
59 if _type > 6: 59 if _type > 6:
60 return 60 return
61 item_type = self.item_types[_type] 61 item_type = self.item_types[_type]
62 item = Item((x, y), item_type, self) 62 item = Item((x, y), item_type, self, end_pos=end_pos)
63 self.items.append(item) 63 self.items.append(item)
64 64
65 65
66 def change_bullets_into_star_items(self): 66 def change_bullets_into_star_items(self):
67 player = self.players[0] #TODO 67 player = self.players[0] #TODO
119 item.update() 119 item.update()
120 120
121 # 4. Check for collisions! 121 # 4. Check for collisions!
122 #TODO 122 #TODO
123 for player in self.players: 123 for player in self.players:
124 if not player.state.touchable:
125 continue
126
124 px, py = player.x, player.y 127 px, py = player.x, player.y
125 phalf_size = player.hitbox_half_size 128 phalf_size = player.hitbox_half_size
126 px1, px2 = px - phalf_size, px + phalf_size 129 px1, px2 = px - phalf_size, px + phalf_size
127 py1, py2 = py - phalf_size, py + phalf_size 130 py1, py2 = py - phalf_size, py + phalf_size
128 131
133 by1, by2 = by - half_size, by + half_size 136 by1, by2 = by - half_size, by + half_size
134 137
135 if not (bx2 < px1 or bx1 > px2 138 if not (bx2 < px1 or bx1 > px2
136 or by2 < py1 or by1 > py2): 139 or by2 < py1 or by1 > py2):
137 bullet.collide() 140 bullet.collide()
138 player.collide() 141 if player.state.invulnerable_time == 0:
142 player.collide()
139 143
140 for enemy in self.enemies: 144 for enemy in self.enemies:
141 half_size_x, half_size_y = enemy.hitbox_half_size 145 half_size_x, half_size_y = enemy.hitbox_half_size
142 bx, by = enemy.x, enemy.y 146 bx, by = enemy.x, enemy.y
143 bx1, bx2 = bx - half_size_x, bx + half_size_x 147 bx1, bx2 = bx - half_size_x, bx + half_size_x
144 by1, by2 = by - half_size_y, by + half_size_y 148 by1, by2 = by - half_size_y, by + half_size_y
145 149
146 if enemy.touchable and not (bx2 < px1 or bx1 > px2 150 if enemy.touchable and not (bx2 < px1 or bx1 > px2
147 or by2 < py1 or by1 > py2): 151 or by2 < py1 or by1 > py2):
148 enemy.on_collide() 152 enemy.on_collide()
149 player.collide() 153 if player.state.invulnerable_time == 0:
154 player.collide()
150 155
151 for item in self.items: 156 for item in self.items:
152 half_size = item.hitbox_half_size 157 half_size = item.hitbox_half_size
153 bx, by = item.x, item.y 158 bx, by = item.x, item.y
154 bx1, bx2 = bx - half_size, bx + half_size 159 bx1, bx2 = bx - half_size, bx + half_size
172 177
173 if not (bx2 < ex1 or bx1 > ex2 178 if not (bx2 < ex1 or bx1 > ex2
174 or by2 < ey1 or by1 > ey2): 179 or by2 < ey1 or by1 > ey2):
175 bullet.collide() 180 bullet.collide()
176 enemy.on_attack(bullet) 181 enemy.on_attack(bullet)
182 player.state.score += 90 # found experimentally
177 183
178 # 5. Cleaning 184 # 5. Cleaning
179 self.cleanup() 185 self.cleanup()
180 186
181 self.frame += 1 187 self.frame += 1