Changeset 315:0fc2b9d1a9cb


Ignore:
Timestamp:
04/08/11 22:04:35 (12 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Phase:
public
Rebase:
35373734393165613030343332353563376266303762666564353963363239323733326363393763
Message:

Recreate inventory image on scene changes

Location:
skaapsteker
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/levelscene.py

    r314 r315  
    194194        if my_item:
    195195            # Get image and resize it
    196             inv_pos = self._clip_rect.left + 8, self._clip_rect.top + 8
     196            inv_pos = self._clip_rect.left + 8, self._clip_rect.top + 32
     197            if self._player.inventory_image is None:
     198                self._player.make_inventory_image()
    197199            self._level_surface.blit(self._player.inventory_image, inv_pos)
    198200
  • skaapsteker/sprites/player.py

    r314 r315  
    3737        self.flying = False
    3838        self._load_images()
     39        self.inventory_image = None
    3940        # We muck with these in load for convience, so ensure they're right
    4041        self.the_world = the_world
     
    299300
    300301
    301     def drop_item(self):
     302    def get_sprite(self):
    302303        my_item = self.the_world.fox.item
    303304        if my_item is None:
    304             return
    305         self.discard_item()
     305            return None
    306306        world_item = getattr(self.the_world.items, my_item)
    307307        world_item.level = self.the_world.fox.level
     
    311311        sprite_dict['name'] = my_item
    312312        sprite_dict['world'] = self.the_world
    313         ItemRepopulationEvent.post(find_sprite(sprite_dict, 'items'))
     313        return find_sprite(sprite_dict, 'items')
     314
     315
     316    def drop_item(self):
     317        sprite = self.get_sprite()
     318        if sprite is None:
     319            return
     320        self.discard_item()
     321        ItemRepopulationEvent.post(sprite)
    314322
    315323
     
    317325        self.take_item_by_name(item.name)
    318326        # We create a scaled version of the image for the inventory display
    319         image = item.image
     327        item.kill()
     328        print "took", item
     329        self.make_inventory_image()
     330
     331
     332    def make_inventory_image(self):
     333        sprite = self.get_sprite()
     334        if sprite is None:
     335            self.inventory_image = None
     336        image = sprite.image
    320337        if image.get_width() > image.get_height():
    321338            new_width = 48
     
    325342            new_width = int(image.get_width() * (48.0 / image.get_height()))
    326343        self.inventory_image = pygame.transform.scale(image, (new_width, new_height))
    327         item.kill()
    328         print "took", item
    329344
    330345
Note: See TracChangeset for help on using the changeset viewer.