Mercurial > rinkhals
changeset 189:37af9e5dd292
Use tool with left button, cancel tool with right button.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Fri, 04 Sep 2009 18:00:59 +0000 |
parents | 1281196ccafd |
children | c5ec3ff32d11 |
files | gamelib/equipment.py gamelib/gameboard.py |
diffstat | 2 files changed, 18 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/equipment.py Fri Sep 04 17:55:16 2009 +0000 +++ b/gamelib/equipment.py Fri Sep 04 18:00:59 2009 +0000 @@ -25,16 +25,23 @@ IS_WEAPON = True DRAW_LAYER = 10 + def _get_parameter(self, parameter, wielder): + mod_attr = 'MODIFY_%s_%s' % (self.TYPE, parameter) + param = getattr(self, parameter) + return getattr(wielder.abode, mod_attr, lambda r: r)(param) + def in_range(self, gameboard, wielder, target): """Can the lucky wielder hit the potentially unlucky target with this?""" - return wielder.pos.dist(target.pos) <= self.RANGE + return wielder.pos.dist(target.pos) <= self._get_parameter('RANGE', wielder) def hit(self, gameboard, wielder, target): """Is the potentially unlucky target actually unlucky?""" if hasattr(self, 'HIT_SOUND'): sound.play_sound(self.HIT_SOUND) roll = random.randint(1, 100) - return roll > (100-self.BASE_HIT) + self.RANGE_MODIFIER*wielder.pos.dist(target.pos) + base_hit = self._get_parameter('BASE_HIT', wielder) + range_penalty = self._get_parameter('RANGE_PENALTY', wielder) + return roll > (100-base_hit) + range_penalty*wielder.pos.dist(target.pos) def place(self, animal): for eq in animal.equipment: @@ -43,25 +50,27 @@ return True class Rifle(Weapon): + TYPE = "GUN" NAME = "rifle" BUY_PRICE = 100 SELL_PRICE = 75 RANGE = 3 BASE_HIT = 55 - RANGE_MODIFIER = 15 + RANGE_PENALTY = 15 HIT_SOUND = "fire-rifle.ogg" CHICKEN_IMAGE_FILE = 'sprites/equip_rifle.png' class Knife(Weapon): + TYPE = "KNIFE" NAME = "knife" BUY_PRICE = 25 SELL_PRICE = 15 RANGE = 1 BASE_HIT = 70 - RANGE_MODIFIER = 0 + RANGE_PENALTY = 0 CHICKEN_IMAGE_FILE = 'sprites/equip_knife.png'
--- a/gamelib/gameboard.py Fri Sep 04 17:55:16 2009 +0000 +++ b/gamelib/gameboard.py Fri Sep 04 18:00:59 2009 +0000 @@ -246,6 +246,11 @@ return True def use_tool(self, e): + if e.button == 3: # Right button + self.selected_tool = None + self.reset_cursor() + elif e.button != 1: # Left button + return if self.selected_tool == constants.TOOL_SELL_CHICKEN: self.sell_chicken(self.tv.screen_to_tile(e.pos)) elif self.selected_tool == constants.TOOL_SELL_EGG: