-
Notifications
You must be signed in to change notification settings - Fork 0
/
animal.py
30 lines (22 loc) · 845 Bytes
/
animal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import random
import game_config as gc
from pygame import image, transform
animals_count = dict((a, 0) for a in gc.asset_files)
def available_animals():
return [a for (a, c) in animals_count.items() if c < 2]
class Animal:
def __init__(self, index):
self.index = index
self.row = index // gc.num_tiles_side
self.col = index % gc.num_tiles_side
self.name = random.choice(available_animals())
animals_count[self.name] += 1
self.image_path = os.path.join(gc.asset_dir, self.name)
self.image = image.load(self.image_path)
self.image = transform.scale(self.image, (gc.image_size - 2
* gc.margin, gc.image_size - 2 * gc.margin))
self.box = self.image.copy()
t = (200, 200, 200)
self.box.fill(t)
self.skip = False