Changeset 189:37af9e5dd292


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

Use tool with left button, cancel tool with right button.

Location:
gamelib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gamelib/equipment.py

    r174 r189  
    2626    DRAW_LAYER = 10
    2727
     28    def _get_parameter(self, parameter, wielder):
     29        mod_attr = 'MODIFY_%s_%s' % (self.TYPE, parameter)
     30        param = getattr(self, parameter)
     31        return getattr(wielder.abode, mod_attr, lambda r: r)(param)
     32
    2833    def in_range(self, gameboard, wielder, target):
    2934        """Can the lucky wielder hit the potentially unlucky target with this?"""
    30         return wielder.pos.dist(target.pos) <= self.RANGE
     35        return wielder.pos.dist(target.pos) <= self._get_parameter('RANGE', wielder)
    3136
    3237    def hit(self, gameboard, wielder, target):
     
    3540            sound.play_sound(self.HIT_SOUND)
    3641        roll = random.randint(1, 100)
    37         return roll > (100-self.BASE_HIT) + self.RANGE_MODIFIER*wielder.pos.dist(target.pos)
     42        base_hit = self._get_parameter('BASE_HIT', wielder)
     43        range_penalty = self._get_parameter('RANGE_PENALTY', wielder)
     44        return roll > (100-base_hit) + range_penalty*wielder.pos.dist(target.pos)
    3845
    3946    def place(self, animal):
     
    4451
    4552class Rifle(Weapon):
     53    TYPE = "GUN"
    4654    NAME = "rifle"
    4755    BUY_PRICE = 100
     
    5058    RANGE = 3
    5159    BASE_HIT = 55
    52     RANGE_MODIFIER = 15
     60    RANGE_PENALTY = 15
    5361    HIT_SOUND = "fire-rifle.ogg"
    5462
     
    5664
    5765class Knife(Weapon):
     66    TYPE = "KNIFE"
    5867    NAME = "knife"
    5968    BUY_PRICE = 25
     
    6271    RANGE = 1
    6372    BASE_HIT = 70
    64     RANGE_MODIFIER = 0
     73    RANGE_PENALTY = 0
    6574
    6675    CHICKEN_IMAGE_FILE = 'sprites/equip_knife.png'
  • gamelib/gameboard.py

    r186 r189  
    247247
    248248    def use_tool(self, e):
     249        if e.button == 3: # Right button
     250            self.selected_tool = None
     251            self.reset_cursor()
     252        elif e.button != 1: # Left button
     253            return
    249254        if self.selected_tool == constants.TOOL_SELL_CHICKEN:
    250255            self.sell_chicken(self.tv.screen_to_tile(e.pos))
Note: See TracChangeset for help on using the changeset viewer.