Changeset 601:23fbf4651f99


Ignore:
Timestamp:
Dec 6, 2009, 10:11:37 AM (11 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68/trunk/rinkhals@606
Message:

Roosters.

Location:
gamelib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gamelib/animal.py

    r557 r601  
    229229        """See if the chicken lays an egg"""
    230230        if self.abode and self.abode.building.HENHOUSE:
     231            # TODO: Find a cleaner way to do this
     232            fertilised = False
     233            for bird in self.abode.building.occupants():
     234                if getattr(bird, 'ROOSTER', None):
     235                    fertilised = True
    231236            if not self.eggs:
    232237                for x in range(random.randint(1, 4)):
    233                     self.eggs.append(Egg(self.pos, self.gameboard))
     238                    self.eggs.append(Egg(self.pos, self.gameboard, fertilised=fertilised))
    234239                self.equip(equipment.NestEgg())
    235240            self.gameboard.eggs += self.get_num_eggs()
     
    296301            weapon.refresh_ammo()
    297302
     303
     304class Rooster(Chicken):
     305    """A rooster"""
     306
     307    IMAGE_FILE = 'sprites/rooster.png'
     308    ROOSTER = True
     309
     310    AGGRESSION = 50
     311
     312    def lay(self):
     313        # Roosters don't lay eggs.
     314        pass
     315
     316    def start_night(self):
     317        Chicken.start_night(self)
     318        self._manly_fight()
     319
     320    def _manly_fight(self):
     321        if self.abode:
     322            for rival in [occ for occ in self.abode.building.occupants()
     323                          if getattr(occ, 'ROOSTER', False)]:
     324                if random.randint(1, 100) <= self.AGGRESSION:
     325                    rival.damage()
     326
     327
    298328class Egg(Animal):
    299329    """An egg"""
     
    301331    IMAGE_FILE = 'sprites/equip_egg.png'
    302332
    303     SIMPLIFY = Animal.SIMPLIFY + ['timer']
    304 
    305     def __init__(self, pos, gameboard):
     333    SIMPLIFY = Animal.SIMPLIFY + ['timer', 'fertilised']
     334
     335    def __init__(self, pos, gameboard, fertilised=False):
    306336        Animal.__init__(self, pos, gameboard)
     337        self.fertilised = fertilised
    307338        self.timer = 2
    308339
     
    311342    def hatch(self):
    312343        self.timer -= 1
    313         if self.timer == 0:
    314             return Chicken(self.pos, self.gameboard)
     344        if self.timer == 0 and self.fertilised:
     345            return random.choice([Chicken, Rooster])(self.pos, self.gameboard)
    315346        return None
     347
    316348
    317349class Fox(Animal):
  • gamelib/gameboard.py

    r599 r601  
    10951095    def add_start_chickens(self, _map, tile, value):
    10961096        """Add chickens as specified by the code layer"""
    1097         chick = animal.Chicken((tile.tx, tile.ty), self)
     1097        chick = random.choice([animal.Chicken, animal.Rooster])((tile.tx, tile.ty), self)
    10981098        for equip_cls in equipment.EQUIP_MAP[value]:
    10991099            item = equip_cls()
Note: See TracChangeset for help on using the changeset viewer.