Mercurial > rinkhals
changeset 30:2eec29085060
Color night and day.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sun, 30 Aug 2009 18:51:28 +0000 |
parents | 2e88c680672c |
children | 3c4db7bba432 |
files | gamelib/engine.py gamelib/tiles.py |
diffstat | 2 files changed, 28 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- 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