Changeset 357:742731e6e6fd


Ignore:
Timestamp:
04/09/11 12:03:44 (12 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Phase:
public
Message:

Centre small inventory items rather than resizing

Location:
skaapsteker
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/levelscene.py

    r356 r357  
    214214        if my_item:
    215215            # Get image and resize it
    216             inv_pos = self._clip_rect.left + 8, self._clip_rect.top + fox_hud.INVENTORY_START
    217216            if self._player.inventory_image is None:
    218217                self._player.make_inventory_image()
     218            inv_pos = self._player.inventory_image.get_rect()
     219            inv_pos.move_ip(self._clip_rect.left + 8,
     220                            self._clip_rect.top + fox_hud.INVENTORY_START)
     221            if inv_pos.width < fox_hud.INVENTORY_SIZE:
     222                inv_pos.left += (fox_hud.INVENTORY_SIZE - inv_pos.width) / 2
     223            if inv_pos.height < fox_hud.INVENTORY_SIZE:
     224                inv_pos.top += (fox_hud.INVENTORY_SIZE - inv_pos.height) / 2
    219225            self._level_surface.blit(self._player.inventory_image, inv_pos)
    220226        # Tail bg
  • skaapsteker/sprites/player.py

    r355 r357  
    77from ..sprites.projectiles import Fireball
    88from ..physics import Sprite
    9 from ..constants import Layers
     9from ..constants import Layers, FoxHud
    1010from ..data import get_files, load_image
    1111from ..engine import PlayerDied, AddSpriteEvent
     
    412412        image = sprite.image
    413413        if image.get_width() > image.get_height():
    414             new_width = 48
    415             new_height = int(image.get_height() * (48.0 / image.get_width()))
    416         else:
    417             new_height = 48
    418             new_width = int(image.get_width() * (48.0 / image.get_height()))
    419         self.inventory_image = pygame.transform.scale(image, (new_width, new_height))
     414            new_width = FoxHud.INVENTORY_SIZE
     415            new_height = int(image.get_height() * (float(FoxHud.INVENTORY_SIZE) / image.get_width()))
     416        else:
     417            new_height = FoxHud.INVENTORY_SIZE
     418            new_width = int(image.get_width() * (float(FoxHud.INVENTORY_SIZE) / image.get_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))
    420423        sprite.kill() # ensure we don't leak into the scene at any point
    421424
Note: See TracChangeset for help on using the changeset viewer.