changeset 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 cd4800154c9b
children b5c7369abd7c
files pytouhou/game/enemy.py pytouhou/vm/eclrunner.py
diffstat 2 files changed, 33 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/enemy.py
+++ b/pytouhou/game/enemy.py
@@ -67,6 +67,7 @@ class Enemy(object):
         self.direction = None
         self.interpolator = None #TODO
         self.speed_interpolator = None
+        self.update_mode = 0
         self.angle = 0.
         self.speed = 0.
         self.rotation_speed = 0.
@@ -195,29 +196,29 @@ class Enemy(object):
 
     def set_pos(self, x, y, z):
         self.x, self.y = x, y
+        self.update_mode = 1
         self.interpolator = Interpolator((x, y))
         self.interpolator.set_interpolation_start(self._game.frame, (x, y))
 
 
     def move_to(self, duration, x, y, z, formula):
-        if not self.interpolator:
-            frame = self._game.frame
-            self.interpolator = Interpolator((self.x, self.y), formula)
-            self.interpolator.set_interpolation_start(frame, (self.x, self.y))
-            self.interpolator.set_interpolation_end(frame + duration - 1, (x, y))
+        frame = self._game.frame
+        self.speed_interpolator = None
+        self.update_mode = 1
+        self.interpolator = Interpolator((self.x, self.y), formula)
+        self.interpolator.set_interpolation_start(frame, (self.x, self.y))
+        self.interpolator.set_interpolation_end(frame + duration - 1, (x, y))
 
-            self.speed = 0.
-            self.angle = atan2(y - self.y, x - self.x)
+        self.angle = atan2(y - self.y, x - self.x)
 
 
     def stop_in(self, duration, formula):
-        if not self.speed_interpolator:
-            frame = self._game.frame
-            self.speed_interpolator = Interpolator((self.speed,), formula)
-            self.speed_interpolator.set_interpolation_start(frame, (self.speed,))
-            self.speed_interpolator.set_interpolation_end(frame + duration - 1, (0.,))
-
-            self.speed = 0.
+        frame = self._game.frame
+        self.interpolator = None
+        self.update_mode = 1
+        self.speed_interpolator = Interpolator((self.speed,), formula)
+        self.speed_interpolator.set_interpolation_start(frame, (self.speed,))
+        self.speed_interpolator.set_interpolation_end(frame + duration - 1, (0.,))
 
 
     def is_visible(self, screen_width, screen_height):
@@ -296,20 +297,21 @@ class Enemy(object):
 
     def update(self):
         x, y = self.x, self.y
-        if self.interpolator:
-            self.interpolator.update(self._game.frame)
-            x, y = self.interpolator.values
-
-        self.speed += self.acceleration #TODO: units? Execution order?
-        self.angle += self.rotation_speed #TODO: units? Execution order?
 
+        if self.update_mode == 1:
+            speed = 0.0
+            if self.interpolator:
+                self.interpolator.update(self._game.frame)
+                x, y = self.interpolator.values
+            if self.speed_interpolator:
+                self.speed_interpolator.update(self._game.frame)
+                speed, = self.speed_interpolator.values
+        else:
+            speed = self.speed
+            self.speed += self.acceleration
+            self.angle += self.rotation_speed
 
-        if self.speed_interpolator:
-            self.speed_interpolator.update(self._game.frame)
-            self.speed, = self.speed_interpolator.values
-
-
-        dx, dy = cos(self.angle) * self.speed, sin(self.angle) * self.speed
+        dx, dy = cos(self.angle) * speed, sin(self.angle) * speed
         if self._type & 2:
             x -= dx
         else:
--- a/pytouhou/vm/eclrunner.py
+++ b/pytouhou/vm/eclrunner.py
@@ -470,21 +470,25 @@ class ECLRunner(object):
 
     @instruction(45)
     def set_angle_speed(self, angle, speed):
+        self._enemy.update_mode = 0
         self._enemy.angle, self._enemy.speed = angle, speed
 
 
     @instruction(46)
     def set_rotation_speed(self, speed):
+        self._enemy.update_mode = 0
         self._enemy.rotation_speed = speed
 
 
     @instruction(47)
     def set_speed(self, speed):
+        self._enemy.update_mode = 0
         self._enemy.speed = speed
 
 
     @instruction(48)
     def set_acceleration(self, acceleration):
+        self._enemy.update_mode = 0
         self._enemy.acceleration = acceleration
 
 
@@ -519,6 +523,7 @@ class ECLRunner(object):
     @instruction(51)
     def target_player(self, unknown, speed):
         #TODO: unknown
+        self._enemy.update_mode = 0
         self._enemy.speed = speed
         self._enemy.angle = self._enemy.get_player_angle()