# HG changeset patch # User Simon Cross # Date 1251738119 0 # Node ID dd9d2a4dd4947cb8c1e1247bbec8a6a3a6412108 # Parent 030bea282f28d5f24c0d4f0b2c82db01c77718d4 Update tile loading to use imagecache and new data.py auto-converting of paths. diff -r 030bea282f28 -r dd9d2a4dd494 gamelib/tiles.py --- a/gamelib/tiles.py Mon Aug 31 16:58:03 2009 +0000 +++ b/gamelib/tiles.py Mon Aug 31 17:01:59 2009 +0000 @@ -1,9 +1,8 @@ """Extension to pgu's tilevid.""" from pgu import tilevid, vid -import pygame -from pygame.locals import BLEND_RGBA_MULT import os +import imagecache TILE_MAP = { 0: "woodland", @@ -25,14 +24,14 @@ def png_folder_load_tiles(self, path): """Load tiles from a folder of PNG files.""" for dirpath, dirnames, filenames in os.walk(path): + abstract_dirpath = "/".join(dirpath.split(os.path.sep)) 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) + self.tiles[n] = FarmTile(abstract_dirpath + "/" + filename) def sun(self, sun_on): """Make it night.""" @@ -45,12 +44,9 @@ class FarmTile(vid.Tile): - NIGHT_COLOUR = (100.0, 100.0, 200.0, 255.0) - - def __init__(self, image): - self.day_image = image - self.night_image = image.copy() - self.night_image.fill(self.NIGHT_COLOUR, None, BLEND_RGBA_MULT) + def __init__(self, image_name): + self.day_image = imagecache.load_image(image_name) + self.night_image = imagecache.load_image(image_name, ("night",)) self.image = self.day_image def sun(self, sun_on):