# HG changeset patch # User Simon Cross # Date 1251658288 0 # Node ID 2eec29085060ffa7bed02402d2700a719a2caf3b # Parent 2e88c680672c31b7d2fb0b5ca10e4d3ac083fceb Color night and day. diff -r 2e88c680672c -r 2eec29085060 gamelib/engine.py --- a/gamelib/engine.py Sun Aug 30 18:46:46 2009 +0000 +++ b/gamelib/engine.py Sun Aug 30 18:51:28 2009 +0000 @@ -43,6 +43,8 @@ class DayState(State): def init(self): """Add some chickens to the farm""" + self.game.gameboard.tv.sun(True) + # disable timer pygame.time.set_timer(MOVE_FOX_ID, 0) # Very simple, we walk around the tilemap, and, for each farm tile, @@ -110,6 +112,8 @@ class NightState(State): def init(self): """Add some foxes to the farm""" + self.game.gameboard.tv.sun(False) + # Add a timer to the event queue self.cycle_count = 0 pygame.time.set_timer(MOVE_FOX_ID, 300) diff -r 2e88c680672c -r 2eec29085060 gamelib/tiles.py --- 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