Changeset 171:9ea53eb919cf


Ignore:
Timestamp:
Sep 3, 2009, 11:00:29 PM (11 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@172
Message:

Make Animals accept Positions when created. move hatch watching from Chicken to Egg

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gamelib/animal.py

    r163 r171  
    2424        self._image_right = image_right
    2525        self.image_right = image_right.copy()
    26         self.pos = Position(tile_pos[0], tile_pos[1])
     26        if hasattr(tile_pos, 'to_tuple'):
     27            self.pos = tile_pos
     28        else:
     29            self.pos = Position(tile_pos[0], tile_pos[1])
    2730        self.equipment = []
    2831        self.abode = None
     
    106109                ("right_facing",))
    107110        Animal.__init__(self, image_left, image_right, pos)
    108         self.egg = False
     111        self.egg = None
    109112        self.egg_counter = 0
    110113
     
    116119        """See if the chicken lays an egg"""
    117120        if not self.egg:
    118             self.egg = True
    119             self.egg_counter = 2
     121            self.egg = Egg(self.pos)
    120122
    121123    def hatch(self):
    122124        """See if we have an egg to hatch"""
    123125        if self.egg:
    124             self.egg_counter -= 1
    125             if self.egg_counter == 0:
    126                 # Egg hatches
    127                 self.egg = False
    128                 return Chicken(self.pos.to_tuple())
     126            return self.egg.hatch()
    129127        return None
    130128
     
    161159        image = imagecache.load_image('sprites/egg.png')
    162160        Animal.__init__(self, image, image, pos)
     161        self.counter = 2
    163162
    164163    # Eggs don't move
     164
     165    def hatch(self):
     166        self.counter -= 1
     167        if self.counter == 0:
     168            return Chicken(self.pos)
     169        return None
    165170
    166171class Fox(Animal):
Note: See TracChangeset for help on using the changeset viewer.