Changeset 313:7db1b7c5c961


Ignore:
Timestamp:
04/08/11 21:02:50 (12 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Phase:
public
Rebase:
64373539666265663437306333313337306436383036653137393239316435376436383837316230
Message:

Add health bar

Location:
skaapsteker
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/constants.py

    r265 r313  
    11# Useful constants
    22# copyright skaapsteker team (see COPYRIGHT file for details)
     3
     4import pygame
    35
    46SCREEN = (800, 600)
     
    2325    IN_FRONT = 3 # Layer in front of the player
    2426    FOREGROUND = 4  # Absolute foreground
     27
     28
     29class FoxHud(object):
     30    TEXT = pygame.Color(255, 255, 255, 196)
     31    HEALTH_BACKGROUND = pygame.Color(128, 64, 0, 128)
     32    HEALTH_FOREGROUND = pygame.Color(255, 64, 0, 196)
     33    HEALTH_HEIGHT = 160
     34    HEALTH_WIDTH = 20
     35    INVENTORY_SIZE = 48
     36
  • skaapsteker/levelscene.py

    r302 r313  
    158158            self._dialogue.draw(self._level_surface)
    159159
     160        self._draw_fox_status()
     161
    160162        fps_text_pos = self._clip_rect.left + 10, self._clip_rect.top + 10
    161163        fps_text = Text('FPS: %.1f' % engine.get_fps(), fps_text_pos, shadow='white')
     
    173175
    174176        screen_surface.blit(self._level_surface, (0, 0), self._clip_rect)
     177
     178    def _draw_fox_status(self):
     179        """Draw the fox inventory. The tails and the item are drawn on the
     180           left side of the screen, a health bar and collected tofu and
     181           scroll counts are shown on the right"""
     182        # Draw the healt bar
     183        health_bottom = self._clip_rect.right - 30, self._clip_rect.top + 200
     184        bar = pygame.Rect(0, 0, constants.FoxHud.HEALTH_WIDTH, constants.FoxHud.HEALTH_HEIGHT)
     185        bar.bottomleft = health_bottom
     186        pygame.draw.rect(self._level_surface, constants.FoxHud.HEALTH_BACKGROUND, bar)
     187        bar.height = int(constants.FoxHud.HEALTH_HEIGHT * float(self.game_state.world.fox.cur_health)/self.game_state.world.fox.max_health)
     188        bar.bottomleft = health_bottom
     189        pygame.draw.rect(self._level_surface, constants.FoxHud.HEALTH_FOREGROUND, bar)
     190
     191
    175192
    176193    def _update_clip_rect(self):
Note: See TracChangeset for help on using the changeset viewer.