# HG changeset patch # User Neil Muller # Date 1302296570 -7200 # Node ID 7db1b7c5c9614f8cfb0c3804b6f9f241560f43f4 # Parent e63a0261ea1f0ce8c030cc563d04c4af15cf9d48 Add health bar diff -r e63a0261ea1f -r 7db1b7c5c961 skaapsteker/constants.py --- 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 + diff -r e63a0261ea1f -r 7db1b7c5c961 skaapsteker/levelscene.py --- 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()