Mercurial > rinkhals
changeset 413:bdc4757e0497
Add Sniper Rifle and give guns limited ammunition.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Sat, 21 Nov 2009 12:07:01 +0000 |
parents | 1e24eedbf40f |
children | 9096c237928c |
files | gamelib/animal.py gamelib/engine.py gamelib/equipment.py gamelib/gameboard.py |
diffstat | 4 files changed, 39 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/animal.py Sat Nov 21 11:34:12 2009 +0000 +++ b/gamelib/animal.py Sat Nov 21 12:07:01 2009 +0000 @@ -225,6 +225,15 @@ if weapon.hit(gameboard, self, fox): fox.damage(gameboard) + def reload_weapon(self): + """If we have a weapon that takes ammunition, reload it.""" + if not self.weapons(): + # Nothing to reload + return + for weapon in self.weapons(): + if hasattr(weapon, 'AMMUNITION'): + weapon.ammunition = weapon.AMMUNITION + class Egg(Animal): """An egg"""
--- a/gamelib/engine.py Sat Nov 21 11:34:12 2009 +0000 +++ b/gamelib/engine.py Sat Nov 21 12:07:01 2009 +0000 @@ -166,10 +166,7 @@ # disable timer pygame.time.set_timer(MOVE_FOX_ID, 0) pygame.time.set_timer(ANIM_ID, SLOW_ANIM_SPEED) - self.game.gameboard.advance_day() - self.game.gameboard.clear_foxes() sound.background_music("daytime.ogg") - self.game.gameboard.hatch_eggs() self.dialog = None def event(self, e): @@ -219,10 +216,8 @@ self.cycle_time = SLOW_ANIM_SPEED pygame.time.set_timer(MOVE_FOX_ID, 4*self.cycle_time) pygame.time.set_timer(ANIM_ID, self.cycle_time) - self.game.gameboard.spawn_foxes() sound.background_music("nighttime.ogg") - self.game.gameboard.lay_eggs() self.dialog = None def event(self, e):
--- a/gamelib/equipment.py Sat Nov 21 11:34:12 2009 +0000 +++ b/gamelib/equipment.py Sat Nov 21 12:07:01 2009 +0000 @@ -64,6 +64,12 @@ def hit(self, gameboard, wielder, target): """Is the potentially unlucky target actually unlucky?""" + if hasattr(self, 'AMMUNITION'): + if self.ammunition <= 0: + # Out of ammunition, so we don't get to shoot. + return + else: + self.ammunition -= 1 if hasattr(self, 'HIT_SOUND'): sound.play_sound(self.HIT_SOUND) if hasattr(self, 'ANIMATION'): @@ -84,6 +90,7 @@ NAME = "Rifle" BUY_PRICE = 100 SELL_PRICE = 75 + AMMUNITION = 30 RANGE = 3 BASE_HIT = 55 @@ -94,6 +101,22 @@ ANIMATION = animations.MuzzleFlash +class SniperRifle(Weapon): + TYPE = "GUN" + NAME = "Sniper Rifle" + BUY_PRICE = 150 + SELL_PRICE = 100 + AMMUNITION = 3 + + RANGE = 5 + BASE_HIT = 80 + RANGE_PENALTY = 10 + HIT_SOUND = "fire-rifle.ogg" + + CHICKEN_IMAGE_FILE = 'sprites/equip_rifle.png' + + ANIMATION = animations.MuzzleFlash + class Knife(Weapon): TYPE = "KNIFE" NAME = "Knife"
--- a/gamelib/gameboard.py Sat Nov 21 11:34:12 2009 +0000 +++ b/gamelib/gameboard.py Sat Nov 21 12:07:01 2009 +0000 @@ -368,6 +368,10 @@ self.reset_states() self.toolbar.update_fin_tool(self.day) self._cache_animal_positions() + self.spawn_foxes() + self.lay_eggs() + for chicken in self.chickens: + chicken.reload_weapon() def start_day(self): self.day, self.night = True, False @@ -375,6 +379,9 @@ self.reset_states() self.toolbar.update_fin_tool(self.day) self._pos_cache = { 'fox' : [], 'chicken' : []} + self.advance_day() + self.clear_foxes() + self.hatch_eggs() def in_bounds(self, pos): """Check if a position is within the game boundaries"""