Changeset 49:dd9d2a4dd494


Ignore:
Timestamp:
Aug 31, 2009, 5:01:59 PM (11 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@50
Message:

Update tile loading to use imagecache and new data.py auto-converting of paths.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gamelib/tiles.py

    r30 r49  
    22
    33from pgu import tilevid, vid
    4 import pygame
    5 from pygame.locals import BLEND_RGBA_MULT
    64import os
     5import imagecache
    76
    87TILE_MAP = {
     
    2625        """Load tiles from a folder of PNG files."""
    2726        for dirpath, dirnames, filenames in os.walk(path):
     27            abstract_dirpath = "/".join(dirpath.split(os.path.sep))
    2828            for filename in filenames:
    2929                basename, ext = os.path.splitext(filename)
     
    3232                if basename in REVERSE_TILE_MAP:
    3333                    n = REVERSE_TILE_MAP[basename]
    34                     img = pygame.image.load(os.path.join(dirpath, filename)).convert_alpha()
    35                     self.tiles[n] = FarmTile(img)
     34                    self.tiles[n] = FarmTile(abstract_dirpath + "/" + filename)
    3635
    3736    def sun(self, sun_on):
     
    4645class FarmTile(vid.Tile):
    4746
    48     NIGHT_COLOUR = (100.0, 100.0, 200.0, 255.0)
    49 
    50     def __init__(self, image):
    51         self.day_image = image
    52         self.night_image = image.copy()
    53         self.night_image.fill(self.NIGHT_COLOUR, None, BLEND_RGBA_MULT)
     47    def __init__(self, image_name):
     48        self.day_image = imagecache.load_image(image_name)
     49        self.night_image = imagecache.load_image(image_name, ("night",))
    5450        self.image = self.day_image
    5551
Note: See TracChangeset for help on using the changeset viewer.