Mercurial > mamba
changeset 195:d488731886dc
Wean colour overlays off image colour patches.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Wed, 14 Sep 2011 19:10:58 +0200 |
parents | acc8efc0fdc2 |
children | a64cea4eff1a |
files | mamba/mutators.py mamba/snake.py |
diffstat | 2 files changed, 21 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mamba/mutators.py Wed Sep 14 18:54:20 2011 +0200 +++ b/mamba/mutators.py Wed Sep 14 19:10:58 2011 +0200 @@ -2,6 +2,7 @@ from pygame.transform import rotate from pygame.locals import BLEND_MULT +from pygame.surface import Surface from mamba.data import load_image @@ -54,7 +55,23 @@ return image +# colour overlays +class Colour(Mutator): + """Overlay an image with a colour.""" + + def __init__(self, colour, blend=BLEND_MULT): + super(Colour, self).__init__(self.colour, colour, blend) + + def colour(self, image, colour, blend): + image = image.copy() + overlay = Surface(image.get_size(), 0, image) + overlay.fill(colour) + image.blit(overlay, (0, 0), None, blend) + return image + + # colours -BLUE = Overlay("tiles/common/blue.png", BLEND_MULT) -RED = Overlay("tiles/common/red.png", BLEND_MULT) -YELLOW = Overlay("tiles/common/yellow.png", BLEND_MULT) +RED = Colour((0xff, 0, 0)) +BLUE = Colour((0, 0, 255)) +YELLOW = Colour((0xff, 0xff, 0)) +SNAKE_GREEN = Colour((0x7c, 0xff, 0))
--- a/mamba/snake.py Wed Sep 14 18:54:20 2011 +0200 +++ b/mamba/snake.py Wed Sep 14 19:10:58 2011 +0200 @@ -1,7 +1,6 @@ """The player snake object.""" from pygame.sprite import Group, spritecollide -from pygame.locals import BLEND_MULT from mamba.constants import TILE_SIZE from mamba.sprites import BaseSprite @@ -70,7 +69,7 @@ class Segment(BaseSprite): - GREEN = mutators.Overlay("tiles/common/snake/green.png", BLEND_MULT) + GREEN = mutators.SNAKE_GREEN BLUE = mutators.BLUE RED = mutators.RED YELLOW = mutators.YELLOW