changeset 545:bcff39c920ab

Set boss mode directly from the enemy.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 15 May 2014 20:14:54 +0200
parents b895ed2de71f
children 94dd9862c470
files pytouhou/game/enemy.pxd pytouhou/game/enemy.pyx pytouhou/game/game.pyx pytouhou/games/eosd.py pytouhou/vm/eclrunner.py
diffstat 5 files changed, 19 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/enemy.pxd	Thu May 15 02:56:08 2014 +0200
+++ b/pytouhou/game/enemy.pxd	Thu May 15 20:14:54 2014 +0200
@@ -47,6 +47,7 @@
     cpdef set_pos(self, double x, double y, double z)
     cpdef move_to(self, unsigned long duration, double x, double y, double z, formula)
     cpdef stop_in(self, unsigned long duration, formula)
+    cpdef set_boss(self, bint enable)
     cdef bint is_visible(self, long screen_width, long screen_height) except? False
     cdef void check_collisions(self) except *
     cdef void handle_callbacks(self) except *
--- a/pytouhou/game/enemy.pyx	Thu May 15 02:56:08 2014 +0200
+++ b/pytouhou/game/enemy.pyx	Thu May 15 20:14:54 2014 +0200
@@ -309,6 +309,16 @@
                                                formula)
 
 
+    cpdef set_boss(self, bint enable):
+        if enable:
+            self.boss = True
+            self._game.boss = self
+            self._game.interface.set_boss_life()
+        else:
+            self.boss = False
+            self._game.boss = None
+
+
     cdef bint is_visible(self, long screen_width, long screen_height):
         if self.sprite is not None:
             if self.sprite.corner_relative_placement:
--- a/pytouhou/game/game.pyx	Thu May 15 02:56:08 2014 +0200
+++ b/pytouhou/game/game.pyx	Thu May 15 20:14:54 2014 +0200
@@ -579,7 +579,7 @@
                 del self.texts[key]
 
         # Disable boss mode if it is dead/it has timeout
-        if self.boss and self.boss._enemy.removed:
+        if self.boss and self.boss.removed:
             self.boss = None
 
 
--- a/pytouhou/games/eosd.py	Thu May 15 02:56:08 2014 +0200
+++ b/pytouhou/games/eosd.py	Thu May 15 20:14:54 2014 +0200
@@ -225,12 +225,12 @@
     def set_boss_life(self):
         if not self.game.boss:
             return
-        self.boss_items[1].maximum = self.game.boss._enemy.life or 1
-        self.boss_items[2].maximum = self.game.boss._enemy.life or 1
+        self.boss_items[1].maximum = self.game.boss.life or 1
+        self.boss_items[2].maximum = self.game.boss.life or 1
 
 
     def set_spell_life(self):
-        self.boss_items[2].set_value(self.game.boss._enemy.low_life_trigger if self.game.boss else 0)
+        self.boss_items[2].set_value(self.game.boss.low_life_trigger if self.game.boss else 0)
 
 
     def update(self):
@@ -254,7 +254,7 @@
         self.labels['bombs'].set_value(player_state.bombs)
 
         if self.game.boss:
-            boss = self.game.boss._enemy
+            boss = self.game.boss
 
             life_gauge = self.boss_items[1]
             life_gauge.set_value(boss.life)
--- a/pytouhou/vm/eclrunner.py	Thu May 15 02:56:08 2014 +0200
+++ b/pytouhou/vm/eclrunner.py	Thu May 15 20:14:54 2014 +0200
@@ -103,7 +103,7 @@
 
     @instruction(10)
     def resume_ecl(self, sub, instr_type, unk1, unk2):
-        boss = self._game.boss._enemy
+        boss = self._game.boss
         self._game.msg_wait = False
         if not boss.boss_callback:
             raise Exception #TODO
@@ -801,12 +801,9 @@
         #      only the last one has her life displayed,
         #      but standard enemies are blocked only until any of them is killed.
         if value == 0:
-            self._enemy.boss = True
-            self._game.boss = self
-            self._game.interface.set_boss_life()
+            self._enemy.set_boss(True)
         elif value == -1:
-            self._enemy.boss = False
-            self._game.boss = None
+            self._enemy.set_boss(False)
         else:
             raise Exception #TODO