comparison gamelib/animal.py @ 114:4c2fbab20abe

Foxes are stealthy now.
author Jeremy Thurgood <firxen@gmail.com>
date Wed, 02 Sep 2009 19:17:26 +0000
parents 48019afde338
children 2b2007e231da
comparison
equal deleted inserted replaced
113:55105d3bdab1 114:4c2fbab20abe
11 import sound 11 import sound
12 import equipment 12 import equipment
13 13
14 class Animal(Sprite): 14 class Animal(Sprite):
15 """Base class for animals""" 15 """Base class for animals"""
16
17 STEALTH = 0
16 18
17 def __init__(self, image_left, image_right, tile_pos): 19 def __init__(self, image_left, image_right, tile_pos):
18 # Create the animal somewhere far off screen 20 # Create the animal somewhere far off screen
19 Sprite.__init__(self, image_left, (-1000, -1000)) 21 Sprite.__init__(self, image_left, (-1000, -1000))
20 self.image_left = image_left 22 self.image_left = image_left
70 72
71 def _find_killable_fox(self, weapon, gameboard): 73 def _find_killable_fox(self, weapon, gameboard):
72 """Choose a random fox within range of this weapon.""" 74 """Choose a random fox within range of this weapon."""
73 killable_foxes = [] 75 killable_foxes = []
74 for fox in gameboard.foxes: 76 for fox in gameboard.foxes:
77 if not visible(self, fox):
78 continue
75 if weapon.in_range(gameboard, self, fox): 79 if weapon.in_range(gameboard, self, fox):
76 killable_foxes.append(fox) 80 killable_foxes.append(fox)
77 if not killable_foxes: 81 if not killable_foxes:
78 return None 82 return None
79 return random.choice(killable_foxes) 83 return random.choice(killable_foxes)
101 105
102 # Eggs don't move 106 # Eggs don't move
103 107
104 class Fox(Animal): 108 class Fox(Animal):
105 """A fox""" 109 """A fox"""
110
111 STEALTH = 20
106 112
107 costs = { 113 costs = {
108 # weighting for movement calculation 114 # weighting for movement calculation
109 'grassland' : 2, 115 'grassland' : 2,
110 'woodland' : 1, # Try to keep to the woods if possible 116 'woodland' : 1, # Try to keep to the woods if possible
288 self.pos = final_pos 294 self.pos = final_pos
289 295
290 class NinjaFox(Fox): 296 class NinjaFox(Fox):
291 """Ninja foxes are hard to see""" 297 """Ninja foxes are hard to see"""
292 298
299 STEALTH = 60
300
293 class DemoFox(Fox): 301 class DemoFox(Fox):
294 """Demolition Foxes destroy fences easily""" 302 """Demolition Foxes destroy fences easily"""
295 303
296 class GreedyFox(Fox): 304 class GreedyFox(Fox):
297 """Greedy foxes eat more chickens""" 305 """Greedy foxes eat more chickens"""
303 def _catch_chicken(self, chicken, gameboard): 311 def _catch_chicken(self, chicken, gameboard):
304 gameboard.remove_chicken(chicken) 312 gameboard.remove_chicken(chicken)
305 self.chickens_eaten += 1 313 self.chickens_eaten += 1
306 if self.chickens_eaten > 2: 314 if self.chickens_eaten > 2:
307 self.hunting = False 315 self.hunting = False
316
317 def visible(watcher, watchee):
318 roll = random.randint(1, 100)
319 distance = watcher.pos.dist(watchee.pos) - 1
320 return roll > watchee.STEALTH + 10*distance