Mercurial > mamba
comparison mamba/mutators.py @ 85:5dd9d91aa94f
Overlay mutators (untested).
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sun, 11 Sep 2011 18:57:11 +0200 |
parents | 80c97a6e53d2 |
children | 9c43a23aa204 |
comparison
equal
deleted
inserted
replaced
84:cced0ddda33f | 85:5dd9d91aa94f |
---|---|
1 """Mutations to apply to images when they're loaded.""" | 1 """Mutations to apply to images when they're loaded.""" |
2 | 2 |
3 from pygame.transform import rotate | 3 from pygame.transform import rotate |
4 from pygame.locals import BLEND_ADD, BLEND_MULT | |
5 | |
6 from mamba.data import load_image | |
4 | 7 |
5 | 8 |
6 class Mutator(object): | 9 class Mutator(object): |
7 | 10 |
8 def __init__(self, func, *args): | 11 def __init__(self, func, *args): |
16 return hash((id(self._func), self._args)) | 19 return hash((id(self._func), self._args)) |
17 | 20 |
18 def __eq__(self, other): | 21 def __eq__(self, other): |
19 return (self._func is other.func) and self._args == other._args | 22 return (self._func is other.func) and self._args == other._args |
20 | 23 |
24 | |
25 # mutator that does nothing | |
21 NULL = Mutator(lambda x: x) | 26 NULL = Mutator(lambda x: x) |
22 | 27 |
23 # sprites mutators | 28 # sprites mutators |
24 RIGHT = NULL | 29 RIGHT = NULL |
25 DOWN = Mutator(rotate, 90) | 30 DOWN = Mutator(rotate, 90) |
29 # tile mutators | 34 # tile mutators |
30 TL = NULL | 35 TL = NULL |
31 BL = Mutator(rotate, -90) | 36 BL = Mutator(rotate, -90) |
32 TR = Mutator(rotate, 90) | 37 TR = Mutator(rotate, 90) |
33 BR = Mutator(rotate, 180) | 38 BR = Mutator(rotate, 180) |
39 | |
40 | |
41 # overlays | |
42 class Overlay(Mutator): | |
43 """Overlay another image on top of the given one.""" | |
44 | |
45 BLEND = BLEND_ADD | |
46 | |
47 def __init__(self, filename, blend=None): | |
48 if blend is None: | |
49 blend = self.BLEND | |
50 super(Overlay, self).__init__(self.overlay, blend, filename) | |
51 | |
52 def overlay(self, image, filename, blend): | |
53 image = image.copy() | |
54 overlay = load_image(filename) | |
55 overlay.blit(image, None, blend) | |
56 return image | |
57 | |
58 | |
59 class Multiply(Overlay): | |
60 BLEND = BLEND_MULT |