Mercurial > touhou
comparison pytouhou/game/player.py @ 220:0595315d3880
Fix SHT handling; change a few things to be closer to ZUN’s mind; and first stub of PCB support.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 18 Dec 2011 14:14:32 +0100 |
parents | a765ef90c2b0 |
children | 2d35565b5608 |
comparison
equal
deleted
inserted
replaced
219:091301805cce | 220:0595315d3880 |
---|---|
18 from pytouhou.game.bullettype import BulletType | 18 from pytouhou.game.bullettype import BulletType |
19 | 19 |
20 from math import pi | 20 from math import pi |
21 | 21 |
22 | 22 |
23 SQ2 = 2. ** 0.5 / 2. | |
24 | |
25 | |
26 class PlayerState(object): | 23 class PlayerState(object): |
27 def __init__(self, character=0, score=0, power=0, lives=0, bombs=0): | 24 def __init__(self, character=0, score=0, power=0, lives=0, bombs=0): |
28 self.character = character # ReimuA/ReimuB/MarisaA/MarisaB/... | 25 self.character = character # ReimuA/ReimuB/MarisaA/MarisaB/... |
29 | 26 |
30 self.score = score | 27 self.score = score |
44 | 41 |
45 self.power_bonus = 0 # Never goes over 30. | 42 self.power_bonus = 0 # Never goes over 30. |
46 | 43 |
47 | 44 |
48 class Player(object): | 45 class Player(object): |
49 def __init__(self, state, game, anm_wrapper, speed=4., hitbox_size=2.5, graze_hitbox_size=42.): | 46 def __init__(self, state, game, anm_wrapper, hitbox_size=2.5, graze_hitbox_size=42., speeds=None): |
50 self._sprite = None | 47 self._sprite = None |
51 self._anmrunner = None | 48 self._anmrunner = None |
52 self._game = game | 49 self._game = game |
53 self.anm_wrapper = anm_wrapper | 50 self.anm_wrapper = anm_wrapper |
54 | 51 |
55 self.speed = speed | 52 self.speeds = speeds |
56 self.focused_speed = speed/2. | |
57 | 53 |
58 self.hitbox_size = hitbox_size | 54 self.hitbox_size = hitbox_size |
59 self.hitbox_half_size = self.hitbox_size / 2. | 55 self.hitbox_half_size = self.hitbox_size / 2. |
60 self.graze_hitbox_size = graze_hitbox_size | 56 self.graze_hitbox_size = graze_hitbox_size |
61 self.graze_hitbox_half_size = self.graze_hitbox_size / 2. | 57 self.graze_hitbox_half_size = self.graze_hitbox_size / 2. |
62 | 58 |
63 self.bullet_type = BulletType(anm_wrapper, 64, 96, 0, 0, 0, hitbox_size=4, damage=48) | 59 self.bullet_type = BulletType(anm_wrapper, 64, 96, 0, 0, 0, hitbox_size=4) |
64 self.bullet_launch_interval = 5 | 60 self.bullet_launch_interval = 5 |
65 self.bullet_speed = 12. | 61 self.bullet_speed = 12. |
66 self.bullet_launch_angle = -pi/2 | 62 self.bullet_launch_angle = -pi/2 |
67 self.fire_time = 0 | 63 self.fire_time = 0 |
68 | 64 |
111 self.state.focused = False | 107 self.state.focused = False |
112 | 108 |
113 | 109 |
114 def update(self, keystate): | 110 def update(self, keystate): |
115 if self.death_time == 0 or self._game.frame - self.death_time > 60: | 111 if self.death_time == 0 or self._game.frame - self.death_time > 60: |
112 speed, diag_speed = self.speeds[2:] if self.state.focused else self.speeds[:2] | |
116 try: | 113 try: |
117 dx, dy = {16: (0.0, -1.0), 32: (0.0, 1.0), 64: (-1.0, 0.0), 128: (1.0, 0.0), | 114 dx, dy = {16: (0.0, -speed), 32: (0.0, speed), 64: (-speed, 0.0), 128: (speed, 0.0), |
118 16|64: (-SQ2, -SQ2), 16|128: (SQ2, -SQ2), | 115 16|64: (-diag_speed, -diag_speed), 16|128: (diag_speed, -diag_speed), |
119 32|64: (-SQ2, SQ2), 32|128: (SQ2, SQ2)}[keystate & (16|32|64|128)] | 116 32|64: (-diag_speed, diag_speed), 32|128: (diag_speed, diag_speed)}[keystate & (16|32|64|128)] |
120 except KeyError: | 117 except KeyError: |
121 speed = 0.0 | |
122 dx, dy = 0.0, 0.0 | 118 dx, dy = 0.0, 0.0 |
123 else: | |
124 speed = self.focused_speed if keystate & 4 else self.speed | |
125 dx, dy = dx * speed, dy * speed | |
126 | 119 |
127 if dx < 0 and self.direction != -1: | 120 if dx < 0 and self.direction != -1: |
128 self.set_anim(1) | 121 self.set_anim(1) |
129 self.direction = -1 | 122 self.direction = -1 |
130 elif dx > 0 and self.direction != +1: | 123 elif dx > 0 and self.direction != +1: |