view gamelib/sprite_cursor.py @ 186:f06010d34cd3

Add sprite cursors for building placement.
author Simon Cross <hodgestar@gmail.com>
date Fri, 04 Sep 2009 17:49:37 +0000
parents
children 0bd214cf9018
line wrap: on
line source

"""In-game sprite cursors for the gameboard.

   Currently mostly used when placing buildings.
   """

import imagecache
from pgu.vid import Sprite

class SpriteCursor(Sprite):
    """A Sprite used as an on-board cursor."""

    def __init__(self, image_name, tv):
        image = imagecache.load_image(image_name, ["sprite_cursor"])
        # Create the sprite somewhere far off screen
        Sprite.__init__(self, image, (-1000, -1000))
        self._tv = tv

    def set_pos(self, tile_pos):
        """Set the cursor position on the gameboard."""
        self.rect.x, self.rect.y = self._tv.tile_to_view(tile_pos)