Mercurial > touhou
comparison pytouhou/game/enemy.py @ 304:f3099ebf4f61
Update attribute names to reflect the actual interface.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Tue, 13 Mar 2012 18:38:14 +0100 |
parents | da53bc29b94a |
children | 5930b33a0370 |
comparison
equal
deleted
inserted
replaced
303:647bde10353d | 304:f3099ebf4f61 |
---|---|
24 | 24 |
25 class Enemy(object): | 25 class Enemy(object): |
26 def __init__(self, pos, life, _type, bonus_dropped, die_score, anm_wrapper, game): | 26 def __init__(self, pos, life, _type, bonus_dropped, die_score, anm_wrapper, game): |
27 self._game = game | 27 self._game = game |
28 self._anm_wrapper = anm_wrapper | 28 self._anm_wrapper = anm_wrapper |
29 self._sprite = None | |
30 self._anmrunner = None | |
31 self._removed = False | |
32 self._visible = True | |
33 self._type = _type | 29 self._type = _type |
34 self._bonus_dropped = bonus_dropped | 30 |
35 self._die_score = die_score #TODO: use it | 31 self.sprite = None |
36 self._was_visible = False | 32 self.anmrunner = None |
33 self.removed = False | |
34 self.visible = True | |
35 self.was_visible = False | |
36 self.bonus_dropped = bonus_dropped | |
37 self.die_score = die_score #TODO: use it | |
37 | 38 |
38 self.frame = 0 | 39 self.frame = 0 |
39 | 40 |
40 self.x, self.y, self.z = pos | 41 self.x, self.y, self.z = pos |
41 self.life = 1 if life < 0 else life | 42 self.life = 1 if life < 0 else life |
190 x, y = pos or (self.x, self.y) | 191 x, y = pos or (self.x, self.y) |
191 return atan2(player.y - y, player.x - x) | 192 return atan2(player.y - y, player.x - x) |
192 | 193 |
193 | 194 |
194 def set_anim(self, index): | 195 def set_anim(self, index): |
195 self._sprite = Sprite() | 196 self.sprite = Sprite() |
196 self._anmrunner = ANMRunner(self._anm_wrapper, index, self._sprite) | 197 self.anmrunner = ANMRunner(self._anm_wrapper, index, self.sprite) |
197 self._anmrunner.run_frame() | 198 self.anmrunner.run_frame() |
198 | 199 |
199 | 200 |
200 def die_anim(self): | 201 def die_anim(self): |
201 anim = {0: 3, 1: 4, 2: 5}[self.death_anim % 256] # The TB is wanted, if index isn’t in these values the original game crashs. | 202 anim = {0: 3, 1: 4, 2: 5}[self.death_anim % 256] # The TB is wanted, if index isn’t in these values the original game crashs. |
202 self._game.new_effect((self.x, self.y), anim) | 203 self._game.new_effect((self.x, self.y), anim) |
242 self.speed_interpolator.set_interpolation_start(frame, (self.speed,)) | 243 self.speed_interpolator.set_interpolation_start(frame, (self.speed,)) |
243 self.speed_interpolator.set_interpolation_end(frame + duration - 1, (0.,)) | 244 self.speed_interpolator.set_interpolation_end(frame + duration - 1, (0.,)) |
244 | 245 |
245 | 246 |
246 def is_visible(self, screen_width, screen_height): | 247 def is_visible(self, screen_width, screen_height): |
247 if self._sprite: | 248 if self.sprite: |
248 tx, ty, tw, th = self._sprite.texcoords | 249 tx, ty, tw, th = self.sprite.texcoords |
249 if self._sprite.corner_relative_placement: | 250 if self.sprite.corner_relative_placement: |
250 raise Exception #TODO | 251 raise Exception #TODO |
251 else: | 252 else: |
252 tx, ty, tw, th = 0., 0., 0., 0. | 253 tx, ty, tw, th = 0., 0., 0., 0. |
253 | 254 |
254 x, y = self.x, self.y | 255 x, y = self.x, self.y |
379 | 380 |
380 | 381 |
381 self.x, self.y = x, y | 382 self.x, self.y = x, y |
382 | 383 |
383 #TODO | 384 #TODO |
384 if self._anmrunner and not self._anmrunner.run_frame(): | 385 if self.anmrunner and not self.anmrunner.run_frame(): |
385 self._anmrunner = None | 386 self.anmrunner = None |
386 | 387 |
387 if self._sprite and self._visible: | 388 if self.sprite and self.visible: |
388 if self._sprite._removed: | 389 if self.sprite.removed: |
389 self._sprite = None | 390 self.sprite = None |
390 else: | 391 else: |
391 self._sprite.update_orientation(self.angle, | 392 self.sprite.update_orientation(self.angle, |
392 self.automatic_orientation) | 393 self.automatic_orientation) |
393 | 394 |
394 | 395 |
395 if self.bullet_launch_interval != 0: | 396 if self.bullet_launch_interval != 0: |
396 self.bullet_launch_timer += 1 | 397 self.bullet_launch_timer += 1 |
397 if self.bullet_launch_timer == self.bullet_launch_interval: | 398 if self.bullet_launch_timer == self.bullet_launch_interval: |