Mercurial > touhou
comparison pytouhou/game/game.pyx @ 492:887de1309491
Add friendly fire in netplay.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 21 Sep 2013 20:26:39 +0200 |
parents | 711c75115675 |
children | 6be9c99a3a24 |
comparison
equal
deleted
inserted
replaced
491:2276229282fd | 492:887de1309491 |
---|---|
24 | 24 |
25 | 25 |
26 cdef class Game: | 26 cdef class Game: |
27 def __init__(self, players, long stage, long rank, long difficulty, bullet_types, | 27 def __init__(self, players, long stage, long rank, long difficulty, bullet_types, |
28 laser_types, item_types, long nb_bullets_max=0, long width=384, | 28 laser_types, item_types, long nb_bullets_max=0, long width=384, |
29 long height=448, prng=None, interface=None, hints=None): | 29 long height=448, prng=None, interface=None, hints=None, |
30 friendly_fire=True): | |
30 self.width, self.height = width, height | 31 self.width, self.height = width, height |
31 | 32 |
32 self.nb_bullets_max = nb_bullets_max | 33 self.nb_bullets_max = nb_bullets_max |
33 self.bullet_types = bullet_types | 34 self.bullet_types = bullet_types |
34 self.laser_types = laser_types | 35 self.laser_types = laser_types |
70 | 71 |
71 # See 102h.exe@0x413220 if you think you're brave enough. | 72 # See 102h.exe@0x413220 if you think you're brave enough. |
72 self.deaths_count = self.prng.rand_uint16() % 3 | 73 self.deaths_count = self.prng.rand_uint16() % 3 |
73 self.next_bonus = self.prng.rand_uint16() % 8 | 74 self.next_bonus = self.prng.rand_uint16() % 8 |
74 | 75 |
76 self.friendly_fire = friendly_fire | |
75 self.last_keystate = 0 | 77 self.last_keystate = 0 |
76 | 78 |
77 | 79 |
78 cdef list msg_sprites(self): | 80 cdef list msg_sprites(self): |
79 return [face for face in self.faces if face is not None] if self.msg_runner is not None and not self.msg_runner.ended else [] | 81 return [face for face in self.faces if face is not None] if self.msg_runner is not None and not self.msg_runner.ended else [] |
384 cdef Player player | 386 cdef Player player |
385 cdef Bullet bullet | 387 cdef Bullet bullet |
386 cdef Item item | 388 cdef Item item |
387 cdef PlayerLaser player_laser | 389 cdef PlayerLaser player_laser |
388 cdef Laser laser | 390 cdef Laser laser |
391 cdef PlayerLaser plaser | |
389 cdef double player_pos[2] | 392 cdef double player_pos[2] |
390 | 393 |
391 if self.time_stop: | 394 if self.time_stop: |
392 return | 395 return |
393 | 396 |
456 self.modify_difficulty(+6) | 459 self.modify_difficulty(+6) |
457 self.new_particle((px, py), 9, 192) #TODO: find the real size and range. | 460 self.new_particle((px, py), 9, 192) #TODO: find the real size and range. |
458 #TODO: display a static particle during one frame at | 461 #TODO: display a static particle during one frame at |
459 # 12 pixels of the player, in the axis of the “collision”. | 462 # 12 pixels of the player, in the axis of the “collision”. |
460 | 463 |
464 # Check for friendly-fire only if there are multiple players. | |
465 if self.friendly_fire and len(self.players) > 1: | |
466 for bullet in self.players_bullets: | |
467 if bullet.state != LAUNCHED: | |
468 continue | |
469 | |
470 if bullet.player == player_state.number: | |
471 continue | |
472 | |
473 bhalf_width = bullet.hitbox[0] | |
474 bhalf_height = bullet.hitbox[1] | |
475 bx, by = bullet.x, bullet.y | |
476 bx1, bx2 = bx - bhalf_width, bx + bhalf_width | |
477 by1, by2 = by - bhalf_height, by + bhalf_height | |
478 | |
479 if not (bx2 < px1 or bx1 > px2 | |
480 or by2 < py1 or by1 > py2): | |
481 bullet.collide() | |
482 if player_state.invulnerable_time == 0: | |
483 player.collide() | |
484 | |
485 for plaser in self.players_lasers: | |
486 if not plaser: | |
487 continue | |
488 | |
489 lhalf_width = plaser.hitbox[0] | |
490 lx, ly = plaser.x, plaser.y * 2. | |
491 lx1, lx2 = lx - lhalf_width, lx + lhalf_width | |
492 | |
493 if not (lx2 < px1 or lx1 > px2 | |
494 or ly < py1): | |
495 if player_state.invulnerable_time == 0: | |
496 player.collide() | |
497 | |
461 #TODO: is it the right place? | 498 #TODO: is it the right place? |
462 if py < 128 and player_state.power >= 128: #TODO: check py. | 499 if py < 128 and player_state.power >= 128: #TODO: check py. |
463 self.autocollect(player) | 500 self.autocollect(player) |
464 | 501 |
465 ihalf_size = <double>player.sht.item_hitbox | 502 ihalf_size = <double>player.sht.item_hitbox |