# HG changeset patch # User Emmanuel Gil Peyrot # Date 1337256919 -7200 # Node ID 1366cefd03340477e221cad6c6912a4c2675a2b5 # Parent 8579c43c124c8bca20a7a52147ddefad46361b04 Move callbacks handling inside Enemy. diff --git a/pytouhou/game/enemy.py b/pytouhou/game/enemy.py --- a/pytouhou/game/enemy.py +++ b/pytouhou/game/enemy.py @@ -340,9 +340,67 @@ class Enemy(object): self.life -= damages + def handle_callbacks(self): + #TODO: implement missing callbacks and clean up! + if self.life <= 0 and self.touchable: + death_flags = self.death_flags & 7 + + self.die_anim() + + if death_flags < 4: + if self.bonus_dropped > -1: + self.drop_particles(7, 0) + self._game.drop_bonus(self.x, self.y, self.bonus_dropped) + elif self.bonus_dropped == -1: + if self._game.deaths_count % 3 == 0: + self.drop_particles(10, 0) + self._game.drop_bonus(self.x, self.y, self._game.bonus_list[self._game.next_bonus]) + self._game.next_bonus = (self._game.next_bonus + 1) % 32 + else: + self.drop_particles(4, 0) + self._game.deaths_count += 1 + else: + self.drop_particles(4, 0) + + if death_flags == 0: + self.removed = True + return + + if death_flags == 1: + self.touchable = False + elif death_flags == 2: + pass # Just that? + elif death_flags == 3: + #TODO: disable boss mode + self.damageable = False + self.life = 1 + self.death_flags = 0 + + if death_flags != 0 and self.death_callback > -1: + self.process.switch_to_sub(self.death_callback) + self.death_callback = -1 + elif self.life <= self.low_life_trigger and self.low_life_callback > -1: + self.process.switch_to_sub(self.low_life_callback) + self.low_life_callback = -1 + elif self.timeout != -1 and self.frame == self.timeout: + self.frame = 0 + if self.timeout_callback > -1: + self.process.switch_to_sub(self.timeout_callback) + self.timeout_callback = -1 + elif self.touchable: + self.life = 0 + elif self.death_callback > -1: + self.process.switch_to_sub(self.death_callback) + self.death_callback = -1 + self.timeout = -1 #TODO: check + else: + raise Exception('What the hell, man!') + + def update(self): if self.process: self.process.run_iteration() + self.handle_callbacks() x, y = self.x, self.y diff --git a/pytouhou/vm/eclrunner.py b/pytouhou/vm/eclrunner.py --- a/pytouhou/vm/eclrunner.py +++ b/pytouhou/vm/eclrunner.py @@ -149,64 +149,6 @@ class ECLRunner(object): self.instruction_pointer = 0 - def handle_callbacks(self): - #TODO: implement missing callbacks and clean up! - enm = self._enemy - if enm.life <= 0 and enm.touchable: - death_flags = enm.death_flags & 7 - - enm.die_anim() - - if death_flags < 4: - if enm.bonus_dropped > -1: - enm.drop_particles(7, 0) - self._game.drop_bonus(enm.x, enm.y, enm.bonus_dropped) - elif enm.bonus_dropped == -1: - if self._game.deaths_count % 3 == 0: - enm.drop_particles(10, 0) - self._game.drop_bonus(enm.x, enm.y, self._game.bonus_list[self._game.next_bonus]) - self._game.next_bonus = (self._game.next_bonus + 1) % 32 - else: - enm.drop_particles(4, 0) - self._game.deaths_count += 1 - else: - enm.drop_particles(4, 0) - - if death_flags == 0: - enm.removed = True - return - - if death_flags == 1: - enm.touchable = False - elif death_flags == 2: - pass # Just that? - elif death_flags == 3: - #TODO: disable boss mode - enm.damageable = False - enm.life = 1 - enm.death_flags = 0 - - if death_flags != 0 and enm.death_callback > -1: - self.switch_to_sub(enm.death_callback) - enm.death_callback = -1 - elif enm.life <= enm.low_life_trigger and enm.low_life_callback > -1: - self.switch_to_sub(enm.low_life_callback) - enm.low_life_callback = -1 - elif enm.timeout != -1 and enm.frame == enm.timeout: - enm.frame = 0 - if enm.timeout_callback > -1: - self.switch_to_sub(enm.timeout_callback) - enm.timeout_callback = -1 - elif enm.touchable: - enm.life = 0 - elif enm.death_callback > -1: - self.switch_to_sub(enm.death_callback) - enm.death_callback = -1 - enm.timeout = -1 #TODO: check - else: - raise Exception('What the hell, man!') - - def run_iteration(self): # Process script while self.running: @@ -235,9 +177,6 @@ class ECLRunner(object): self.frame += 1 - # Handle callbacks - self.handle_callbacks() - def _getval(self, value): if -10012 <= value <= -10001: