comparison gamelib/animal.py @ 25:6d6ab0c1479d

Add placing some chickens and foxes
author Neil Muller <drnlmuller@gmail.com>
date Sun, 30 Aug 2009 18:14:07 +0000
parents
children ac3a74352b74
comparison
equal deleted inserted replaced
24:7584453f4944 25:6d6ab0c1479d
1 """Class for the various animals in the game"""
2
3 import pygame
4 from pgu.vid import Sprite
5
6 import data
7
8 class Animal(Sprite):
9 """Base class for animals"""
10
11 def __init__(self, image, pos):
12 Sprite.__init__(self, image, pos)
13 self.pos = pos
14
15 def loop(self, tv, _sprite):
16 ppos = tv.tile_to_view(self.pos)
17 self.rect.x = ppos[0]
18 self.rect.y = ppos[1]
19
20 def move(self, state):
21 """Given the game state, return a new position for the object"""
22 # Default is not to move
23 return self.pos
24
25 class Chicken(Animal):
26 """A chicken"""
27
28 def __init__(self, pos):
29 image = pygame.image.load(data.filepath('sprites/chkn.png'))
30 Animal.__init__(self, image, pos)
31
32 def move(self, gameboard):
33 """A free chicken will move away from other free chickens"""
34 return self.pos
35
36 class Egg(Animal):
37 """An egg"""
38
39 # Eggs don't move
40
41 class Fox(Animal):
42 """A fox"""
43
44 def __init__(self, pos):
45 image = pygame.image.load(data.filepath('sprites/fox.png'))
46 Animal.__init__(self, image, pos)
47
48 def move(self, gameboard):
49 """Foxes will aim to move towards the closest henhouse or free
50 chicken"""
51 return self.pos
52