comparison gamelib/equipment.py @ 429:42777630956a

Add ammo to things serialized and deserialized.
author Simon Cross <hodgestar@gmail.com>
date Sat, 21 Nov 2009 16:28:27 +0000
parents 97dd557504a2
children db7bb20d2336
comparison
equal deleted inserted replaced
428:a356e57529ea 429:42777630956a
10 class Equipment(serializer.Simplifiable): 10 class Equipment(serializer.Simplifiable):
11 IS_EQUIPMENT = True 11 IS_EQUIPMENT = True
12 DRAW_LAYER = 0 12 DRAW_LAYER = 0
13 UNDER_LIMB = False 13 UNDER_LIMB = False
14 UNDER_EYE = False 14 UNDER_EYE = False
15 AMMUNITION = None
15 16
16 SIMPLIFY = [ 17 SIMPLIFY = [
17 '_buy_price', 18 '_buy_price',
18 '_sell_price', 19 '_sell_price',
19 '_name', 20 '_name',
21 'ammunition',
20 ] 22 ]
21 23
22 def __init__(self): 24 def __init__(self):
23 self._buy_price = self.BUY_PRICE 25 self._buy_price = self.BUY_PRICE
24 self._sell_price = self.SELL_PRICE 26 self._sell_price = self.SELL_PRICE
25 self._name = self.NAME 27 self._name = self.NAME
28 self.refresh_ammo()
26 29
27 def make(cls): 30 def make(cls):
28 """Override default Simplifiable object creation.""" 31 """Override default Simplifiable object creation."""
29 return cls() 32 return cls()
30 make = classmethod(make) 33 make = classmethod(make)
56 eye_right = imagecache.load_image("sprites/eye.png", ("right_facing",)) 59 eye_right = imagecache.load_image("sprites/eye.png", ("right_facing",))
57 eq_image_left.blit(eye_left, (0,0)) 60 eq_image_left.blit(eye_left, (0,0))
58 eq_image_right.blit(eye_right, (0,0)) 61 eq_image_right.blit(eye_right, (0,0))
59 return eq_image_left, eq_image_right, self.DRAW_LAYER 62 return eq_image_left, eq_image_right, self.DRAW_LAYER
60 63
64 def refresh_ammo(self):
65 self.ammunition = getattr(self, 'AMMUNITION', None)
66
61 class Weapon(Equipment): 67 class Weapon(Equipment):
62 IS_WEAPON = True 68 IS_WEAPON = True
63 DRAW_LAYER = 10 69 DRAW_LAYER = 10
64 UNDER_LIMB = True 70 UNDER_LIMB = True
65 71
75 """Can the lucky wielder hit the potentially unlucky target with this?""" 81 """Can the lucky wielder hit the potentially unlucky target with this?"""
76 return wielder.pos.dist(target.pos) <= self._get_parameter('RANGE', wielder) 82 return wielder.pos.dist(target.pos) <= self._get_parameter('RANGE', wielder)
77 83
78 def hit(self, gameboard, wielder, target): 84 def hit(self, gameboard, wielder, target):
79 """Is the potentially unlucky target actually unlucky?""" 85 """Is the potentially unlucky target actually unlucky?"""
80 if hasattr(self, 'AMMUNITION'): 86 if self.ammunition is not None:
81 if self.ammunition <= 0: 87 if self.ammunition <= 0:
82 # Out of ammunition, so we don't get to shoot. 88 # Out of ammunition, so we don't get to shoot.
83 return 89 return
84 else: 90 else:
85 self.ammunition -= 1 91 self.ammunition -= 1