# HG changeset patch # User Stefano Rivera # Date 1302349370 -7200 # Node ID f5148f70ca84faf5985e99a3772e216e63fdf8f0 # Parent 5bdb4677510ae841c0171afb57628c68b51452b0 Backgrounds for HUD diff -r 5bdb4677510a -r f5148f70ca84 skaapsteker/constants.py --- a/skaapsteker/constants.py Sat Apr 09 14:02:13 2011 +0200 +++ b/skaapsteker/constants.py Sat Apr 09 13:42:50 2011 +0200 @@ -32,7 +32,12 @@ HEALTH_FOREGROUND = pygame.Color(255, 64, 0, 196) HEALTH_HEIGHT = 160 HEALTH_WIDTH = 20 + + BG_ALPHA = 120 + BG_MARGIN = 8 + INVENTORY_SIZE = 48 + INVENTORY_START = 32 TAIL_START = 100 TAIL_OFFSET = 30 @@ -46,3 +51,6 @@ 'steal' : TAIL_START + 6 * TAIL_OFFSET, 'lightning' : TAIL_START + 7 * TAIL_OFFSET, } + TAILS_WIDTH = 51 + TAILS_HEIGHT = 8 * TAIL_OFFSET + diff -r 5bdb4677510a -r f5148f70ca84 skaapsteker/levelscene.py --- a/skaapsteker/levelscene.py Sat Apr 09 14:02:13 2011 +0200 +++ b/skaapsteker/levelscene.py Sat Apr 09 13:42:50 2011 +0200 @@ -1,7 +1,8 @@ """Scene wrapping a level object.""" from pygame.locals import (KEYDOWN, KEYUP, K_DOWN, K_ESCAPE, K_LEFT, K_RIGHT, - K_SEMICOLON, K_UP, K_p, K_q, K_x, K_z, K_RETURN, K_c, K_j) + K_SEMICOLON, K_UP, K_c, K_j, K_p, K_q, K_x, K_z, + K_RETURN, SRCALPHA) import pygame import time @@ -188,8 +189,11 @@ """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""" - fox = self.game_state.world.fox # conveience shortcur - # Draw the healt bar + # Convenience shortcuts + fox = self.game_state.world.fox + fox_hud = constants.FoxHud + + # Draw the health 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 @@ -197,20 +201,37 @@ bar.height = int(constants.FoxHud.HEALTH_HEIGHT * float(max(0, fox.cur_health))/fox.max_health) bar.bottomleft = health_bottom pygame.draw.rect(self._level_surface, constants.FoxHud.HEALTH_FOREGROUND, bar) + # Inventory bg + bgsurf = pygame.Surface((fox_hud.INVENTORY_SIZE + 2 * 8, + fox_hud.INVENTORY_SIZE + 2 * 8), + flags=SRCALPHA) + bgsurf.fill((255, 255, 255, fox_hud.BG_ALPHA)) + self._level_surface.blit(bgsurf, (self._clip_rect.left, + self._clip_rect.top + fox_hud.INVENTORY_START - 8)) # Draw inventory my_item = fox.item if my_item: # Get image and resize it - inv_pos = self._clip_rect.left + 8, self._clip_rect.top + 32 + inv_pos = self._clip_rect.left + 8, self._clip_rect.top + fox_hud.INVENTORY_START if self._player.inventory_image is None: self._player.make_inventory_image() self._level_surface.blit(self._player.inventory_image, inv_pos) + # Tail bg + bgsurf = pygame.Surface((self._tail.get_size()[0] + 2 * fox_hud.BG_MARGIN, + fox_hud.TAILS_HEIGHT + fox_hud.BG_MARGIN), + flags=SRCALPHA) + bgsurf.fill((255, 255, 255, fox_hud.BG_ALPHA)) + self._level_surface.blit(bgsurf, + (self._clip_rect.left, + self._clip_rect.top + + fox_hud.TAIL_START + - fox_hud.BG_MARGIN)) # Draw tails # FIXME: Use correct tail icon for tail in fox.tails: - tail_pos = self._clip_rect.left + 8, self._clip_rect.top + constants.FoxHud.TAIL_POSITIONS[tail] + tail_pos = self._clip_rect.left + 8, self._clip_rect.top + fox_hud.TAIL_POSITIONS[tail] self._level_surface.blit(self._tail, tail_pos) # Draw scroll count