diff 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
line wrap: on
line diff
--- a/gamelib/tiles.py	Sun Aug 30 18:46:46 2009 +0000
+++ b/gamelib/tiles.py	Sun Aug 30 18:51:28 2009 +0000
@@ -2,6 +2,7 @@
 
 from pgu import tilevid, vid
 import pygame
+from pygame.locals import BLEND_RGBA_MULT
 import os
 
 TILE_MAP = {
@@ -33,5 +34,27 @@
                     img = pygame.image.load(os.path.join(dirpath, filename)).convert_alpha()
                     self.tiles[n] = FarmTile(img)
 
+    def sun(self, sun_on):
+        """Make it night."""
+        for tile in self.tiles:
+            if hasattr(tile, "sun"):
+                tile.sun(sun_on)
+        for sprite in self.sprites:
+            if hasattr(sprite, "sun"):
+                sprite.sun(sun_on)
+
 class FarmTile(vid.Tile):
-    pass
+
+    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)
+        self.image = self.day_image
+
+    def sun(self, sun_on):
+        if sun_on:
+            self.image = self.day_image
+        else:
+            self.image = self.night_image