diff skaapsteker/sprites/player.py @ 357:742731e6e6fd

Centre small inventory items rather than resizing
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 09 Apr 2011 14:03:44 +0200
parents 5bdb4677510a
children eacb3e1bc1d1
line wrap: on
line diff
--- a/skaapsteker/sprites/player.py	Sat Apr 09 13:42:50 2011 +0200
+++ b/skaapsteker/sprites/player.py	Sat Apr 09 14:03:44 2011 +0200
@@ -6,7 +6,7 @@
 from ..sprites.base import find_sprite, TILE_SIZE, PC_LAYER, MONSTER_LAYER
 from ..sprites.projectiles import Fireball
 from ..physics import Sprite
-from ..constants import Layers
+from ..constants import Layers, FoxHud
 from ..data import get_files, load_image
 from ..engine import PlayerDied, AddSpriteEvent
 
@@ -411,12 +411,15 @@
             self.inventory_image = None
         image = sprite.image
         if image.get_width() > image.get_height():
-            new_width = 48
-            new_height = int(image.get_height() * (48.0 / image.get_width()))
+            new_width = FoxHud.INVENTORY_SIZE
+            new_height = int(image.get_height() * (float(FoxHud.INVENTORY_SIZE) / 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))
+            new_height = FoxHud.INVENTORY_SIZE
+            new_width = int(image.get_width() * (float(FoxHud.INVENTORY_SIZE) / image.get_height()))
+        if image.get_width() <= FoxHud.INVENTORY_SIZE and image.get_height() <= FoxHud.INVENTORY_SIZE:
+            self.inventory_image = image
+        else:
+            self.inventory_image = pygame.transform.smoothscale(image, (new_width, new_height))
         sprite.kill() # ensure we don't leak into the scene at any point