Changeset 232:0bd214cf9018


Ignore:
Timestamp:
Sep 4, 2009, 11:59:52 PM (11 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Convert:
svn:b4e93282-eac8-4b8b-b765-0f5d36de2b68@233
Message:

Overlay cost on building sprite cursors.

Location:
gamelib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gamelib/gameboard.py

    r228 r232  
    259259        sprite_curs = None
    260260        if buildings.is_building(tool):
    261             sprite_curs = sprite_cursor.SpriteCursor(tool.IMAGE, self.tv)
     261            sprite_curs = sprite_cursor.SpriteCursor(tool.IMAGE, self.tv, tool.BUY_PRICE)
    262262        if tool == constants.TOOL_BUY_FENCE:
    263263            sprite_curs = sprite_cursor.SpriteCursor("tiles/fence.png", self.tv)
  • gamelib/sprite_cursor.py

    r186 r232  
    44   """
    55
     6import pygame
     7import pygame.font
     8from pygame.locals import SRCALPHA
     9
    610import imagecache
     11import constants
    712from pgu.vid import Sprite
     13
     14# ignore os.popen3 warning generated by pygame.font.SysFont
     15import warnings
     16warnings.filterwarnings("ignore", "os.popen3 is deprecated.")
    817
    918class SpriteCursor(Sprite):
    1019    """A Sprite used as an on-board cursor."""
    1120
    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)
    1323        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
    1432        # Create the sprite somewhere far off screen
    1533        Sprite.__init__(self, image, (-1000, -1000))
Note: See TracChangeset for help on using the changeset viewer.