24
|
1 """Extension to pgu's tilevid."""
|
|
2
|
|
3 from pgu import tilevid, vid
|
|
4 import pygame
|
|
5 import os
|
|
6
|
|
7 TILE_MAP = {
|
|
8 0: "woodland",
|
|
9 1: "grassland",
|
|
10 2: "fence",
|
|
11 3: "henhouse",
|
|
12 4: "chicken",
|
|
13 }
|
|
14
|
|
15 REVERSE_TILE_MAP = dict((v, k) for k, v in TILE_MAP.iteritems())
|
|
16
|
|
17 class FarmVid(tilevid.Tilevid):
|
|
18 """Extension of pgu's TileVid class to handle the complications
|
|
19 of raising chickens.
|
|
20 """
|
|
21 def __init__(self):
|
|
22 tilevid.Tilevid.__init__(self)
|
|
23
|
|
24 def png_folder_load_tiles(self, path):
|
|
25 """Load tiles from a folder of PNG files."""
|
|
26 for dirpath, dirnames, filenames in os.walk(path):
|
|
27 for filename in filenames:
|
|
28 basename, ext = os.path.splitext(filename)
|
|
29 if ext != ".png":
|
|
30 continue
|
|
31 if basename in REVERSE_TILE_MAP:
|
|
32 n = REVERSE_TILE_MAP[basename]
|
|
33 img = pygame.image.load(os.path.join(dirpath, filename)).convert_alpha()
|
|
34 self.tiles[n] = FarmTile(img)
|
|
35
|
|
36 class FarmTile(vid.Tile):
|
|
37 pass
|