Mercurial > touhou
comparison pytouhou/game/player.py @ 199:8ec34c56fed0
Implement orbs.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 31 Oct 2011 09:38:57 -0700 |
parents | 13918723d1bc |
children | eca53abdfeab |
comparison
equal
deleted
inserted
replaced
198:13918723d1bc | 199:8ec34c56fed0 |
---|---|
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.utils.interpolator import Interpolator | |
19 | 20 |
20 from math import pi | 21 from math import pi |
21 | 22 |
22 | 23 |
23 SQ2 = 2. ** 0.5 / 2. | 24 SQ2 = 2. ** 0.5 / 2. |
38 self.x = 192.0 | 39 self.x = 192.0 |
39 self.y = 384.0 | 40 self.y = 384.0 |
40 | 41 |
41 self.invulnerable_time = 240 | 42 self.invulnerable_time = 240 |
42 self.touchable = True | 43 self.touchable = True |
44 self.focused = False | |
43 | 45 |
44 self.power_bonus = 0 # Never goes over 30. | 46 self.power_bonus = 0 # Never goes over 30. |
45 | 47 |
46 | 48 |
47 class Player(object): | 49 class Player(object): |
70 | 72 |
71 self.set_anim(0) | 73 self.set_anim(0) |
72 | 74 |
73 self.death_time = 0 | 75 self.death_time = 0 |
74 | 76 |
77 self.orb_dx_interpolator = None | |
78 self.orb_dy_interpolator = None | |
79 | |
75 | 80 |
76 @property | 81 @property |
77 def x(self): | 82 def x(self): |
78 return self.state.x | 83 return self.state.x |
79 | 84 |
80 | 85 |
81 @property | 86 @property |
82 def y(self): | 87 def y(self): |
83 return self.state.y | 88 return self.state.y |
89 | |
90 | |
91 def objects(self): | |
92 return self.orbs if self.state.power >= 8 else [] | |
84 | 93 |
85 | 94 |
86 def set_anim(self, index): | 95 def set_anim(self, index): |
87 self._sprite = Sprite() | 96 self._sprite = Sprite() |
88 self._anmrunner = ANMRunner(self.anm_wrapper, index, self._sprite) | 97 self._anmrunner = ANMRunner(self.anm_wrapper, index, self._sprite) |
122 self.direction = None | 131 self.direction = None |
123 | 132 |
124 self.state.x += dx | 133 self.state.x += dx |
125 self.state.y += dy | 134 self.state.y += dy |
126 | 135 |
136 if not self.state.focused and keystate & 4: | |
137 self.orb_dx_interpolator = Interpolator((24,), self._game.frame, | |
138 (8,), self._game.frame + 8, | |
139 lambda x: x ** 2) | |
140 self.orb_dy_interpolator = Interpolator((0,), self._game.frame, | |
141 (-32,), self._game.frame + 8) | |
142 self.state.focused = True | |
143 elif self.state.focused and not keystate & 4: | |
144 self.orb_dx_interpolator = Interpolator((8,), self._game.frame, | |
145 (24,), self._game.frame + 8, | |
146 lambda x: x ** 2) | |
147 self.orb_dy_interpolator = Interpolator((-32,), self._game.frame, | |
148 (0,), self._game.frame + 8) | |
149 self.state.focused = False | |
150 | |
151 if self.orb_dx_interpolator: | |
152 self.orb_dx_interpolator.update(self._game.frame) | |
153 dx, = self.orb_dx_interpolator.values | |
154 self.orbs[0].offset_x = -dx | |
155 self.orbs[1].offset_x = dx | |
156 if self.orb_dy_interpolator: | |
157 self.orb_dy_interpolator.update(self._game.frame) | |
158 dy, = self.orb_dy_interpolator.values | |
159 self.orbs[0].offset_y = dy | |
160 self.orbs[1].offset_y = dy | |
161 | |
127 if self.state.invulnerable_time > 0: | 162 if self.state.invulnerable_time > 0: |
128 self.state.invulnerable_time -= 1 | 163 self.state.invulnerable_time -= 1 |
129 | 164 |
130 m = self.state.invulnerable_time % 8 | 165 m = self.state.invulnerable_time % 8 |
131 if m == 0: | 166 if m == 0: |
190 | 225 |
191 if time > 90: # start the bullet hell again | 226 if time > 90: # start the bullet hell again |
192 self.death_time = 0 | 227 self.death_time = 0 |
193 | 228 |
194 | 229 |
230 for orb in self.orbs: | |
231 orb.update() | |
232 | |
233 | |
195 self._anmrunner.run_frame() | 234 self._anmrunner.run_frame() |
196 | 235 |