Mercurial > skaapsteker
comparison 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 |
comparison
equal
deleted
inserted
replaced
356:f5148f70ca84 | 357:742731e6e6fd |
---|---|
4 import time | 4 import time |
5 | 5 |
6 from ..sprites.base import find_sprite, TILE_SIZE, PC_LAYER, MONSTER_LAYER | 6 from ..sprites.base import find_sprite, TILE_SIZE, PC_LAYER, MONSTER_LAYER |
7 from ..sprites.projectiles import Fireball | 7 from ..sprites.projectiles import Fireball |
8 from ..physics import Sprite | 8 from ..physics import Sprite |
9 from ..constants import Layers | 9 from ..constants import Layers, FoxHud |
10 from ..data import get_files, load_image | 10 from ..data import get_files, load_image |
11 from ..engine import PlayerDied, AddSpriteEvent | 11 from ..engine import PlayerDied, AddSpriteEvent |
12 | 12 |
13 | 13 |
14 class Player(Sprite): | 14 class Player(Sprite): |
409 sprite = self.get_sprite(False) | 409 sprite = self.get_sprite(False) |
410 if sprite is None: | 410 if sprite is None: |
411 self.inventory_image = None | 411 self.inventory_image = None |
412 image = sprite.image | 412 image = sprite.image |
413 if image.get_width() > image.get_height(): | 413 if image.get_width() > image.get_height(): |
414 new_width = 48 | 414 new_width = FoxHud.INVENTORY_SIZE |
415 new_height = int(image.get_height() * (48.0 / image.get_width())) | 415 new_height = int(image.get_height() * (float(FoxHud.INVENTORY_SIZE) / image.get_width())) |
416 else: | 416 else: |
417 new_height = 48 | 417 new_height = FoxHud.INVENTORY_SIZE |
418 new_width = int(image.get_width() * (48.0 / image.get_height())) | 418 new_width = int(image.get_width() * (float(FoxHud.INVENTORY_SIZE) / image.get_height())) |
419 self.inventory_image = pygame.transform.scale(image, (new_width, new_height)) | 419 if image.get_width() <= FoxHud.INVENTORY_SIZE and image.get_height() <= FoxHud.INVENTORY_SIZE: |
420 self.inventory_image = image | |
421 else: | |
422 self.inventory_image = pygame.transform.smoothscale(image, (new_width, new_height)) | |
420 sprite.kill() # ensure we don't leak into the scene at any point | 423 sprite.kill() # ensure we don't leak into the scene at any point |
421 | 424 |
422 | 425 |
423 def take_item_by_name(self, item_name): | 426 def take_item_by_name(self, item_name): |
424 self.drop_item() | 427 self.drop_item() |