comparison pytouhou/game/enemy.pyx @ 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 e35bef07290d
children e15672733c93
comparison
equal deleted inserted replaced
563:ab0a5580bc40 564:a0fa01cd9f70
185 self.bullet_launch_timer = 0 185 self.bullet_launch_timer = 0
186 186
187 player = self.select_player() 187 player = self.select_player()
188 188
189 if type_ in (67, 69, 71): 189 if type_ in (67, 69, 71):
190 launch_angle += self.get_player_angle(launch_pos, player) 190 launch_angle += self.get_angle(player, launch_pos)
191 if type_ == 71 and bullets_per_shot % 2 or type_ in (69, 70) and not bullets_per_shot % 2: 191 if type_ == 71 and bullets_per_shot % 2 or type_ in (69, 70) and not bullets_per_shot % 2:
192 launch_angle += pi / bullets_per_shot 192 launch_angle += pi / bullets_per_shot
193 if type_ != 75: 193 if type_ != 75:
194 launch_angle -= angle * (bullets_per_shot - 1) / 2. 194 launch_angle -= angle * (bullets_per_shot - 1) / 2.
195 195
230 if offset is None: 230 if offset is None:
231 offset = self.bullet_launch_offset 231 offset = self.bullet_launch_offset
232 ox, oy = offset 232 ox, oy = offset
233 launch_pos = self.x + ox, self.y + oy 233 launch_pos = self.x + ox, self.y + oy
234 if variant == 86: 234 if variant == 86:
235 angle += self.get_player_angle(launch_pos) 235 player = self.select_player()
236 angle += self.get_angle(player, launch_pos)
236 laser = Laser(launch_pos, self._game.laser_types[laser_type], 237 laser = Laser(launch_pos, self._game.laser_types[laser_type],
237 sprite_idx_offset, angle, speed, 238 sprite_idx_offset, angle, speed,
238 start_offset, end_offset, max_length, width, 239 start_offset, end_offset, max_length, width,
239 start_duration, duration, end_duration, grazing_delay, 240 start_duration, duration, end_duration, grazing_delay,
240 grazing_extra_duration, self._game) 241 grazing_extra_duration, self._game)
246 if players is None: 247 if players is None:
247 players = self._game.players 248 players = self._game.players
248 return min(players, key=self.select_player_key) 249 return min(players, key=self.select_player_key)
249 250
250 251
251 cpdef double get_player_angle(self, tuple pos=None, Player player=None): 252 cpdef double get_angle(self, Element target, tuple pos=None):
252 cdef double x, y 253 cdef double x, y
253 if player is None:
254 player = self.select_player()
255 x, y = pos or (self.x, self.y) 254 x, y = pos or (self.x, self.y)
256 return atan2(player.y - y, player.x - x) 255 return atan2(target.y - y, target.x - x)
257 256
258 257
259 cpdef set_anim(self, index): 258 cpdef set_anim(self, index):
260 entry = 0 if index in self._anms[0].scripts else 1 259 entry = 0 if index in self._anms[0].scripts else 1
261 self.sprite = Sprite() 260 self.sprite = Sprite()