# HG changeset patch # User Emmanuel Gil Peyrot # Date 1341441527 -7200 # Node ID 862011266f2cdf49993307304c2cef20b1b4b785 # Parent 2c4589370cc63ca578e4f6543af44ca620842cb6 Add a gauge and use it for the enemy life bar. diff --git a/pytouhou/game/enemy.py b/pytouhou/game/enemy.py --- 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 diff --git a/pytouhou/game/text.py b/pytouhou/game/text.py --- 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 + + diff --git a/pytouhou/games/eosd.py b/pytouhou/games/eosd.py --- 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() diff --git a/pytouhou/vm/eclrunner.py b/pytouhou/vm/eclrunner.py --- 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)