Mercurial > touhou
diff pytouhou/game/enemy.py @ 166:dcf32488a2c9
Better enemy death, with animation and (hopefully) correct flags handling.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 18 Oct 2011 13:17:23 -0700 |
parents | 4684d311a32d |
children | e483b5a7e84b |
line wrap: on
line diff
--- a/pytouhou/game/enemy.py +++ b/pytouhou/game/enemy.py @@ -21,6 +21,24 @@ from pytouhou.game.item import Item from math import cos, sin, atan2, pi +class Effect(object): + def __init__(self, pos, index, anm_wrapper): + self._sprite = Sprite() + self._anmrunner = ANMRunner(anm_wrapper, index, self._sprite) + self._anmrunner.run_frame() + self._removed = False + + self.x, self.y = pos + + def update(self): + if self._anmrunner and not self._anmrunner.run_frame(): + self._anmrunner = None + + if self._sprite: + if self._sprite._removed: + self._sprite = None + + class Enemy(object): def __init__(self, pos, life, _type, bonus_dropped, anm_wrapper, game): self._game = game @@ -144,21 +162,18 @@ class Enemy(object): self._anmrunner.run_frame() - def collide(self): - #TODO: animation - #TODO: doesn’t always kill herself (a boss for example), search how - self._removed = True + def on_attack(self, bullet): + if self.damageable: + self.life -= bullet._bullet_type.damage - def killed(self): - if self.touchable: - if 0 <= self._bonus_dropped < 256: - self._game.drop_bonus(self.x, self.y, 0) - elif -256 <= self._bonus_dropped < 0: - pass #TODO: should be random, search how it is done. + def on_collide(self): + self.life -= 80 # found experimentally + - #TODO: use self.death_flags - self._removed = True + def die_anim(self): + eff00 = self._game.resource_loader.get_anm_wrapper(('eff00.anm',)) + self._game.effects.append(Effect((self.x, self.y), self.death_anim, eff00)) def set_pos(self, x, y, z): @@ -271,8 +286,5 @@ class Enemy(object): if self.bullet_launch_timer == self.bullet_launch_interval: self.fire() - if self.life <= 0: - self.killed() - self.frame += 1