changeset 62:1f591adcea04

Fix animation determination (ins_98 stuff) and some interpolation functions
author Thibaut Girka <thib@sitedethib.com>
date Wed, 24 Aug 2011 21:16:14 +0200
parents 0886994029e4
children 8527fe640844
files pytouhou/game/eclrunner.py pytouhou/game/enemymanager.py pytouhou/utils/interpolator.py
diffstat 3 files changed, 24 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/eclrunner.py
+++ b/pytouhou/game/eclrunner.py
@@ -334,7 +334,13 @@ class ECLRunner(object):
 
     @instruction(57)
     def move_to(self, duration, x, y, z):
-        self._enemy.move_to(duration, x, y, z)
+        self._enemy.move_to(duration, x, y, z, lambda x: 2. * x - x ** 2)
+
+
+    @instruction(59)
+    def move_to2(self, duration, x, y, z):
+        #TODO: not accurate
+        self._enemy.move_to(duration, x, y, z, lambda x: 1.0014 * x ** 2 - 0.0012 * x)
 
 
     @instruction(61)
--- a/pytouhou/game/enemymanager.py
+++ b/pytouhou/game/enemymanager.py
@@ -97,14 +97,16 @@ class Enemy(object):
         self.interpolator.set_interpolation_start(self.frame, (x, y))
 
 
-    def move_to(self, duration, x, y, z):
+    def move_to(self, duration, x, y, z, formula):
         if not self.interpolator:
-            self.interpolator = Interpolator((self.x, self.y))
+            self.interpolator = Interpolator((self.x, self.y), formula)
             self.interpolator.set_interpolation_start(self.frame, (self.x, self.y))
-        self.interpolator.set_interpolation_end(self.frame + duration, (x, y))
+            self.interpolator.set_interpolation_end(self.frame + duration - 1, (x, y))
 
 
     def stop_in(self, duration):
+        #TODO: interpolation method and start/stop frame
+        # See 97 vs 98 anim conflict
         if not self.speed_interpolator:
             self.speed_interpolator = Interpolator((self.speed,))
             self.speed_interpolator.set_interpolation_start(self.frame, (self.speed,))
@@ -171,14 +173,18 @@ class Enemy(object):
             #TODO: is that really how it works? Almost.
             # Sprite determination is done only once per changement, and is
             # superseeded by ins_97.
-            if x < self.x:
-                self.set_anim(self.movement_dependant_sprites[2])
+            end_left, end_right, left, right = self.movement_dependant_sprites
+            if x < self.x and self.direction != -1:
+                self.set_anim(left)
                 self.direction = -1
-            elif x > self.x:
-                self.set_anim(self.movement_dependant_sprites[3])
+                print('left')
+            elif x > self.x and self.direction != +1:
+                self.set_anim(right)
                 self.direction = +1
-            elif self.direction is not None:
-                self.set_anim(self.movement_dependant_sprites[{-1: 0, +1:1}[self.direction]])
+                print(left, right)
+                print('right')
+            elif x == self.x and self.direction is not None:
+                self.set_anim({-1: end_left, +1: end_right}[self.direction])
                 self.direction = None
 
 
--- a/pytouhou/utils/interpolator.py
+++ b/pytouhou/utils/interpolator.py
@@ -48,7 +48,8 @@ class Interpolator(object):
 
     def update(self, frame):
         self._frame = frame
-        if frame >= self.end_frame - 1:
+        if frame >= self.end_frame - 1: #XXX: skip the last interpolation step
+            # This bug is replicated from the original game
             self.values = tuple(self.end_values)
             self.start_values = tuple(self.end_values)
             self.start_frame = frame