changeset 314:f29999d1bba6

Add inventory drawing
author Neil Muller <drnlmuller@gmail.com>
date Fri, 08 Apr 2011 23:29:24 +0200
parents 7db1b7c5c961
children 0fc2b9d1a9cb
files skaapsteker/constants.py skaapsteker/levelscene.py skaapsteker/sprites/player.py
diffstat 3 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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
-
--- 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):
--- 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