changeset 53:f20dd3dcb118

foxes don't run backwards
author Adrianna Pińska <adrianna.pinska@gmail.com>
date Mon, 31 Aug 2009 17:47:10 +0000
parents 0d4799866bcf
children b8f64db0d39e
files gamelib/animal.py gamelib/imagecache.py
diffstat 2 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/animal.py	Mon Aug 31 17:37:20 2009 +0000
+++ b/gamelib/animal.py	Mon Aug 31 17:47:10 2009 +0000
@@ -7,9 +7,11 @@
 class Animal(Sprite):
     """Base class for animals"""
 
-    def __init__(self, image, pos):
+    def __init__(self, image_left, image_right, pos):
         # Create the animal somewhere far off screen
-        Sprite.__init__(self, image, (-1000, -1000))
+        Sprite.__init__(self, image_left, (-1000, -1000))
+        self.image_left = image_left
+        self.image_right = image_right
         self.pos = pos
 
     def loop(self, tv, _sprite):
@@ -26,8 +28,9 @@
     """A chicken"""
 
     def __init__(self, pos):
-        image = imagecache.load_image('sprites/chkn.png')
-        Animal.__init__(self, image, pos)
+        image_left = imagecache.load_image('sprites/chkn.png')
+        image_right = imagecache.load_image('sprites/chkn.png', ("right_facing",))
+        Animal.__init__(self, image_left, image_right, pos)
 
     def move(self, gameboard):
         """A free chicken will move away from other free chickens"""
@@ -38,7 +41,7 @@
 
     def __init__(self, pos):
         image = imagecache.load_image('sprites/egg.png')
-        Animal.__init__(self, image, pos)
+        Animal.__init__(self, image, image, pos)
 
     # Eggs don't move
 
@@ -46,9 +49,10 @@
     """A fox"""
 
     def __init__(self, pos):
-        image = imagecache.load_image('sprites/fox.png')
+        image_left = imagecache.load_image('sprites/fox.png')
+        image_right = imagecache.load_image('sprites/fox.png', ("right_facing",))
         self.full = False
-        Animal.__init__(self, image, pos)
+        Animal.__init__(self, image_left, image_right, pos)
 
     def move(self, gameboard):
         """Foxes will aim to move towards the closest henhouse or free
@@ -69,8 +73,10 @@
         xpos, ypos = self.pos
         if min_vec[0] < 0:
             xpos -= 1
+            self.setimage(self.image_left)
         elif min_vec[0] > 0:
             xpos += 1
+            self.setimage(self.image_right)
         if min_vec[1] < 0:
             ypos -= 1
         elif min_vec[1] > 0:
--- a/gamelib/imagecache.py	Mon Aug 31 17:37:20 2009 +0000
+++ b/gamelib/imagecache.py	Mon Aug 31 17:47:10 2009 +0000
@@ -65,8 +65,14 @@
     night_image.fill(NIGHT_COLOUR, None, BLEND_RGBA_MULT)
     return night_image
 
+def convert_to_right_facing(image):
+    right_facing_image = image.copy()
+    right_facing_image = pygame.transform.flip(right_facing_image, 1, 0)
+    return right_facing_image
+
 # globals
 
 cache = ImageCache()
 cache.register_modifier("night", convert_to_night)
+cache.register_modifier("right_facing", convert_to_right_facing)
 load_image = cache.load_image