comparison pytouhou/game/enemy.py @ 212:78e9957ad344

Hopefully fix enemy-player collision
author Thibaut Girka <thib@sitedethib.com>
date Sat, 26 Nov 2011 20:39:04 +0100
parents f5be441d2c42
children 0595315d3880
comparison
equal deleted inserted replaced
211:a765ef90c2b0 212:78e9957ad344
249 bullet.collide() 249 bullet.collide()
250 damages += bullet._bullet_type.damage 250 damages += bullet._bullet_type.damage
251 self.drop_particles(1, 1) 251 self.drop_particles(1, 1)
252 252
253 # Check for enemy-player collisions 253 # Check for enemy-player collisions
254 ex1, ex2 = ex - ehalf_size_x * 2. / 3., ex + ehalf_size_x * 2. / 3.
255 ey1, ey2 = ey - ehalf_size_y * 2. / 3., ey + ehalf_size_y * 2. / 3.
254 if self.collidable: 256 if self.collidable:
255 for player in self._game.players: 257 for player in self._game.players:
256 if not player.state.touchable:
257 continue
258
259 px, py = player.x, player.y 258 px, py = player.x, player.y
260 phalf_size = player.hitbox_half_size 259 phalf_size = player.hitbox_half_size
261 px1, px2 = px - phalf_size, px + phalf_size 260 px1, px2 = px - phalf_size, px + phalf_size
262 py1, py2 = py - phalf_size, py + phalf_size 261 py1, py2 = py - phalf_size, py + phalf_size
263 262
264 #TODO: box-box or point-in-box? 263 #TODO: box-box or point-in-box?
265 if not (ex2 < px1 or ex1 > px2 or ey2 < py1 or ey1 > py2): 264 if not (ex2 < px1 or ex1 > px2 or ey2 < py1 or ey1 > py2):
266 if not self.boss: 265 if not self.boss:
267 damages += 10 266 damages += 10
268 if player.state.invulnerable_time == 0: #TODO 267 player.collide()
269 player.collide()
270 268
271 # Adjust damages 269 # Adjust damages
272 damages = min(70, damages) 270 damages = min(70, damages)
273 score = (damages // 5) * 10 #TODO: give to which player? 271 score = (damages // 5) * 10 #TODO: give to which player?
274 272