comparison gamelib/animal.py @ 241:1a7000c8211c

Demolition foxes, including better fox selection.
author Jeremy Thurgood <firxen@gmail.com>
date Sat, 05 Sep 2009 11:19:26 +0000
parents 9a6ac9c9ff46
children 4f86c2616cdf
comparison
equal deleted inserted replaced
240:af19d6fdc1f8 241:1a7000c8211c
8 import imagecache 8 import imagecache
9 import tiles 9 import tiles
10 from misc import Position 10 from misc import Position
11 import sound 11 import sound
12 import equipment 12 import equipment
13 import animations
13 14
14 class Animal(Sprite): 15 class Animal(Sprite):
15 """Base class for animals""" 16 """Base class for animals"""
16 17
17 STEALTH = 0 18 STEALTH = 0
367 this_tile = tiles.REVERSE_TILE_MAP['woodland'] 368 this_tile = tiles.REVERSE_TILE_MAP['woodland']
368 if tiles.TILE_MAP[this_tile] == 'broken fence' and self.hunting: 369 if tiles.TILE_MAP[this_tile] == 'broken fence' and self.hunting:
369 # We'll head back towards the holes we make/find 370 # We'll head back towards the holes we make/find
370 self.landmarks.append(final_pos) 371 self.landmarks.append(final_pos)
371 elif tiles.TILE_MAP[this_tile] == 'fence' and not self.dig_pos: 372 elif tiles.TILE_MAP[this_tile] == 'fence' and not self.dig_pos:
372 self._dig(final_pos) 373 self._dig(gameboard, final_pos)
373 return self.pos 374 return self.pos
374 self.last_steps.append(final_pos) 375 self.last_steps.append(final_pos)
375 if len(self.last_steps) > 3: 376 if len(self.last_steps) > 3:
376 self.last_steps.pop(0) 377 self.last_steps.pop(0)
377 return final_pos 378 return final_pos
378 379
379 def _dig(self, dig_pos): 380 def _dig(self, gameboard, dig_pos):
380 """Setup dig parameters, to be overridden if needed""" 381 """Setup dig parameters, to be overridden if needed"""
381 self.tick = 5 382 self.tick = 5
382 self.dig_pos = dig_pos 383 self.dig_pos = dig_pos
383 384
384 def _make_hole(self, gameboard): 385 def _make_hole(self, gameboard):
420 IMAGE_FILE = 'sprites/ninja_fox.png' 421 IMAGE_FILE = 'sprites/ninja_fox.png'
421 422
422 class DemoFox(Fox): 423 class DemoFox(Fox):
423 """Demolition Foxes destroy fences easily""" 424 """Demolition Foxes destroy fences easily"""
424 425
426 DIG_ANIMATION = animations.FenceExplosion
427 IMAGE_FILE = 'sprites/sapper_fox.png'
428
429 def _dig(self, gameboard, dig_pos):
430 """Setup dig parameters, to be overridden if needed"""
431 self.tick = 0 # Costs us nothing to go through a fence.
432 self.dig_pos = dig_pos
433 gameboard.animations.append(self.DIG_ANIMATION(dig_pos))
434 self._make_hole(gameboard)
435
425 class GreedyFox(Fox): 436 class GreedyFox(Fox):
426 """Greedy foxes eat more chickens""" 437 """Greedy foxes eat more chickens"""
427 438
428 def __init__(self, pos): 439 def __init__(self, pos):
429 Fox.__init__(self, pos) 440 Fox.__init__(self, pos)