Changeset 314:f29999d1bba6


Ignore:
Timestamp:
04/08/11 21:29:24 (12 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Phase:
public
Rebase:
66323731326636393533306339633461633639323661643630613636643733323236373463646635
Message:

Add inventory drawing

Location:
skaapsteker
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/constants.py

    r313 r314  
    3434    HEALTH_WIDTH = 20
    3535    INVENTORY_SIZE = 48
    36 
  • skaapsteker/levelscene.py

    r313 r314  
    180180           left side of the screen, a health bar and collected tofu and
    181181           scroll counts are shown on the right"""
     182        fox = self.game_state.world.fox  # conveience shortcur
    182183        # Draw the healt bar
    183184        health_bottom = self._clip_rect.right - 30, self._clip_rect.top + 200
     
    185186        bar.bottomleft = health_bottom
    186187        pygame.draw.rect(self._level_surface, constants.FoxHud.HEALTH_BACKGROUND, bar)
    187         bar.height = int(constants.FoxHud.HEALTH_HEIGHT * float(self.game_state.world.fox.cur_health)/self.game_state.world.fox.max_health)
     188        bar.height = int(constants.FoxHud.HEALTH_HEIGHT * float(fox.cur_health)/fox.max_health)
    188189        bar.bottomleft = health_bottom
    189190        pygame.draw.rect(self._level_surface, constants.FoxHud.HEALTH_FOREGROUND, bar)
     191
     192        # Draw inventory
     193        my_item = fox.item
     194        if my_item:
     195            # Get image and resize it
     196            inv_pos = self._clip_rect.left + 8, self._clip_rect.top + 8
     197            self._level_surface.blit(self._player.inventory_image, inv_pos)
    190198
    191199
  • skaapsteker/sprites/player.py

    r296 r314  
    316316    def take_item(self, item):
    317317        self.take_item_by_name(item.name)
     318        # We create a scaled version of the image for the inventory display
     319        image = item.image
     320        if image.get_width() > image.get_height():
     321            new_width = 48
     322            new_height = int(image.get_height() * (48.0 / image.get_width()))
     323        else:
     324            new_height = 48
     325            new_width = int(image.get_width() * (48.0 / image.get_height()))
     326        self.inventory_image = pygame.transform.scale(image, (new_width, new_height))
    318327        item.kill()
    319328        print "took", item
Note: See TracChangeset for help on using the changeset viewer.