Mercurial > mamba
changeset 85:5dd9d91aa94f
Overlay mutators (untested).
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sun, 11 Sep 2011 18:57:11 +0200 |
parents | cced0ddda33f |
children | f894666defc7 |
files | mamba/mutators.py |
diffstat | 1 files changed, 27 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mamba/mutators.py Sun Sep 11 18:43:21 2011 +0200 +++ b/mamba/mutators.py Sun Sep 11 18:57:11 2011 +0200 @@ -1,6 +1,9 @@ """Mutations to apply to images when they're loaded.""" from pygame.transform import rotate +from pygame.locals import BLEND_ADD, BLEND_MULT + +from mamba.data import load_image class Mutator(object): @@ -18,6 +21,8 @@ def __eq__(self, other): return (self._func is other.func) and self._args == other._args + +# mutator that does nothing NULL = Mutator(lambda x: x) # sprites mutators @@ -31,3 +36,25 @@ BL = Mutator(rotate, -90) TR = Mutator(rotate, 90) BR = Mutator(rotate, 180) + + +# overlays +class Overlay(Mutator): + """Overlay another image on top of the given one.""" + + BLEND = BLEND_ADD + + def __init__(self, filename, blend=None): + if blend is None: + blend = self.BLEND + super(Overlay, self).__init__(self.overlay, blend, filename) + + def overlay(self, image, filename, blend): + image = image.copy() + overlay = load_image(filename) + overlay.blit(image, None, blend) + return image + + +class Multiply(Overlay): + BLEND = BLEND_MULT