changeset 346:862011266f2c

Add a gauge and use it for the enemy life bar.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 05 Jul 2012 00:38:47 +0200
parents 2c4589370cc6
children b150ed7188a2
files pytouhou/game/enemy.py pytouhou/game/text.py pytouhou/games/eosd.py pytouhou/vm/eclrunner.py
diffstat 4 files changed, 38 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/enemy.py
+++ b/pytouhou/game/enemy.py
@@ -42,7 +42,6 @@ class Enemy(object):
 
         self.x, self.y, self.z = pos
         self.life = 1 if life < 0 else life
-        self.max_life = life
         self.touchable = True
         self.collidable = True
         self.damageable = True
--- a/pytouhou/game/text.py
+++ b/pytouhou/game/text.py
@@ -149,3 +149,30 @@ class Counter(GlyphCollection):
         self.changed = True
 
 
+
+class Gauge(object):
+    def __init__(self, pos, anm_wrapper, max_length=280, maximum=1, value=0.):
+        self.sprite = Sprite()
+        self.anmrunner = ANMRunner(anm_wrapper, 21, self.sprite)
+        self.anmrunner.run_frame()
+        self.removed = False
+        self.sprite.corner_relative_placement = True #TODO: perhaps not right
+
+        self.x, self.y = pos
+        self.max_length = max_length
+        self.maximum = maximum
+
+        self.set_value(value)
+
+
+    def set_value(self, value):
+        self.value = value
+        self.sprite.width_override = self.max_length * value / self.maximum
+        self.sprite.changed = True #TODO
+
+
+    def update(self):
+        if self.anmrunner and not self.anmrunner.run_frame():
+            self.anmrunner = None
+
+
--- a/pytouhou/games/eosd.py
+++ b/pytouhou/games/eosd.py
@@ -21,7 +21,7 @@ from pytouhou.game.itemtype import ItemT
 from pytouhou.game.player import Player
 from pytouhou.game.orb import Orb
 from pytouhou.game.effect import Effect
-from pytouhou.game.text import Text, Counter
+from pytouhou.game.text import Text, Counter, Gauge
 
 
 SQ2 = 2. ** 0.5 / 2.
@@ -138,12 +138,14 @@ class EoSDInterface(object):
 
         self.boss_items = [
             Effect((0, 0), 19, front), # Enemy
-            # Gauge
+            Gauge((100, 24), front), # Gauge
         ]
         for item in self.boss_items:
             item.sprite.allow_dest_offset = True #XXX
 
-        self.front = front #XXX
+
+    def set_boss_life(self):
+        self.boss_items[1].maximum = self.game.boss._enemy.life
 
 
     def update(self):
@@ -163,6 +165,10 @@ class EoSDInterface(object):
 
         if self.game.boss:
             boss = self.game.boss._enemy
+
+            life_gauge = self.boss_items[1]
+            life_gauge.set_value(boss.life)
+
             for item in self.boss_items:
                 item.update()
 
--- a/pytouhou/vm/eclrunner.py
+++ b/pytouhou/vm/eclrunner.py
@@ -804,6 +804,7 @@ class ECLRunner(object):
         if value == 0:
             self._enemy.boss = True
             self._game.boss = self
+            self._game.interface.set_boss_life()
         elif value == -1:
             self._enemy.boss = False
             self._game.boss = None
@@ -856,6 +857,7 @@ class ECLRunner(object):
     @instruction(111)
     def set_life(self, value):
         self._enemy.life = value
+        self._game.interface.set_boss_life()
 
 
     @instruction(112)