Changeset 146:423050ec188b


Ignore:
Timestamp:
Sep 3, 2009, 6:46:38 PM (11 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@147
Message:

Equipment images.

Location:
gamelib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gamelib/animal.py

    r145 r146  
    2020        # Create the animal somewhere far off screen
    2121        Sprite.__init__(self, image_left, (-1000, -1000))
    22         self.image_left = image_left
    23         self.image_right = image_right
     22        self._image_left = image_left
     23        self.image_left = image_left.copy()
     24        self._image_right = image_right
     25        self.image_right = image_right.copy()
    2426        self.pos = Position(tile_pos[0], tile_pos[1])
    2527        self.equipment = []
    2628        self.abode = None
     29        self.facing = 'left'
    2730
    2831    def loop(self, tv, _sprite):
     
    4548        """Set the face correctly"""
    4649        if final_pos.left_of(self.pos):
     50            self._set_image_facing('left')
     51        elif final_pos.right_of(self.pos):
     52            self._set_image_facing('right')
     53
     54    def _set_image_facing(self, facing):
     55        self.facing = facing
     56        if self.facing == 'left':
    4757            self.setimage(self.image_left)
    48         elif final_pos.right_of(self.pos):
     58        elif self.facing == 'right':
    4959            self.setimage(self.image_right)
    5060
    5161    def equip(self, item):
    5262        self.equipment.append(item)
     63        if not hasattr(self, 'EQUIPMENT_IMAGE_ATTRIBUTE'):
     64            return
     65        eq_image_attr = getattr(item, self.EQUIPMENT_IMAGE_ATTRIBUTE, 'None')
     66        if not eq_image_attr:
     67            return
     68        eq_image_left = imagecache.load_image(eq_image_attr)
     69        eq_image_right = imagecache.load_image(eq_image_attr, ("right_facing",))
     70        self.image_left.blit(eq_image_left, (0, 0))
     71        self.image_right.blit(eq_image_right, (0, 0))
     72        self._set_image_facing(self.facing)
    5373
    5474    def weapons(self):
     
    6383class Chicken(Animal):
    6484    """A chicken"""
     85
     86    EQUIPMENT_IMAGE_ATTRIBUTE = 'CHICKEN_IMAGE_FILE'
    6587
    6688    def __init__(self, pos):
  • gamelib/equipment.py

    r120 r146  
    5151    HIT_SOUND = "fire-rifle.ogg"
    5252
     53    CHICKEN_IMAGE_FILE = 'sprites/equip_rifle.png'
     54
    5355class Knife(Weapon):
    5456    NAME = "knife"
     
    5961    BASE_HIT = 70
    6062    RANGE_MODIFIER = 0
     63
     64    CHICKEN_IMAGE_FILE = 'sprites/equip_knife.png'
    6165
    6266def is_equipment(obj):
Note: See TracChangeset for help on using the changeset viewer.