comparison pytouhou/game/game.pyx @ 494:6be9c99a3a24

Merge PlayerState into Player, fix player respawn position.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 14 Oct 2013 12:11:01 +0200
parents 887de1309491
children 3da7395f39e3
comparison
equal deleted inserted replaced
493:26c082870dcf 494:6be9c99a3a24
190 self.bullets = [] 190 self.bullets = []
191 #TODO: display the final bonus score. 191 #TODO: display the final bonus score.
192 192
193 #TODO: do we really want to give it to each player? 193 #TODO: do we really want to give it to each player?
194 for player in self.players: 194 for player in self.players:
195 player.state.score += score 195 player.score += score
196 196
197 197
198 cpdef kill_enemies(self): 198 cpdef kill_enemies(self):
199 cdef Enemy enemy 199 cdef Enemy enemy
200 200
356 356
357 for player, keystate in zip(self.players, keystates): 357 for player, keystate in zip(self.players, keystates):
358 player.update(keystate) #TODO: differentiate keystates (multiplayer mode) 358 player.update(keystate) #TODO: differentiate keystates (multiplayer mode)
359 359
360 #XXX: Why 78910? Is it really the right value? 360 #XXX: Why 78910? Is it really the right value?
361 player.state.effective_score = min(player.state.effective_score + 78910, 361 player.effective_score = min(player.effective_score + 78910,
362 player.state.score) 362 player.score)
363 #TODO: give extra lives to the player 363 #TODO: give extra lives to the player
364 364
365 365
366 cdef void update_effects(self): 366 cdef void update_effects(self):
367 cdef Element effect 367 cdef Element effect
406 406
407 for item in self.items: 407 for item in self.items:
408 item.update() 408 item.update()
409 409
410 for player in self.players: 410 for player in self.players:
411 player_state = player.state 411 if not player.touchable:
412
413 if not player_state.touchable:
414 continue 412 continue
415 413
416 px, py = player_state.x, player_state.y 414 px, py = player.x, player.y
417 player_pos[:] = [px, py] 415 player_pos[:] = [px, py]
418 phalf_size = <double>player.sht.hitbox 416 phalf_size = <double>player.sht.hitbox
419 px1, px2 = px - phalf_size, px + phalf_size 417 px1, px2 = px - phalf_size, px + phalf_size
420 py1, py2 = py - phalf_size, py + phalf_size 418 py1, py2 = py - phalf_size, py + phalf_size
421 419
423 gx1, gx2 = px - ghalf_size, px + ghalf_size 421 gx1, gx2 = px - ghalf_size, px + ghalf_size
424 gy1, gy2 = py - ghalf_size, py + ghalf_size 422 gy1, gy2 = py - ghalf_size, py + ghalf_size
425 423
426 for laser in self.lasers: 424 for laser in self.lasers:
427 if laser.check_collision(player_pos): 425 if laser.check_collision(player_pos):
428 if player_state.invulnerable_time == 0: 426 if player.invulnerable_time == 0:
429 player.collide() 427 player.collide()
430 elif laser.check_grazing(player_pos): 428 elif laser.check_grazing(player_pos):
431 player_state.graze += 1 #TODO 429 player.graze += 1 #TODO
432 player_state.score += 500 #TODO 430 player.score += 500 #TODO
433 player.play_sound('graze') 431 player.play_sound('graze')
434 self.modify_difficulty(+6) #TODO 432 self.modify_difficulty(+6) #TODO
435 self.new_particle((px, py), 9, 192) #TODO 433 self.new_particle((px, py), 9, 192) #TODO
436 434
437 for bullet in self.bullets: 435 for bullet in self.bullets:
445 by1, by2 = by - bhalf_height, by + bhalf_height 443 by1, by2 = by - bhalf_height, by + bhalf_height
446 444
447 if not (bx2 < px1 or bx1 > px2 445 if not (bx2 < px1 or bx1 > px2
448 or by2 < py1 or by1 > py2): 446 or by2 < py1 or by1 > py2):
449 bullet.collide() 447 bullet.collide()
450 if player_state.invulnerable_time == 0: 448 if player.invulnerable_time == 0:
451 player.collide() 449 player.collide()
452 450
453 elif not bullet.grazed and not (bx2 < gx1 or bx1 > gx2 451 elif not bullet.grazed and not (bx2 < gx1 or bx1 > gx2
454 or by2 < gy1 or by1 > gy2): 452 or by2 < gy1 or by1 > gy2):
455 bullet.grazed = True 453 bullet.grazed = True
456 player_state.graze += 1 454 player.graze += 1
457 player_state.score += 500 # found experimentally 455 player.score += 500 # found experimentally
458 player.play_sound('graze') 456 player.play_sound('graze')
459 self.modify_difficulty(+6) 457 self.modify_difficulty(+6)
460 self.new_particle((px, py), 9, 192) #TODO: find the real size and range. 458 self.new_particle((px, py), 9, 192) #TODO: find the real size and range.
461 #TODO: display a static particle during one frame at 459 #TODO: display a static particle during one frame at
462 # 12 pixels of the player, in the axis of the “collision”. 460 # 12 pixels of the player, in the axis of the “collision”.
465 if self.friendly_fire and len(self.players) > 1: 463 if self.friendly_fire and len(self.players) > 1:
466 for bullet in self.players_bullets: 464 for bullet in self.players_bullets:
467 if bullet.state != LAUNCHED: 465 if bullet.state != LAUNCHED:
468 continue 466 continue
469 467
470 if bullet.player == player_state.number: 468 if bullet.player == player.number:
471 continue 469 continue
472 470
473 bhalf_width = bullet.hitbox[0] 471 bhalf_width = bullet.hitbox[0]
474 bhalf_height = bullet.hitbox[1] 472 bhalf_height = bullet.hitbox[1]
475 bx, by = bullet.x, bullet.y 473 bx, by = bullet.x, bullet.y
477 by1, by2 = by - bhalf_height, by + bhalf_height 475 by1, by2 = by - bhalf_height, by + bhalf_height
478 476
479 if not (bx2 < px1 or bx1 > px2 477 if not (bx2 < px1 or bx1 > px2
480 or by2 < py1 or by1 > py2): 478 or by2 < py1 or by1 > py2):
481 bullet.collide() 479 bullet.collide()
482 if player_state.invulnerable_time == 0: 480 if player.invulnerable_time == 0:
483 player.collide() 481 player.collide()
484 482
485 for plaser in self.players_lasers: 483 for plaser in self.players_lasers:
486 if not plaser: 484 if not plaser:
487 continue 485 continue
490 lx, ly = plaser.x, plaser.y * 2. 488 lx, ly = plaser.x, plaser.y * 2.
491 lx1, lx2 = lx - lhalf_width, lx + lhalf_width 489 lx1, lx2 = lx - lhalf_width, lx + lhalf_width
492 490
493 if not (lx2 < px1 or lx1 > px2 491 if not (lx2 < px1 or lx1 > px2
494 or ly < py1): 492 or ly < py1):
495 if player_state.invulnerable_time == 0: 493 if player.invulnerable_time == 0:
496 player.collide() 494 player.collide()
497 495
498 #TODO: is it the right place? 496 #TODO: is it the right place?
499 if py < 128 and player_state.power >= 128: #TODO: check py. 497 if py < 128 and player.power >= 128: #TODO: check py.
500 self.autocollect(player) 498 self.autocollect(player)
501 499
502 ihalf_size = <double>player.sht.item_hitbox 500 ihalf_size = <double>player.sht.item_hitbox
503 for item in self.items: 501 for item in self.items:
504 bx, by = item.x, item.y 502 bx, by = item.x, item.y
592 filtered.append(element) 590 filtered.append(element)
593 return filtered 591 return filtered
594 592
595 593
596 def select_player_key(player): 594 def select_player_key(player):
597 return (player.state.score, player.state.character) 595 return (player.score, player.character)