changeset 313:7db1b7c5c961

Add health bar
author Neil Muller <drnlmuller@gmail.com>
date Fri, 08 Apr 2011 23:02:50 +0200
parents e63a0261ea1f
children f29999d1bba6
files skaapsteker/constants.py skaapsteker/levelscene.py
diffstat 2 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/skaapsteker/constants.py	Fri Apr 08 22:36:12 2011 +0200
+++ b/skaapsteker/constants.py	Fri Apr 08 23:02:50 2011 +0200
@@ -1,6 +1,8 @@
 # Useful constants
 # copyright skaapsteker team (see COPYRIGHT file for details)
 
+import pygame
+
 SCREEN = (800, 600)
 FREQ = 44100   # same as audio CD
 BITSIZE = -16  # unsigned 16 bit
@@ -22,3 +24,13 @@
     PLAYER = 2  # Layer of the player and enemies
     IN_FRONT = 3 # Layer in front of the player
     FOREGROUND = 4  # Absolute foreground
+
+
+class FoxHud(object):
+    TEXT = pygame.Color(255, 255, 255, 196)
+    HEALTH_BACKGROUND = pygame.Color(128, 64, 0, 128)
+    HEALTH_FOREGROUND = pygame.Color(255, 64, 0, 196)
+    HEALTH_HEIGHT = 160
+    HEALTH_WIDTH = 20
+    INVENTORY_SIZE = 48
+
--- a/skaapsteker/levelscene.py	Fri Apr 08 22:36:12 2011 +0200
+++ b/skaapsteker/levelscene.py	Fri Apr 08 23:02:50 2011 +0200
@@ -157,6 +157,8 @@
         if self._dialogue:
             self._dialogue.draw(self._level_surface)
 
+        self._draw_fox_status()
+
         fps_text_pos = self._clip_rect.left + 10, self._clip_rect.top + 10
         fps_text = Text('FPS: %.1f' % engine.get_fps(), fps_text_pos, shadow='white')
         fps_text.draw(self._level_surface)
@@ -173,6 +175,21 @@
 
         screen_surface.blit(self._level_surface, (0, 0), self._clip_rect)
 
+    def _draw_fox_status(self):
+        """Draw the fox inventory. The tails and the item are drawn on the
+           left side of the screen, a health bar and collected tofu and
+           scroll counts are shown on the right"""
+        # Draw the healt bar
+        health_bottom = self._clip_rect.right - 30, self._clip_rect.top + 200
+        bar = pygame.Rect(0, 0, constants.FoxHud.HEALTH_WIDTH, constants.FoxHud.HEALTH_HEIGHT)
+        bar.bottomleft = health_bottom
+        pygame.draw.rect(self._level_surface, constants.FoxHud.HEALTH_BACKGROUND, bar)
+        bar.height = int(constants.FoxHud.HEALTH_HEIGHT * float(self.game_state.world.fox.cur_health)/self.game_state.world.fox.max_health)
+        bar.bottomleft = health_bottom
+        pygame.draw.rect(self._level_surface, constants.FoxHud.HEALTH_FOREGROUND, bar)
+
+
+
     def _update_clip_rect(self):
         cr = self._clip_rect
         lr = self._level_surface.get_rect()