# HG changeset patch # User Neil Muller # Date 1302298164 -7200 # Node ID f29999d1bba6f31bd053aedcac5341cf2a0884d2 # Parent 7db1b7c5c9614f8cfb0c3804b6f9f241560f43f4 Add inventory drawing diff -r 7db1b7c5c961 -r f29999d1bba6 skaapsteker/constants.py --- a/skaapsteker/constants.py Fri Apr 08 23:02:50 2011 +0200 +++ b/skaapsteker/constants.py Fri Apr 08 23:29:24 2011 +0200 @@ -33,4 +33,3 @@ HEALTH_HEIGHT = 160 HEALTH_WIDTH = 20 INVENTORY_SIZE = 48 - diff -r 7db1b7c5c961 -r f29999d1bba6 skaapsteker/levelscene.py --- a/skaapsteker/levelscene.py Fri Apr 08 23:02:50 2011 +0200 +++ b/skaapsteker/levelscene.py Fri Apr 08 23:29:24 2011 +0200 @@ -179,15 +179,23 @@ """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 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.height = int(constants.FoxHud.HEALTH_HEIGHT * float(fox.cur_health)/fox.max_health) bar.bottomleft = health_bottom pygame.draw.rect(self._level_surface, constants.FoxHud.HEALTH_FOREGROUND, bar) + # 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 + 8 + self._level_surface.blit(self._player.inventory_image, inv_pos) + def _update_clip_rect(self): diff -r 7db1b7c5c961 -r f29999d1bba6 skaapsteker/sprites/player.py --- a/skaapsteker/sprites/player.py Fri Apr 08 23:02:50 2011 +0200 +++ b/skaapsteker/sprites/player.py Fri Apr 08 23:29:24 2011 +0200 @@ -315,6 +315,15 @@ def take_item(self, item): self.take_item_by_name(item.name) + # We create a scaled version of the image for the inventory display + image = item.image + if image.get_width() > image.get_height(): + new_width = 48 + new_height = int(image.get_height() * (48.0 / image.get_width())) + else: + new_height = 48 + new_width = int(image.get_width() * (48.0 / image.get_height())) + self.inventory_image = pygame.transform.scale(image, (new_width, new_height)) item.kill() print "took", item