comparison gamelib/equipment.py @ 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 ff168162974e
children 9d31cfc3afde
comparison
equal deleted inserted replaced
188:1281196ccafd 189:37af9e5dd292
23 23
24 class Weapon(Equipment): 24 class Weapon(Equipment):
25 IS_WEAPON = True 25 IS_WEAPON = True
26 DRAW_LAYER = 10 26 DRAW_LAYER = 10
27 27
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
28 def in_range(self, gameboard, wielder, target): 33 def in_range(self, gameboard, wielder, target):
29 """Can the lucky wielder hit the potentially unlucky target with this?""" 34 """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)
31 36
32 def hit(self, gameboard, wielder, target): 37 def hit(self, gameboard, wielder, target):
33 """Is the potentially unlucky target actually unlucky?""" 38 """Is the potentially unlucky target actually unlucky?"""
34 if hasattr(self, 'HIT_SOUND'): 39 if hasattr(self, 'HIT_SOUND'):
35 sound.play_sound(self.HIT_SOUND) 40 sound.play_sound(self.HIT_SOUND)
36 roll = random.randint(1, 100) 41 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)
38 45
39 def place(self, animal): 46 def place(self, animal):
40 for eq in animal.equipment: 47 for eq in animal.equipment:
41 if is_weapon(eq): 48 if is_weapon(eq):
42 return False 49 return False
43 return True 50 return True
44 51
45 class Rifle(Weapon): 52 class Rifle(Weapon):
53 TYPE = "GUN"
46 NAME = "rifle" 54 NAME = "rifle"
47 BUY_PRICE = 100 55 BUY_PRICE = 100
48 SELL_PRICE = 75 56 SELL_PRICE = 75
49 57
50 RANGE = 3 58 RANGE = 3
51 BASE_HIT = 55 59 BASE_HIT = 55
52 RANGE_MODIFIER = 15 60 RANGE_PENALTY = 15
53 HIT_SOUND = "fire-rifle.ogg" 61 HIT_SOUND = "fire-rifle.ogg"
54 62
55 CHICKEN_IMAGE_FILE = 'sprites/equip_rifle.png' 63 CHICKEN_IMAGE_FILE = 'sprites/equip_rifle.png'
56 64
57 class Knife(Weapon): 65 class Knife(Weapon):
66 TYPE = "KNIFE"
58 NAME = "knife" 67 NAME = "knife"
59 BUY_PRICE = 25 68 BUY_PRICE = 25
60 SELL_PRICE = 15 69 SELL_PRICE = 15
61 70
62 RANGE = 1 71 RANGE = 1
63 BASE_HIT = 70 72 BASE_HIT = 70
64 RANGE_MODIFIER = 0 73 RANGE_PENALTY = 0
65 74
66 CHICKEN_IMAGE_FILE = 'sprites/equip_knife.png' 75 CHICKEN_IMAGE_FILE = 'sprites/equip_knife.png'
67 76
68 class Armour(Equipment): 77 class Armour(Equipment):
69 IS_ARMOUR = True 78 IS_ARMOUR = True