comparison pytouhou/game/game.py @ 176:80a4c7ed43b3

Add grazing check.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 22 Oct 2011 06:21:38 -0700
parents 35d850502d1f
children 5a1533677a9a
comparison
equal deleted inserted replaced
175:5dc243bcf312 176:80a4c7ed43b3
133 px, py = player.x, player.y 133 px, py = player.x, player.y
134 phalf_size = player.hitbox_half_size 134 phalf_size = player.hitbox_half_size
135 px1, px2 = px - phalf_size, px + phalf_size 135 px1, px2 = px - phalf_size, px + phalf_size
136 py1, py2 = py - phalf_size, py + phalf_size 136 py1, py2 = py - phalf_size, py + phalf_size
137 137
138 ghalf_size = player.graze_hitbox_half_size
139 gx1, gx2 = px - ghalf_size, px + ghalf_size
140 gy1, gy2 = py - ghalf_size, py + ghalf_size
141
138 for bullet in self.bullets: 142 for bullet in self.bullets:
139 half_size = bullet.hitbox_half_size 143 half_size = bullet.hitbox_half_size
140 bx, by = bullet.x, bullet.y 144 bx, by = bullet.x, bullet.y
141 bx1, bx2 = bx - half_size, bx + half_size 145 bx1, bx2 = bx - half_size, bx + half_size
142 by1, by2 = by - half_size, by + half_size 146 by1, by2 = by - half_size, by + half_size
144 if not (bx2 < px1 or bx1 > px2 148 if not (bx2 < px1 or bx1 > px2
145 or by2 < py1 or by1 > py2): 149 or by2 < py1 or by1 > py2):
146 bullet.collide() 150 bullet.collide()
147 if player.state.invulnerable_time == 0: 151 if player.state.invulnerable_time == 0:
148 player.collide() 152 player.collide()
153
154 elif not (bx2 < gx1 or bx1 > gx2
155 or by2 < gy1 or by1 > gy2):
156 pass#TODO: graze
149 157
150 for enemy in self.enemies: 158 for enemy in self.enemies:
151 half_size_x, half_size_y = enemy.hitbox_half_size 159 half_size_x, half_size_y = enemy.hitbox_half_size
152 bx, by = enemy.x, enemy.y 160 bx, by = enemy.x, enemy.y
153 bx1, bx2 = bx - half_size_x, bx + half_size_x 161 bx1, bx2 = bx - half_size_x, bx + half_size_x