# HG changeset patch # User Thibaut Girka # Date 1314213374 -7200 # Node ID 1f591adcea043fff7bcc8d4efa921c815014fca3 # Parent 0886994029e401e6d92eb885cbfc3fd79f710ba1 Fix animation determination (ins_98 stuff) and some interpolation functions diff --git a/pytouhou/game/eclrunner.py b/pytouhou/game/eclrunner.py --- 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) diff --git a/pytouhou/game/enemymanager.py b/pytouhou/game/enemymanager.py --- 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 diff --git a/pytouhou/utils/interpolator.py b/pytouhou/utils/interpolator.py --- 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