comparison pytouhou/game/game.py @ 390:b11953cf1d3b

Use only half-size hitboxes for player.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 12 Nov 2012 18:34:24 +0100
parents ac2891afb0bb
children 9589a01e6edf
comparison
equal deleted inserted replaced
389:eef492100f4c 390:b11953cf1d3b
317 for player in self.players: 317 for player in self.players:
318 if not player.state.touchable: 318 if not player.state.touchable:
319 continue 319 continue
320 320
321 px, py = player.x, player.y 321 px, py = player.x, player.y
322 phalf_size = player.hitbox_half_size 322 phalf_size = player.sht.hitbox
323 px1, px2 = px - phalf_size, px + phalf_size 323 px1, px2 = px - phalf_size, px + phalf_size
324 py1, py2 = py - phalf_size, py + phalf_size 324 py1, py2 = py - phalf_size, py + phalf_size
325 325
326 ghalf_size = player.graze_hitbox_half_size 326 ghalf_size = player.sht.graze_hitbox
327 gx1, gx2 = px - ghalf_size, px + ghalf_size 327 gx1, gx2 = px - ghalf_size, px + ghalf_size
328 gy1, gy2 = py - ghalf_size, py + ghalf_size 328 gy1, gy2 = py - ghalf_size, py + ghalf_size
329 329
330 for laser in self.lasers: 330 for laser in self.lasers:
331 if laser.check_collision((px, py)): 331 if laser.check_collision((px, py)):
340 340
341 for bullet in self.bullets: 341 for bullet in self.bullets:
342 if bullet.state != LAUNCHED: 342 if bullet.state != LAUNCHED:
343 continue 343 continue
344 344
345 half_size = bullet.hitbox_half_size 345 bhalf_width, bhalf_height = bullet.hitbox
346 bx, by = bullet.x, bullet.y 346 bx, by = bullet.x, bullet.y
347 bx1, bx2 = bx - half_size[0], bx + half_size[0] 347 bx1, bx2 = bx - bhalf_width, bx + bhalf_width
348 by1, by2 = by - half_size[1], by + half_size[1] 348 by1, by2 = by - bhalf_height, by + bhalf_height
349 349
350 if not (bx2 < px1 or bx1 > px2 350 if not (bx2 < px1 or bx1 > px2
351 or by2 < py1 or by1 > py2): 351 or by2 < py1 or by1 > py2):
352 bullet.collide() 352 bullet.collide()
353 if player.state.invulnerable_time == 0: 353 if player.state.invulnerable_time == 0:
366 366
367 #TODO: is it the right place? 367 #TODO: is it the right place?
368 if py < 128 and player.state.power >= 128: #TODO: check py. 368 if py < 128 and player.state.power >= 128: #TODO: check py.
369 self.autocollect(player) 369 self.autocollect(player)
370 370
371 half_size = player.sht.item_hitbox / 2. 371 ihalf_size = player.sht.item_hitbox
372 for item in self.items: 372 for item in self.items:
373 bx, by = item.x, item.y 373 bx, by = item.x, item.y
374 bx1, bx2 = bx - half_size, bx + half_size 374 bx1, bx2 = bx - ihalf_size, bx + ihalf_size
375 by1, by2 = by - half_size, by + half_size 375 by1, by2 = by - ihalf_size, by + ihalf_size
376 376
377 if not (bx2 < px1 or bx1 > px2 377 if not (bx2 < px1 or bx1 > px2
378 or by2 < py1 or by1 > py2): 378 or by2 < py1 or by1 > py2):
379 item.on_collect(player) 379 item.on_collect(player)
380 380