Mercurial > touhou
comparison pytouhou/game/enemy.py @ 251:4b549894ef6b
Change position/speed interpoletor handling to match the original game more closely.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 22 Jan 2012 14:24:38 +0100 |
parents | 77b83064b57e |
children | ea4832f843aa |
comparison
equal
deleted
inserted
replaced
250:cd4800154c9b | 251:4b549894ef6b |
---|---|
65 self.death_anim = 0 | 65 self.death_anim = 0 |
66 self.movement_dependant_sprites = None | 66 self.movement_dependant_sprites = None |
67 self.direction = None | 67 self.direction = None |
68 self.interpolator = None #TODO | 68 self.interpolator = None #TODO |
69 self.speed_interpolator = None | 69 self.speed_interpolator = None |
70 self.update_mode = 0 | |
70 self.angle = 0. | 71 self.angle = 0. |
71 self.speed = 0. | 72 self.speed = 0. |
72 self.rotation_speed = 0. | 73 self.rotation_speed = 0. |
73 self.acceleration = 0. | 74 self.acceleration = 0. |
74 | 75 |
193 self.aux_anm[number] = Effect((self.x, self.y), script, self._anm_wrapper) | 194 self.aux_anm[number] = Effect((self.x, self.y), script, self._anm_wrapper) |
194 | 195 |
195 | 196 |
196 def set_pos(self, x, y, z): | 197 def set_pos(self, x, y, z): |
197 self.x, self.y = x, y | 198 self.x, self.y = x, y |
199 self.update_mode = 1 | |
198 self.interpolator = Interpolator((x, y)) | 200 self.interpolator = Interpolator((x, y)) |
199 self.interpolator.set_interpolation_start(self._game.frame, (x, y)) | 201 self.interpolator.set_interpolation_start(self._game.frame, (x, y)) |
200 | 202 |
201 | 203 |
202 def move_to(self, duration, x, y, z, formula): | 204 def move_to(self, duration, x, y, z, formula): |
203 if not self.interpolator: | 205 frame = self._game.frame |
204 frame = self._game.frame | 206 self.speed_interpolator = None |
205 self.interpolator = Interpolator((self.x, self.y), formula) | 207 self.update_mode = 1 |
206 self.interpolator.set_interpolation_start(frame, (self.x, self.y)) | 208 self.interpolator = Interpolator((self.x, self.y), formula) |
207 self.interpolator.set_interpolation_end(frame + duration - 1, (x, y)) | 209 self.interpolator.set_interpolation_start(frame, (self.x, self.y)) |
208 | 210 self.interpolator.set_interpolation_end(frame + duration - 1, (x, y)) |
209 self.speed = 0. | 211 |
210 self.angle = atan2(y - self.y, x - self.x) | 212 self.angle = atan2(y - self.y, x - self.x) |
211 | 213 |
212 | 214 |
213 def stop_in(self, duration, formula): | 215 def stop_in(self, duration, formula): |
214 if not self.speed_interpolator: | 216 frame = self._game.frame |
215 frame = self._game.frame | 217 self.interpolator = None |
216 self.speed_interpolator = Interpolator((self.speed,), formula) | 218 self.update_mode = 1 |
217 self.speed_interpolator.set_interpolation_start(frame, (self.speed,)) | 219 self.speed_interpolator = Interpolator((self.speed,), formula) |
218 self.speed_interpolator.set_interpolation_end(frame + duration - 1, (0.,)) | 220 self.speed_interpolator.set_interpolation_start(frame, (self.speed,)) |
219 | 221 self.speed_interpolator.set_interpolation_end(frame + duration - 1, (0.,)) |
220 self.speed = 0. | |
221 | 222 |
222 | 223 |
223 def is_visible(self, screen_width, screen_height): | 224 def is_visible(self, screen_width, screen_height): |
224 if self._sprite: | 225 if self._sprite: |
225 tx, ty, tw, th = self._sprite.texcoords | 226 tx, ty, tw, th = self._sprite.texcoords |
294 self.life -= damages | 295 self.life -= damages |
295 | 296 |
296 | 297 |
297 def update(self): | 298 def update(self): |
298 x, y = self.x, self.y | 299 x, y = self.x, self.y |
299 if self.interpolator: | 300 |
300 self.interpolator.update(self._game.frame) | 301 if self.update_mode == 1: |
301 x, y = self.interpolator.values | 302 speed = 0.0 |
302 | 303 if self.interpolator: |
303 self.speed += self.acceleration #TODO: units? Execution order? | 304 self.interpolator.update(self._game.frame) |
304 self.angle += self.rotation_speed #TODO: units? Execution order? | 305 x, y = self.interpolator.values |
305 | 306 if self.speed_interpolator: |
306 | 307 self.speed_interpolator.update(self._game.frame) |
307 if self.speed_interpolator: | 308 speed, = self.speed_interpolator.values |
308 self.speed_interpolator.update(self._game.frame) | 309 else: |
309 self.speed, = self.speed_interpolator.values | 310 speed = self.speed |
310 | 311 self.speed += self.acceleration |
311 | 312 self.angle += self.rotation_speed |
312 dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed | 313 |
314 dx, dy = cos(self.angle) * speed, sin(self.angle) * speed | |
313 if self._type & 2: | 315 if self._type & 2: |
314 x -= dx | 316 x -= dx |
315 else: | 317 else: |
316 x += dx | 318 x += dx |
317 y += dy | 319 y += dy |