comparison gamelib/animal.py @ 236:9a6ac9c9ff46

chickens turn to face target foxes
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Sat, 05 Sep 2009 09:46:29 +0000
parents 962934b8c7dc
children 1a7000c8211c
comparison
equal deleted inserted replaced
235:d0760fccce14 236:9a6ac9c9ff46
48 """Move an animal to the given tile_pos.""" 48 """Move an animal to the given tile_pos."""
49 new_pos = Position(*tile_pos) 49 new_pos = Position(*tile_pos)
50 self._fix_face(new_pos) 50 self._fix_face(new_pos)
51 self.pos = new_pos 51 self.pos = new_pos
52 52
53 def _fix_face(self, final_pos): 53 def _fix_face(self, facing_pos):
54 """Set the face correctly""" 54 """Set the face correctly"""
55 if final_pos.left_of(self.pos): 55 if facing_pos.left_of(self.pos):
56 self._set_image_facing('left') 56 self._set_image_facing('left')
57 elif final_pos.right_of(self.pos): 57 elif facing_pos.right_of(self.pos):
58 self._set_image_facing('right') 58 self._set_image_facing('right')
59 59
60 def _set_image_facing(self, facing): 60 def _set_image_facing(self, facing):
61 self.facing = facing 61 self.facing = facing
62 if self.facing == 'left': 62 if self.facing == 'left':
179 # Choose the first weapon equipped. 179 # Choose the first weapon equipped.
180 weapon = self.weapons()[0] 180 weapon = self.weapons()[0]
181 fox = self._find_killable_fox(weapon, gameboard) 181 fox = self._find_killable_fox(weapon, gameboard)
182 if not fox: 182 if not fox:
183 return 183 return
184 self._fix_face(fox.pos)
184 if weapon.hit(gameboard, self, fox): 185 if weapon.hit(gameboard, self, fox):
185 sound.play_sound("kill-fox.ogg") 186 sound.play_sound("kill-fox.ogg")
186 gameboard.kill_fox(fox) 187 gameboard.kill_fox(fox)
187 188
188 class Egg(Animal): 189 class Egg(Animal):