comparison pytouhou/game/player.py @ 235:e59bd7979ddc

Do a little cleanup, and fix PCB SHT usage.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 31 Dec 2011 16:31:10 +0100
parents 2d35565b5608
children 741860192b56
comparison
equal deleted inserted replaced
234:3cbfa2c11dec 235:e59bd7979ddc
14 14
15 15
16 from pytouhou.game.sprite import Sprite 16 from pytouhou.game.sprite import Sprite
17 from pytouhou.vm.anmrunner import ANMRunner 17 from pytouhou.vm.anmrunner import ANMRunner
18 from pytouhou.game.bullettype import BulletType 18 from pytouhou.game.bullettype import BulletType
19 from pytouhou.game.bullet import Bullet
19 20
20 from math import pi 21 from math import pi
21 22
22 23
23 class PlayerState(object): 24 class PlayerState(object):
41 42
42 self.power_bonus = 0 # Never goes over 30. 43 self.power_bonus = 0 # Never goes over 30.
43 44
44 45
45 class Player(object): 46 class Player(object):
46 def __init__(self, state, game, anm_wrapper, hitbox_size=2.5, graze_hitbox_size=42., speeds=None): 47 def __init__(self, state, game, anm_wrapper):
47 self._sprite = None 48 self._sprite = None
48 self._anmrunner = None 49 self._anmrunner = None
49 self._game = game 50 self._game = game
50 self.anm_wrapper = anm_wrapper 51 self.anm_wrapper = anm_wrapper
51 52
52 self.speeds = speeds 53 self.speeds = (self.sht.horizontal_vertical_speed,
53 54 self.sht.diagonal_speed,
54 self.hitbox_size = hitbox_size 55 self.sht.horizontal_vertical_focused_speed,
55 self.hitbox_half_size = self.hitbox_size / 2. 56 self.sht.diagonal_focused_speed)
56 self.graze_hitbox_size = graze_hitbox_size 57
57 self.graze_hitbox_half_size = self.graze_hitbox_size / 2. 58 self.hitbox_half_size = self.sht.hitbox / 2.
58 59 self.graze_hitbox_half_size = self.sht.graze_hitbox / 2.
59 self.bullet_type = BulletType(anm_wrapper, 64, 96, 0, 0, 0, hitbox_size=4) 60
60 self.bullet_launch_interval = 5
61 self.bullet_speed = 12.
62 self.bullet_launch_angle = -pi/2
63 self.fire_time = 0 61 self.fire_time = 0
64 62
65 self.state = state 63 self.state = state
66 self.direction = None 64 self.direction = None
67 65
103 self.state.focused = True 101 self.state.focused = True
104 102
105 103
106 def stop_focusing(self): 104 def stop_focusing(self):
107 self.state.focused = False 105 self.state.focused = False
106
107
108 def fire(self):
109 sht = self.focused_sht if self.state.focused else self.sht
110 power = min(power for power in sht.shots if self.state.power < power)
111
112 bullets = self._game.players_bullets
113 nb_bullets_max = self._game.nb_bullets_max
114
115 for shot in sht.shots[power]:
116 if shot.type == 3: # TODO: Lasers aren't implemented yet
117 continue
118
119 if (self.fire_time + shot.delay) % shot.interval != 0:
120 continue
121
122 if nb_bullets_max is not None and len(bullets) == nb_bullets_max:
123 break
124
125 origin = self.orbs[shot.orb - 1] if shot.orb else self
126 x = origin.x + shot.pos[0]
127 y = origin.y + shot.pos[1]
128
129 #TODO: find a better way to do that.
130 bullet_type = BulletType(self.anm_wrapper, shot.sprite % 256,
131 shot.sprite % 256 + 32, #TODO: find the real cancel anim
132 0, 0, 0, 0.)
133 if shot.type == 2:
134 #TODO: triple-check acceleration!
135 bullets.append(Bullet((x, y), bullet_type, 0,
136 shot.angle, shot.speed,
137 (-1, 0, 0, 0, 0.15, -pi/2., 0., 0.),
138 16, self, self._game, player_bullet=True,
139 damage=shot.damage, hitbox=shot.hitbox))
140 #TODO: types 1 and 4
141 else:
142 bullets.append(Bullet((x, y), bullet_type, 0,
143 shot.angle, shot.speed,
144 (0, 0, 0, 0, 0., 0., 0., 0.),
145 0, self, self._game, player_bullet=True,
146 damage=shot.damage, hitbox=shot.hitbox))
108 147
109 148
110 def update(self, keystate): 149 def update(self, keystate):
111 if self.death_time == 0 or self._game.frame - self.death_time > 60: 150 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] 151 speed, diag_speed = self.speeds[2:] if self.state.focused else self.speeds[:2]