Mercurial > rinkhals
comparison gamelib/sprite_cursor.py @ 232:0bd214cf9018
Overlay cost on building sprite cursors.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Fri, 04 Sep 2009 23:59:52 +0000 |
parents | f06010d34cd3 |
children | 9cc7bc5cd10c |
comparison
equal
deleted
inserted
replaced
231:857040b211d5 | 232:0bd214cf9018 |
---|---|
1 """In-game sprite cursors for the gameboard. | 1 """In-game sprite cursors for the gameboard. |
2 | 2 |
3 Currently mostly used when placing buildings. | 3 Currently mostly used when placing buildings. |
4 """ | 4 """ |
5 | 5 |
6 import pygame | |
7 import pygame.font | |
8 from pygame.locals import SRCALPHA | |
9 | |
6 import imagecache | 10 import imagecache |
11 import constants | |
7 from pgu.vid import Sprite | 12 from pgu.vid import Sprite |
13 | |
14 # ignore os.popen3 warning generated by pygame.font.SysFont | |
15 import warnings | |
16 warnings.filterwarnings("ignore", "os.popen3 is deprecated.") | |
8 | 17 |
9 class SpriteCursor(Sprite): | 18 class SpriteCursor(Sprite): |
10 """A Sprite used as an on-board cursor.""" | 19 """A Sprite used as an on-board cursor.""" |
11 | 20 |
12 def __init__(self, image_name, tv): | 21 def __init__(self, image_name, tv, cost=None): |
22 self._font = pygame.font.SysFont('Vera', 20, bold=True) | |
13 image = imagecache.load_image(image_name, ["sprite_cursor"]) | 23 image = imagecache.load_image(image_name, ["sprite_cursor"]) |
24 | |
25 if cost is not None: | |
26 image = image.copy() | |
27 text = self._font.render(str(cost), True, constants.FG_COLOR) | |
28 w, h = image.get_size() | |
29 x, y = text.get_size() | |
30 image.blit(text, (w - x, h - y)) | |
31 | |
14 # Create the sprite somewhere far off screen | 32 # Create the sprite somewhere far off screen |
15 Sprite.__init__(self, image, (-1000, -1000)) | 33 Sprite.__init__(self, image, (-1000, -1000)) |
16 self._tv = tv | 34 self._tv = tv |
17 | 35 |
18 def set_pos(self, tile_pos): | 36 def set_pos(self, tile_pos): |