Mercurial > mamba
changeset 67:1b086362d7d4
First mutators (untested).
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sun, 11 Sep 2011 17:39:58 +0200 |
parents | 855bc20b9900 |
children | b88d5cd79fa7 |
files | mamba/mutators.py |
diffstat | 1 files changed, 30 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mamba/mutators.py Sun Sep 11 17:26:05 2011 +0200 +++ b/mamba/mutators.py Sun Sep 11 17:39:58 2011 +0200 @@ -1,3 +1,33 @@ """Mutations to apply to images when they're loaded.""" +from pygame.transform import rotate + +class Mutator(object): + + def __init__(self, func, *args): + self._func = func + sefl._args = args + + def __call__(self, image): + return func(image, *args) + + def __hash__(self): + return hash((id(self._func), self._args)) + + def __eq__(self, other): + return (self._func is other.func) and self._args == other._args + +NULL = Mutator(lambda x: x) + +# sprites mutators +RIGHT = NULL +DOWN = Mutator(rotate, 90) +LEFT = Mutator(rotate, 180) +UP = Mutator(rotate, -90) + +# tile mutators +TL = NULL +BL = Mutator(rotate, -90) +TR = Mutator(rotate, 90) +BR = Mutator(rotate, 180)