Mercurial > rinkhals
comparison gamelib/imagecache.py @ 159:7bb8d9d6858a
Darken center of game over splash screen to make text legible.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Thu, 03 Sep 2009 22:00:28 +0000 |
parents | f20dd3dcb118 |
children | 7e556ef40100 |
comparison
equal
deleted
inserted
replaced
158:baf857805867 | 159:7bb8d9d6858a |
---|---|
54 self._cache[key] = image | 54 self._cache[key] = image |
55 return image | 55 return image |
56 | 56 |
57 # modifiers | 57 # modifiers |
58 | 58 |
59 from pygame.locals import BLEND_RGBA_MULT | 59 from pygame.locals import BLEND_RGBA_MULT, BLEND_MULT |
60 NIGHT_COLOUR = (100.0, 100.0, 200.0, 255.0) | 60 NIGHT_COLOUR = (100.0, 100.0, 200.0, 255.0) |
61 DARKEN_COLOUR = (100.0, 100.0, 100.0, 255.0) | |
61 | 62 |
62 def convert_to_night(image): | 63 def convert_to_night(image): |
63 """Convert a day tile to a night tile.""" | 64 """Convert a day tile to a night tile.""" |
64 night_image = image.copy() | 65 night_image = image.copy() |
65 night_image.fill(NIGHT_COLOUR, None, BLEND_RGBA_MULT) | 66 night_image.fill(NIGHT_COLOUR, None, BLEND_RGBA_MULT) |
68 def convert_to_right_facing(image): | 69 def convert_to_right_facing(image): |
69 right_facing_image = image.copy() | 70 right_facing_image = image.copy() |
70 right_facing_image = pygame.transform.flip(right_facing_image, 1, 0) | 71 right_facing_image = pygame.transform.flip(right_facing_image, 1, 0) |
71 return right_facing_image | 72 return right_facing_image |
72 | 73 |
74 def darken_center(image): | |
75 darkened = image.copy() | |
76 w, h = darkened.get_size() | |
77 w, h = int(w*0.5), int(h*0.5) | |
78 x, y = int(w*0.5), int(h*0.5) | |
79 overlay = pygame.Surface((w, h)) | |
80 overlay.fill(DARKEN_COLOUR) | |
81 darkened.blit(overlay, (x,y), None, BLEND_MULT) | |
82 return darkened | |
83 | |
73 # globals | 84 # globals |
74 | 85 |
75 cache = ImageCache() | 86 cache = ImageCache() |
76 cache.register_modifier("night", convert_to_night) | 87 cache.register_modifier("night", convert_to_night) |
77 cache.register_modifier("right_facing", convert_to_right_facing) | 88 cache.register_modifier("right_facing", convert_to_right_facing) |
89 cache.register_modifier("darken_center", darken_center) | |
78 load_image = cache.load_image | 90 load_image = cache.load_image |