Mercurial > touhou
comparison pytouhou/game/enemy.pyx @ 468:feecdb4a8928
Add “except *” to cdef void functions, and type some more.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 12 Sep 2013 15:47:08 +0200 |
parents | 3bc37791f0a2 |
children | 06f0eeb519bb |
comparison
equal
deleted
inserted
replaced
467:5bb7d2c0ff46 | 468:feecdb4a8928 |
---|---|
157 self.bullet_launch_timer = 0 | 157 self.bullet_launch_timer = 0 |
158 | 158 |
159 player = self.select_player() | 159 player = self.select_player() |
160 | 160 |
161 if type_ in (67, 69, 71): | 161 if type_ in (67, 69, 71): |
162 launch_angle += self.get_player_angle(player, launch_pos) | 162 launch_angle += self.get_player_angle(launch_pos, player) |
163 if type_ == 71 and bullets_per_shot % 2 or type_ in (69, 70) and not bullets_per_shot % 2: | 163 if type_ == 71 and bullets_per_shot % 2 or type_ in (69, 70) and not bullets_per_shot % 2: |
164 launch_angle += pi / bullets_per_shot | 164 launch_angle += pi / bullets_per_shot |
165 if type_ != 75: | 165 if type_ != 75: |
166 launch_angle -= angle * (bullets_per_shot - 1) / 2. | 166 launch_angle -= angle * (bullets_per_shot - 1) / 2. |
167 | 167 |
198 grazing_delay, grazing_extra_duration, unknown, | 198 grazing_delay, grazing_extra_duration, unknown, |
199 offset=None): | 199 offset=None): |
200 ox, oy = offset or self.bullet_launch_offset | 200 ox, oy = offset or self.bullet_launch_offset |
201 launch_pos = self.x + ox, self.y + oy | 201 launch_pos = self.x + ox, self.y + oy |
202 if variant == 86: | 202 if variant == 86: |
203 angle += self.get_player_angle(self.select_player(), launch_pos) | 203 angle += self.get_player_angle(launch_pos) |
204 laser = Laser(launch_pos, self._game.laser_types[laser_type], | 204 laser = Laser(launch_pos, self._game.laser_types[laser_type], |
205 sprite_idx_offset, angle, speed, | 205 sprite_idx_offset, angle, speed, |
206 start_offset, end_offset, max_length, width, | 206 start_offset, end_offset, max_length, width, |
207 start_duration, duration, end_duration, grazing_delay, | 207 start_duration, duration, end_duration, grazing_delay, |
208 grazing_extra_duration, self._game) | 208 grazing_extra_duration, self._game) |
209 self._game.lasers.append(laser) | 209 self._game.lasers.append(laser) |
210 self.laser_by_id[self.current_laser_id] = laser | 210 self.laser_by_id[self.current_laser_id] = laser |
211 | 211 |
212 | 212 |
213 cpdef select_player(self, players=None): | 213 cpdef Player select_player(self, list players=None): |
214 return (players or self._game.players)[0] #TODO | 214 if players is None: |
215 | 215 players = self._game.players |
216 | 216 return players[0] #TODO |
217 cpdef get_player_angle(self, player=None, pos=None): | 217 |
218 player_state = (player or self.select_player()).state | 218 |
219 cpdef double get_player_angle(self, tuple pos=None, Player player=None): | |
220 cdef double x, y | |
221 if player is None: | |
222 player = self.select_player() | |
219 x, y = pos or (self.x, self.y) | 223 x, y = pos or (self.x, self.y) |
220 return atan2(player_state.y - y, player_state.x - x) | 224 return atan2(player.state.y - y, player.state.x - x) |
221 | 225 |
222 | 226 |
223 cpdef set_anim(self, index): | 227 cpdef set_anim(self, index): |
224 entry = 0 if index in self._anms[0].scripts else 1 | 228 entry = 0 if index in self._anms[0].scripts else 1 |
225 self.sprite = Sprite() | 229 self.sprite = Sprite() |
293 return False | 297 return False |
294 return True | 298 return True |
295 | 299 |
296 | 300 |
297 cdef void check_collisions(self): | 301 cdef void check_collisions(self): |
302 cdef Bullet bullet | |
303 cdef Player player | |
298 cdef long damages | 304 cdef long damages |
299 cdef double half_size[2], bx, by, lx, ly, px, py, phalf_size | 305 cdef double half_size[2], lx, ly, phalf_size |
300 | 306 |
301 # Check for collisions | 307 # Check for collisions |
302 ex, ey = self.x, self.y | 308 ex, ey = self.x, self.y |
303 ehalf_size_x = self.hitbox_half_size[0] | 309 ehalf_size_x = self.hitbox_half_size[0] |
304 ehalf_size_y = self.hitbox_half_size[1] | 310 ehalf_size_y = self.hitbox_half_size[1] |
449 self.life = 0 #TODO: do this next frame? Bypass self.touchable? | 455 self.life = 0 #TODO: do this next frame? Bypass self.touchable? |
450 else: | 456 else: |
451 raise Exception('What the hell, man!') | 457 raise Exception('What the hell, man!') |
452 | 458 |
453 | 459 |
454 cpdef update(self): | 460 cdef void update(self): |
455 cdef double x, y, speed | 461 cdef double x, y, speed |
456 | 462 |
457 if self.process: | 463 if self.process is not None: |
458 self.process.run_iteration() | 464 self.process.run_iteration() |
459 | 465 |
460 x, y = self.x, self.y | 466 x, y = self.x, self.y |
461 | 467 |
462 if self.update_mode == 1: | 468 if self.update_mode == 1: |