changeset 345:2c4589370cc6

Display a boss remaining lives and timeout.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 05 Jul 2012 00:11:19 +0200
parents eab591728abf
children 862011266f2c
files pytouhou/game/enemy.py pytouhou/game/text.py pytouhou/games/eosd.py pytouhou/ui/gamerenderer.pyx pytouhou/ui/gamerunner.py
diffstat 5 files changed, 49 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/enemy.py
+++ b/pytouhou/game/enemy.py
@@ -395,11 +395,14 @@ class Enemy(object):
                     return
 
                 if death_flags == 1:
+                    self.boss = False #TODO: really?
+                    self._game.boss = None
                     self.touchable = False
                 elif death_flags == 2:
                     pass # Just that?
                 elif death_flags == 3:
-                    #TODO: disable boss mode
+                    self.boss = False #TODO: really?
+                    self._game.boss = None
                     self.damageable = False
                     self.life = 1
                     self.death_flags = 0
--- a/pytouhou/game/text.py
+++ b/pytouhou/game/text.py
@@ -106,7 +106,8 @@ class Text(GlyphCollection):
 
 
     def set_color(self, color):
-        colors = {'white': (255, 255, 255), 'yellow': (255, 255, 0), 'blue': (192, 192, 255)}
+        colors = {'white': (255, 255, 255), 'yellow': (255, 255, 0), 'blue': (192, 192, 255), 'darkblue': (160, 128, 255), 'purple': (224, 128, 255), 'red': (255, 64, 0)}
+        self.ref_sprite.color = colors[color]
         for glyph in self.glyphes:
             glyph.sprite.color = colors[color]
 
--- a/pytouhou/games/eosd.py
+++ b/pytouhou/games/eosd.py
@@ -91,7 +91,7 @@ class EoSDGame(Game):
         characters = resource_loader.get_eosd_characters()
         players = [EoSDPlayer(state, self, resource_loader, characters[state.character]) for state in player_states]
 
-        interface = EoSDInterface(player_states, resource_loader)
+        interface = EoSDInterface(self, resource_loader)
 
         Game.__init__(self, resource_loader, players, stage, rank, difficulty,
                       bullet_types, laser_types, item_types, nb_bullets_max,
@@ -100,8 +100,8 @@ class EoSDGame(Game):
 
 
 class EoSDInterface(object):
-    def __init__(self, states, resource_loader):
-        self.states = states
+    def __init__(self, game, resource_loader):
+        self.game = game
         front = resource_loader.get_anm_wrapper(('front.anm',))
         ascii_wrapper = resource_loader.get_anm_wrapper(('ascii.anm',))
 
@@ -129,14 +129,28 @@ class EoSDInterface(object):
             'points': Text((500, 226), ascii_wrapper, front, text='0'),
             'framerate': Text((512, 464), ascii_wrapper, front),
             'debug?': Text((0, 464), ascii_wrapper, front),
+
+            # Only when there is a boss.
+            'boss_lives': Text((80, 16), ascii_wrapper),
+            'timeout': Text((384, 16), ascii_wrapper),
         }
+        self.labels['boss_lives'].set_color('yellow')
+
+        self.boss_items = [
+            Effect((0, 0), 19, front), # Enemy
+            # Gauge
+        ]
+        for item in self.boss_items:
+            item.sprite.allow_dest_offset = True #XXX
+
+        self.front = front #XXX
 
 
     def update(self):
         for elem in self.items:
             elem.update()
 
-        player_state = self.states[0]
+        player_state = self.game.players[0].state
 
         self.highscore = max(self.highscore, player_state.effective_score)
         self.labels['highscore'].set_text('%09d' % self.highscore)
@@ -147,6 +161,27 @@ class EoSDInterface(object):
         self.labels['player'].set_value(player_state.lives)
         self.labels['bombs'].set_value(player_state.bombs)
 
+        if self.game.boss:
+            boss = self.game.boss._enemy
+            for item in self.boss_items:
+                item.update()
+
+            self.labels['boss_lives'].set_text('%d' % boss.remaining_lives)
+            self.labels['boss_lives'].changed = True
+
+            timeout = (boss.timeout - boss.frame) // 60
+            timeout_label = self.labels['timeout']
+            if timeout >= 20:
+                timeout_label.set_color('blue')
+            elif timeout >= 10:
+                timeout_label.set_color('darkblue')
+            elif timeout >= 5:
+                timeout_label.set_color('purple')
+            else:
+                timeout_label.set_color('red')
+            timeout_label.set_text('%02d' % (timeout if timeout >= 0 else 0))
+            timeout_label.changed = True
+
 
 
 class EoSDPlayer(Player):
--- a/pytouhou/ui/gamerenderer.pyx
+++ b/pytouhou/ui/gamerenderer.pyx
@@ -95,6 +95,6 @@ cdef class GameRenderer(Renderer):
             self.render_elements(chain(game.bullets, game.lasers,
                                        game.cancelled_bullets, game.items,
                                        (item.indicator for item in game.items if item.indicator),
-				       *(label.objects() for label in game.labels)))
+                                       *(label.objects() for label in game.labels)))
             glEnable(GL_FOG)
 
--- a/pytouhou/ui/gamerunner.py
+++ b/pytouhou/ui/gamerunner.py
@@ -195,6 +195,9 @@ class GameRunner(pyglet.window.Window, G
             # Redraw only changed labels
             labels = [label for label in labels if label.changed]
 
+        if self.game.boss:
+            self.render_elements(interface.boss_items)
+
         self.render_elements(labels)
         self.render_elements(chain(*(label.objects() for label in labels)))
         for label in labels: