changeset 564:a0fa01cd9f70

Make Enemy.get_angle able to target any Element, not only Player.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 12 Jun 2014 18:41:01 +0200
parents ab0a5580bc40
children 5f7f859a72f9
files pytouhou/game/enemy.pxd pytouhou/game/enemy.pyx pytouhou/vm/eclrunner.py
diffstat 3 files changed, 11 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/enemy.pxd
+++ b/pytouhou/game/enemy.pxd
@@ -39,7 +39,7 @@ cdef class Enemy(Element):
                     grazing_delay, grazing_extra_duration, unknown,
                     tuple offset=*)
     cpdef Player select_player(self, list players=*)
-    cpdef double get_player_angle(self, tuple pos=*, Player player=*) except 42
+    cpdef double get_angle(self, Element target, tuple pos=*) except 42
     cpdef set_anim(self, index)
     cdef void die_anim(self) except *
     cdef void drop_particles(self, long number, long color) except *
--- a/pytouhou/game/enemy.pyx
+++ b/pytouhou/game/enemy.pyx
@@ -187,7 +187,7 @@ cdef class Enemy(Element):
         player = self.select_player()
 
         if type_ in (67, 69, 71):
-            launch_angle += self.get_player_angle(launch_pos, player)
+            launch_angle += self.get_angle(player, launch_pos)
         if type_ == 71 and bullets_per_shot % 2 or type_ in (69, 70) and not bullets_per_shot % 2:
             launch_angle += pi / bullets_per_shot
         if type_ != 75:
@@ -232,7 +232,8 @@ cdef class Enemy(Element):
         ox, oy = offset
         launch_pos = self.x + ox, self.y + oy
         if variant == 86:
-            angle += self.get_player_angle(launch_pos)
+            player = self.select_player()
+            angle += self.get_angle(player, launch_pos)
         laser = Laser(launch_pos, self._game.laser_types[laser_type],
                       sprite_idx_offset, angle, speed,
                       start_offset, end_offset, max_length, width,
@@ -248,12 +249,10 @@ cdef class Enemy(Element):
         return min(players, key=self.select_player_key)
 
 
-    cpdef double get_player_angle(self, tuple pos=None, Player player=None):
+    cpdef double get_angle(self, Element target, tuple pos=None):
         cdef double x, y
-        if player is None:
-            player = self.select_player()
         x, y = pos or (self.x, self.y)
-        return atan2(player.y - y, player.x - x)
+        return atan2(target.y - y, target.x - x)
 
 
     cpdef set_anim(self, index):
--- a/pytouhou/vm/eclrunner.py
+++ b/pytouhou/vm/eclrunner.py
@@ -206,7 +206,8 @@ class ECLRunner(object):
                 player = self._enemy.select_player()
                 return player.y
             elif value == -10021:
-                return self._enemy.get_player_angle()
+                player = self._enemy.select_player()
+                return self._enemy.get_angle(player)
             elif value == -10022:
                 return self._enemy.frame
             elif value == -10024:
@@ -488,9 +489,11 @@ class ECLRunner(object):
     @instruction(51)
     def target_player(self, unknown, speed):
         #TODO: unknown
+        player = self._enemy.select_player()
+
         self._enemy.update_mode = 0
         self._enemy.speed = speed
-        self._enemy.angle = self._enemy.get_player_angle()
+        self._enemy.angle = self._enemy.get_angle(player)
 
 
     @instruction(52)