Mercurial > rinkhals
diff gamelib/tiles.py @ 24:7584453f4944
Add support for PNG tiles.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sun, 30 Aug 2009 18:11:30 +0000 |
parents | |
children | 2eec29085060 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gamelib/tiles.py Sun Aug 30 18:11:30 2009 +0000 @@ -0,0 +1,37 @@ +"""Extension to pgu's tilevid.""" + +from pgu import tilevid, vid +import pygame +import os + +TILE_MAP = { + 0: "woodland", + 1: "grassland", + 2: "fence", + 3: "henhouse", + 4: "chicken", +} + +REVERSE_TILE_MAP = dict((v, k) for k, v in TILE_MAP.iteritems()) + +class FarmVid(tilevid.Tilevid): + """Extension of pgu's TileVid class to handle the complications + of raising chickens. + """ + def __init__(self): + tilevid.Tilevid.__init__(self) + + def png_folder_load_tiles(self, path): + """Load tiles from a folder of PNG files.""" + for dirpath, dirnames, filenames in os.walk(path): + for filename in filenames: + basename, ext = os.path.splitext(filename) + if ext != ".png": + continue + if basename in REVERSE_TILE_MAP: + n = REVERSE_TILE_MAP[basename] + img = pygame.image.load(os.path.join(dirpath, filename)).convert_alpha() + self.tiles[n] = FarmTile(img) + +class FarmTile(vid.Tile): + pass