changeset 103:789994275968

Fix boss callback, handle a few more callbacks
author Thibaut Girka <thib@sitedethib.com>
date Mon, 05 Sep 2011 01:07:43 +0200
parents ad9297e0fbf2
children 6c59d0eeb5fa
files pytouhou/game/enemy.py pytouhou/vm/eclrunner.py
diffstat 2 files changed, 20 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/enemy.py
+++ b/pytouhou/game/enemy.py
@@ -48,6 +48,7 @@ class Enemy(object):
         self.bullet_attributes = None
         self.bullet_launch_offset = (0, 0)
         self.death_callback = None
+        self.boss_callback = None
         self.low_life_callback = None
         self.low_life_trigger = None
         self.timeout = None
--- a/pytouhou/vm/eclrunner.py
+++ b/pytouhou/vm/eclrunner.py
@@ -106,16 +106,28 @@ class ECLRunner(object):
 
 
     def handle_callbacks(self):
-        #TODO
+        #TODO: implement missing callbacks and clean up!
         enm = self._enemy
-        if enm.timeout and enm.frame == enm.timeout:
+        if enm.boss_callback is not None: #XXX: MSG's job!
+            self.frame = 0
+            self.sub = enm.boss_callback
+            self.instruction_pointer = 0
+            enm.boss_callback = None
+        if enm.life == 0 and enm.death_callback is not None:
+            self.frame = 0
+            self.sub = enm.death_callback
+            self.instruction_pointer = 0
+            #TODO: various things, like deleting the character
+            enm.death_callback = None #XXX
+        elif enm.timeout and enm.frame == enm.timeout:
             enm.frame = 0
-            if enm.timeout_callback:
+            if enm.timeout_callback is not None:
                 self.frame = 0
                 self.sub = enm.timeout_callback
                 self.instruction_pointer = 0
+                enm.timeout_callback = None
             else:
-                pass #TODO
+                enm.life = 0
         #TODO: other callbacks (low life, etc.)
 
 
@@ -695,9 +707,9 @@ class ECLRunner(object):
         #TODO
         #XXX: this is a hack to display bosses although we don't handle MSG :)
         if index == 0:
-            self.sub = value
-            self.frame = 0
-            self.instruction_pointer = 0
+            self._enemy.boss_callback = value
+        else:
+            raise Exception #TODO
 
 
     @instruction(111)