# HG changeset patch # User Emmanuel Gil Peyrot # Date 1402591261 -7200 # Node ID a0fa01cd9f70f4dc8c40d8a7d01fb102c2dd6fd3 # Parent ab0a5580bc40fb4b0f9bf3359be35e249de2cdfb Make Enemy.get_angle able to target any Element, not only Player. diff --git a/pytouhou/game/enemy.pxd b/pytouhou/game/enemy.pxd --- 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 * diff --git a/pytouhou/game/enemy.pyx b/pytouhou/game/enemy.pyx --- 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): diff --git a/pytouhou/vm/eclrunner.py b/pytouhou/vm/eclrunner.py --- 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)