changeset 268:dd621ad72beb

Fix callback handling and damage dealing.
author Thibaut Girka <thib@sitedethib.com>
date Mon, 23 Jan 2012 23:00:42 +0100
parents 35644a67ba4c
children 729382f57ad0
files pytouhou/game/enemy.py pytouhou/vm/eclrunner.py
diffstat 2 files changed, 26 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/enemy.py
+++ b/pytouhou/game/enemy.py
@@ -48,12 +48,12 @@ class Enemy(object):
         self.extended_bullet_attributes = (0, 0, 0, 0, 0., 0., 0., 0.)
         self.bullet_attributes = None
         self.bullet_launch_offset = (0, 0)
-        self.death_callback = None
+        self.death_callback = -1
         self.boss_callback = None
-        self.low_life_callback = None
+        self.low_life_callback = -1
         self.low_life_trigger = None
-        self.timeout = None
-        self.timeout_callback = None
+        self.timeout = -1
+        self.timeout_callback = -1
         self.remaining_lives = -1
 
         self.automatic_orientation = False
@@ -262,7 +262,8 @@ class Enemy(object):
             if not (bx2 < ex1 or bx1 > ex2
                     or by2 < ey1 or by1 > ey2):
                 bullet.collide()
-                damages += bullet.damage
+                if self.damageable:
+                    damages += bullet.damage
                 self.drop_particles(1, 1)
 
         # Check for enemy-player collisions
@@ -293,8 +294,7 @@ class Enemy(object):
                 damages //= 7
 
         # Apply damages
-        if self.damageable:
-            self.life -= damages
+        self.life -= damages
 
 
     def update(self):
--- a/pytouhou/vm/eclrunner.py
+++ b/pytouhou/vm/eclrunner.py
@@ -151,29 +151,28 @@ class ECLRunner(object):
                 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
-            else:
-                pass #TODO: sparks
 
-            if death_flags != 0 and enm.death_callback is not None:
+            if death_flags != 0 and enm.death_callback >= 0:
                 self.frame = 0
                 self.sub = enm.death_callback
                 self.instruction_pointer = 0
-                enm.death_callback = None
-        elif enm.life <= enm.low_life_trigger and enm.low_life_callback is not None:
+                enm.death_callback = -1
+        elif enm.life <= enm.low_life_trigger and enm.low_life_callback >= 0:
             self.frame = 0
             self.sub = enm.low_life_callback
             self.instruction_pointer = 0
-            enm.low_life_callback = None
+            enm.low_life_callback = -1
         elif enm.timeout and enm.frame == enm.timeout:
             enm.frame = 0
-            if enm.timeout_callback is not None:
+            if enm.timeout_callback >= 0:
                 self.frame = 0
                 self.sub = enm.timeout_callback
                 self.instruction_pointer = 0
-                enm.timeout_callback = None
+                enm.timeout_callback = -1
             else:
                 enm.life = 0
         #TODO: other callbacks (low life, etc.)
@@ -743,9 +742,18 @@ class ECLRunner(object):
 
     @instruction(96)
     def kill_enemies(self):
-        for enemy in self._game.enemies:
-            if enemy.touchable and not enemy.boss:
-                enemy.life = 0
+        for proc in self._game.ecl_runner.processes:
+            if proc._enemy.boss:
+                pass # Bosses are immune to 96
+            elif proc._enemy.touchable:
+                proc._enemy.life = 0
+            elif proc._enemy.death_callback > 0:
+                #TODO: check
+                #TODO: refactor
+                proc.frame = 0
+                proc.instruction_pointer = 0
+                proc.sub = proc._enemy.death_callback
+                proc._enemy.death_callback = -1
 
 
     @instruction(97)