comparison gamelib/tiles.py @ 30:2eec29085060

Color night and day.
author Simon Cross <hodgestar@gmail.com>
date Sun, 30 Aug 2009 18:51:28 +0000
parents 7584453f4944
children dd9d2a4dd494
comparison
equal deleted inserted replaced
29:2e88c680672c 30:2eec29085060
1 """Extension to pgu's tilevid.""" 1 """Extension to pgu's tilevid."""
2 2
3 from pgu import tilevid, vid 3 from pgu import tilevid, vid
4 import pygame 4 import pygame
5 from pygame.locals import BLEND_RGBA_MULT
5 import os 6 import os
6 7
7 TILE_MAP = { 8 TILE_MAP = {
8 0: "woodland", 9 0: "woodland",
9 1: "grassland", 10 1: "grassland",
31 if basename in REVERSE_TILE_MAP: 32 if basename in REVERSE_TILE_MAP:
32 n = REVERSE_TILE_MAP[basename] 33 n = REVERSE_TILE_MAP[basename]
33 img = pygame.image.load(os.path.join(dirpath, filename)).convert_alpha() 34 img = pygame.image.load(os.path.join(dirpath, filename)).convert_alpha()
34 self.tiles[n] = FarmTile(img) 35 self.tiles[n] = FarmTile(img)
35 36
37 def sun(self, sun_on):
38 """Make it night."""
39 for tile in self.tiles:
40 if hasattr(tile, "sun"):
41 tile.sun(sun_on)
42 for sprite in self.sprites:
43 if hasattr(sprite, "sun"):
44 sprite.sun(sun_on)
45
36 class FarmTile(vid.Tile): 46 class FarmTile(vid.Tile):
37 pass 47
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)
54 self.image = self.day_image
55
56 def sun(self, sun_on):
57 if sun_on:
58 self.image = self.day_image
59 else:
60 self.image = self.night_image