Mercurial > touhou
comparison pytouhou/game/player.py @ 206:eca53abdfeab
Fix ReimuA, and refactor Player a bit.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sat, 05 Nov 2011 19:43:11 +0100 |
parents | 8ec34c56fed0 |
children | a765ef90c2b0 |
comparison
equal
deleted
inserted
replaced
205:ee6dfd14a785 | 206:eca53abdfeab |
---|---|
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 | |
20 | 19 |
21 from math import pi | 20 from math import pi |
22 | 21 |
23 | 22 |
24 SQ2 = 2. ** 0.5 / 2. | 23 SQ2 = 2. ** 0.5 / 2. |
72 | 71 |
73 self.set_anim(0) | 72 self.set_anim(0) |
74 | 73 |
75 self.death_time = 0 | 74 self.death_time = 0 |
76 | 75 |
77 self.orb_dx_interpolator = None | |
78 self.orb_dy_interpolator = None | |
79 | |
80 | 76 |
81 @property | 77 @property |
82 def x(self): | 78 def x(self): |
83 return self.state.x | 79 return self.state.x |
84 | 80 |
87 def y(self): | 83 def y(self): |
88 return self.state.y | 84 return self.state.y |
89 | 85 |
90 | 86 |
91 def objects(self): | 87 def objects(self): |
92 return self.orbs if self.state.power >= 8 else [] | 88 return [] |
93 | 89 |
94 | 90 |
95 def set_anim(self, index): | 91 def set_anim(self, index): |
96 self._sprite = Sprite() | 92 self._sprite = Sprite() |
97 self._anmrunner = ANMRunner(self.anm_wrapper, index, self._sprite) | 93 self._anmrunner = ANMRunner(self.anm_wrapper, index, self._sprite) |
103 self.death_time = self._game.frame | 99 self.death_time = self._game.frame |
104 self._game.new_death((self.state.x, self.state.y), 2) | 100 self._game.new_death((self.state.x, self.state.y), 2) |
105 self._game.modify_difficulty(-1600) | 101 self._game.modify_difficulty(-1600) |
106 for i in range(16): | 102 for i in range(16): |
107 self._game.new_particle((self.state.x, self.state.y), 2, 4., 256) #TODO: find the real size and range. | 103 self._game.new_particle((self.state.x, self.state.y), 2, 4., 256) #TODO: find the real size and range. |
104 | |
105 | |
106 def start_focusing(self): | |
107 self.state.focused = True | |
108 | |
109 | |
110 def stop_focusing(self): | |
111 self.state.focused = False | |
108 | 112 |
109 | 113 |
110 def update(self, keystate): | 114 def update(self, keystate): |
111 if self.death_time == 0 or self._game.frame - self.death_time > 60: | 115 if self.death_time == 0 or self._game.frame - self.death_time > 60: |
112 try: | 116 try: |
132 | 136 |
133 self.state.x += dx | 137 self.state.x += dx |
134 self.state.y += dy | 138 self.state.y += dy |
135 | 139 |
136 if not self.state.focused and keystate & 4: | 140 if not self.state.focused and keystate & 4: |
137 self.orb_dx_interpolator = Interpolator((24,), self._game.frame, | 141 self.start_focusing() |
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: | 142 elif self.state.focused and not keystate & 4: |
144 self.orb_dx_interpolator = Interpolator((8,), self._game.frame, | 143 self.stop_focusing() |
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 | 144 |
162 if self.state.invulnerable_time > 0: | 145 if self.state.invulnerable_time > 0: |
163 self.state.invulnerable_time -= 1 | 146 self.state.invulnerable_time -= 1 |
164 | 147 |
165 m = self.state.invulnerable_time % 8 | 148 m = self.state.invulnerable_time % 8 |
224 bullet.cancel() | 207 bullet.cancel() |
225 | 208 |
226 if time > 90: # start the bullet hell again | 209 if time > 90: # start the bullet hell again |
227 self.death_time = 0 | 210 self.death_time = 0 |
228 | 211 |
229 | |
230 for orb in self.orbs: | |
231 orb.update() | |
232 | |
233 | |
234 self._anmrunner.run_frame() | 212 self._anmrunner.run_frame() |
235 | 213 |