Mercurial > touhou
comparison pytouhou/game/enemy.py @ 154:364935f6e313
Implement enemy killing.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 09 Oct 2011 16:55:18 -0700 |
parents | 86807b8a63bd |
children | ebfd328e700c |
comparison
equal
deleted
inserted
replaced
153:37df8c618c2e | 154:364935f6e313 |
---|---|
16 from pytouhou.utils.interpolator import Interpolator | 16 from pytouhou.utils.interpolator import Interpolator |
17 from pytouhou.vm.eclrunner import ECLRunner | 17 from pytouhou.vm.eclrunner import ECLRunner |
18 from pytouhou.vm.anmrunner import ANMRunner | 18 from pytouhou.vm.anmrunner import ANMRunner |
19 from pytouhou.game.sprite import Sprite | 19 from pytouhou.game.sprite import Sprite |
20 from pytouhou.game.bullet import Bullet | 20 from pytouhou.game.bullet import Bullet |
21 from pytouhou.game.item import Item | |
21 from math import cos, sin, atan2, pi | 22 from math import cos, sin, atan2, pi |
22 | 23 |
23 | 24 |
24 class Enemy(object): | 25 class Enemy(object): |
25 def __init__(self, pos, life, _type, anm_wrapper, game, pop_enemy): | 26 def __init__(self, pos, life, _type, bonus_dropped, anm_wrapper, game, pop_enemy): |
26 self._game = game | 27 self._game = game |
27 self._anm_wrapper = anm_wrapper | 28 self._anm_wrapper = anm_wrapper |
28 self._sprite = None | 29 self._sprite = None |
29 self._anmrunner = None | 30 self._anmrunner = None |
30 self._removed = False | 31 self._removed = False |
31 self._type = _type | 32 self._type = _type |
33 self._bonus_dropped = bonus_dropped | |
32 self._was_visible = False | 34 self._was_visible = False |
33 | 35 |
34 self.frame = 0 | 36 self.frame = 0 |
35 | 37 |
36 self.x, self.y = pos | 38 self.x, self.y = pos |
151 #TODO: doesn’t always kill herself (a boss for example), search how | 153 #TODO: doesn’t always kill herself (a boss for example), search how |
152 self._removed = True | 154 self._removed = True |
153 player.die() | 155 player.die() |
154 | 156 |
155 | 157 |
158 def killed(self): | |
159 if self.touchable: | |
160 if 0 <= self._bonus_dropped < 256: | |
161 self._game.drop_bonus(self.x, self.y, 0) | |
162 elif -256 <= self._bonus_dropped < 0: | |
163 pass #TODO: should be random, search how it is done. | |
164 | |
165 #TODO: use self.death_flags | |
166 self._removed = True | |
167 | |
168 | |
156 def set_pos(self, x, y, z): | 169 def set_pos(self, x, y, z): |
157 self.x, self.y = x, y | 170 self.x, self.y = x, y |
158 self.interpolator = Interpolator((x, y)) | 171 self.interpolator = Interpolator((x, y)) |
159 self.interpolator.set_interpolation_start(self._game.frame, (x, y)) | 172 self.interpolator.set_interpolation_start(self._game.frame, (x, y)) |
160 | 173 |
261 if self.bullet_launch_interval != 0: | 274 if self.bullet_launch_interval != 0: |
262 self.bullet_launch_timer += 1 | 275 self.bullet_launch_timer += 1 |
263 if self.bullet_launch_timer == self.bullet_launch_interval: | 276 if self.bullet_launch_timer == self.bullet_launch_interval: |
264 self.fire() | 277 self.fire() |
265 | 278 |
279 if self.life <= 0: | |
280 self.killed() | |
281 | |
266 self.frame += 1 | 282 self.frame += 1 |
267 | 283 |