comparison pytouhou/game/enemy.pyx @ 494:6be9c99a3a24

Merge PlayerState into Player, fix player respawn position.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 14 Oct 2013 12:11:01 +0200
parents 887de1309491
children 3da7395f39e3
comparison
equal deleted inserted replaced
493:26c082870dcf 494:6be9c99a3a24
219 cpdef double get_player_angle(self, tuple pos=None, Player player=None): 219 cpdef double get_player_angle(self, tuple pos=None, Player player=None):
220 cdef double x, y 220 cdef double x, y
221 if player is None: 221 if player is None:
222 player = self.select_player() 222 player = self.select_player()
223 x, y = pos or (self.x, self.y) 223 x, y = pos or (self.x, self.y)
224 return atan2(player.state.y - y, player.state.x - x) 224 return atan2(player.y - y, player.x - x)
225 225
226 226
227 cpdef set_anim(self, index): 227 cpdef set_anim(self, index):
228 entry = 0 if index in self._anms[0].scripts else 1 228 entry = 0 if index in self._anms[0].scripts else 1
229 self.sprite = Sprite() 229 self.sprite = Sprite()
348 # Check for enemy-player collisions 348 # Check for enemy-player collisions
349 ex1, ex2 = ex - ehalf_size_x * 2. / 3., ex + ehalf_size_x * 2. / 3. 349 ex1, ex2 = ex - ehalf_size_x * 2. / 3., ex + ehalf_size_x * 2. / 3.
350 ey1, ey2 = ey - ehalf_size_y * 2. / 3., ey + ehalf_size_y * 2. / 3. 350 ey1, ey2 = ey - ehalf_size_y * 2. / 3., ey + ehalf_size_y * 2. / 3.
351 if self.collidable: 351 if self.collidable:
352 for player in self._game.players: 352 for player in self._game.players:
353 px, py = player.state.x, player.state.y 353 px, py = player.x, player.y
354 phalf_size = player.sht.hitbox 354 phalf_size = player.sht.hitbox
355 px1, px2 = px - phalf_size, px + phalf_size 355 px1, px2 = px - phalf_size, px + phalf_size
356 py1, py2 = py - phalf_size, py + phalf_size 356 py1, py2 = py - phalf_size, py + phalf_size
357 357
358 #TODO: box-box or point-in-box? 358 #TODO: box-box or point-in-box?
362 player.collide() 362 player.collide()
363 363
364 # Adjust damages 364 # Adjust damages
365 damages = min(70, damages) 365 damages = min(70, damages)
366 score = (damages // 5) * 10 366 score = (damages // 5) * 10
367 self._game.players[0].state.score += score #TODO: better distribution amongst the players. 367 self._game.players[0].score += score #TODO: better distribution amongst the players.
368 368
369 if self.damageable: 369 if self.damageable:
370 if self._game.spellcard is not None: 370 if self._game.spellcard is not None:
371 #TODO: there is a division by 3, somewhere... where is it? 371 #TODO: there is a division by 3, somewhere... where is it?
372 if damages <= 7: 372 if damages <= 7:
386 death_flags = self.death_flags & 7 386 death_flags = self.death_flags & 7
387 387
388 self.die_anim() 388 self.die_anim()
389 389
390 #TODO: verify if the score is added with all the different flags. 390 #TODO: verify if the score is added with all the different flags.
391 self._game.players[0].state.score += self.die_score #TODO: better distribution amongst the players. 391 self._game.players[0].score += self.die_score #TODO: better distribution amongst the players.
392 392
393 #TODO: verify if that should really be there. 393 #TODO: verify if that should really be there.
394 if self.boss: 394 if self.boss:
395 self._game.change_bullets_into_bonus() 395 self._game.change_bullets_into_bonus()
396 396
538 self.handle_callbacks() 538 self.handle_callbacks()
539 539
540 self.frame += 1 540 self.frame += 1
541 541
542 542
543 def select_player_key(self, p): 543 def select_player_key(self, player):
544 return ((p.x - self.x) ** 2 + (p.y - self.y) ** 2, p.state.character) 544 return ((player.x - self.x) ** 2 + (player.y - self.y) ** 2, player.character)