comparison pytouhou/game/game.py @ 164:5271789c067d

Implement player bullets rendering and updating.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 16 Oct 2011 08:01:28 -0700
parents 7e7368356445
children c8c60291c56f
comparison
equal deleted inserted replaced
163:ee0bbde02c48 164:5271789c067d
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.bullets = [] 38 self.bullets = []
39 self.cancelled_bullets = [] 39 self.cancelled_bullets = []
40 self.players_bullets = []
40 self.items = [] 41 self.items = []
41 42
42 self.stage = stage 43 self.stage = stage
43 self.rank = rank 44 self.rank = rank
44 self.difficulty = difficulty 45 self.difficulty = difficulty
102 bullet.update() 103 bullet.update()
103 104
104 for bullet in self.cancelled_bullets: 105 for bullet in self.cancelled_bullets:
105 bullet.update() 106 bullet.update()
106 107
108 for bullet in self.players_bullets:
109 bullet.update()
110
107 for item in self.items: 111 for item in self.items:
108 item.update() 112 item.update()
109 113
110 # 4. Check for collisions! 114 # 4. Check for collisions!
111 #TODO 115 #TODO
145 149
146 if not (bx2 < px1 or bx1 > px2 150 if not (bx2 < px1 or bx1 > px2
147 or by2 < py1 or by1 > py2): 151 or by2 < py1 or by1 > py2):
148 player.collect(item) 152 player.collect(item)
149 153
154 for enemy in self.enemies:
155 ex, ey = enemy.x, enemy.y
156 ehalf_size_x, ehalf_size_y = enemy.hitbox_half_size
157 ex1, ex2 = ex - ehalf_size_x, ex + ehalf_size_x
158 ey1, ey2 = ey - ehalf_size_y, ey + ehalf_size_y
159
160 for bullet in self.players_bullets:
161 half_size = bullet.hitbox_half_size
162 bx, by = bullet.x, bullet.y
163 bx1, bx2 = bx - half_size, bx + half_size
164 by1, by2 = by - half_size, by + half_size
165
166 if not (bx2 < ex1 or bx1 > ex2
167 or by2 < ey1 or by1 > ey2):
168 bullet.collide()
169 enemy.life -= bullet._bullet_type.damage
170
150 # 5. Cleaning 171 # 5. Cleaning
151 self.cleanup() 172 self.cleanup()
152 173
153 self.frame += 1 174 self.frame += 1
154 175
165 186
166 # Filter out-of-scren bullets 187 # Filter out-of-scren bullets
167 # TODO: was_visible thing 188 # TODO: was_visible thing
168 self.bullets = [bullet for bullet in self.bullets if bullet.is_visible(384, 448)] 189 self.bullets = [bullet for bullet in self.bullets if bullet.is_visible(384, 448)]
169 self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets if bullet.is_visible(384, 448)] 190 self.cancelled_bullets = [bullet for bullet in self.cancelled_bullets if bullet.is_visible(384, 448)]
191 self.players_bullets = [bullet for bullet in self.players_bullets if bullet.is_visible(384, 448)]
170 192
171 # Disable boss mode if it is dead/it has timeout 193 # Disable boss mode if it is dead/it has timeout
172 if self.boss and self.boss._removed: 194 if self.boss and self.boss._removed:
173 self.boss = None 195 self.boss = None
174 196