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