changeset 279:3539520fff93

Fix sprite rotation/translation. ANM translations are done *after* rotation, lasers are handled differently.
author Thibaut Girka <thib@sitedethib.com>
date Wed, 08 Feb 2012 18:43:39 +0100
parents 615c0bb6064b
children e04c3e1957c8
files pytouhou/game/laser.py pytouhou/ui/sprite.pyx pytouhou/vm/eclrunner.py
diffstat 3 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/laser.py
+++ b/pytouhou/game/laser.py
@@ -22,7 +22,7 @@ STARTING, STARTED, STOPPING = range(3)
 
 
 class Laser(object):
-    def __init__(self, pos, laser_type, sprite_idx_offset,
+    def __init__(self, base_pos, laser_type, sprite_idx_offset,
                        angle, speed, start_offset, end_offset, max_length, width,
                        start_duration, duration, stop_duration,
                        grazing_delay, grazing_extra_duration,
@@ -45,7 +45,8 @@ class Laser(object):
         self.grazing_extra_duration = grazing_extra_duration
 
         self.sprite_idx_offset = sprite_idx_offset
-        self.x, self.y = pos
+        self.base_pos = base_pos
+        self.x, self.y = 0, 0
         self.angle = angle
         self.speed = speed
         self.start_offset = start_offset
@@ -109,8 +110,8 @@ class Laser(object):
             else:
                 width = self.width * (1. - float(self.frame) / self.stop_duration) #TODO
 
-        self._sprite.allow_dest_offset = True
-        self._sprite.dest_offset = (0., self.end_offset - length / 2., 0.)
+        offset = self.end_offset - length / 2.
+        self.x, self.y = self.base_pos[0] + offset * cos(self.angle), self.base_pos[1] + offset * sin(self.angle)
         self._sprite.width_override = width or 0.01 #TODO
         self._sprite.height_override = length or 0.01 #TODO
 
--- a/pytouhou/ui/sprite.pyx
+++ b/pytouhou/ui/sprite.pyx
@@ -38,8 +38,6 @@ cpdef object get_sprite_rendering_data(o
     if sprite.mirrored:
         vertmat.flip()
 
-    if sprite.allow_dest_offset:
-        vertmat.translate(sprite.dest_offset[0], sprite.dest_offset[1], sprite.dest_offset[2])
     rx, ry, rz = sprite.rotations_3d
     if sprite.automatic_orientation:
         rz += pi/2. - sprite.angle
@@ -53,6 +51,8 @@ cpdef object get_sprite_rendering_data(o
             vertmat.rotate_y(ry)
         if rz:
             vertmat.rotate_z(-rz) #TODO: minus, really?
+    if sprite.allow_dest_offset:
+        vertmat.translate(sprite.dest_offset[0], sprite.dest_offset[1], sprite.dest_offset[2])
     if sprite.corner_relative_placement: # Reposition
         vertmat.translate(width / 2., height / 2., 0.)
 
--- a/pytouhou/vm/eclrunner.py
+++ b/pytouhou/vm/eclrunner.py
@@ -767,7 +767,7 @@ class ECLRunner(object):
         except KeyError:
             pass #TODO
         else:
-            laser.x, laser.y = self._enemy.x + ox, self._enemy.y + oy
+            laser.base_pos = self._enemy.x + ox, self._enemy.y + oy
 
 
     @instruction(92)