Ignore:
Timestamp:
Sep 7, 2013, 8:03:09 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
rebase_source:
8e7b1799412b3374e05c95406aec0f073471ced7
Message:

Inventory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/screens/area.py

    r520 r555  
    55import pymunk.pygame_util
    66
     7from nagslang.resources import resources
     8from nagslang.mutators import ImageCentre, scaler
    79from nagslang.options import options
    810from nagslang.constants import (
     
    257259                break
    258260        self.render_health_bar(surface)
     261        self.render_inventory(surface)
    259262
    260263    def tick_protagonist(self):
     
    282285
    283286    def render_health_bar(self, surface, damage_experienced=None):
    284         bar_surface = pygame.Surface((110, 50)).convert(surface)
     287        bar_surface = pygame.Surface((110, 40)).convert(surface)
    285288        if damage_experienced:
    286289            health_box_colour = pygame.color.THECOLORS['red']
     
    292295        else:
    293296            health_colour = pygame.color.THECOLORS['violetred3']
    294         rect = pygame.Rect(5, 5, self.protagonist.get_health_level(), 40)
     297        rect = pygame.Rect(5, 5, self.protagonist.get_health_level(), 30)
    295298        pygame.draw.rect(bar_surface, health_colour, rect, 0)
    296299        bar_surface.set_alpha(192)
    297300        y_pos = surface.get_height() - 20 - bar_surface.get_height()
    298301        surface.blit(bar_surface, (20, y_pos))
     302
     303    def render_inventory(self, surface):
     304        items = len(self.world.inventory)
     305        if not items:
     306            return
     307        padding = 4
     308        img_size = 64
     309        size = 32
     310        inv_surf = pygame.Surface(
     311            (padding + (size + padding) * items,
     312             (2 * padding + size)))
     313        inv_surf = inv_surf.convert(surface)
     314        inv_surf.set_alpha(192)
     315        inv_surf.fill(pygame.color.THECOLORS['white'])
     316        for index, item in enumerate(sorted(self.world.inventory)):
     317            img = resources.get_image(
     318                'objects', item + '.png',
     319                transforms=(ImageCentre((img_size, img_size)),
     320                            scaler((size, size))))
     321            inv_surf.blit(img, (padding + index * (size + padding), padding))
     322        y_pos = surface.get_height() - 20 - inv_surf.get_height()
     323        x_pos = 130 + padding
     324        surface.blit(inv_surf, (x_pos, y_pos))
Note: See TracChangeset for help on using the changeset viewer.