rendered paste body##
## cursor.py
##
## Split Visionaries is (c)2006, Rikard Bosnjakovic <bos@hack.org>
##
## Last update: 2006-06-25
##
import pygame
class Cursor:
def __init__(self, size, limit):
# size in pixels
self.size = size
# max value for x/y-movement
self.limit = (limit - 1, limit)
# paint and store the cursor
self.init_cursor()
# initiate the cursor at the first board block
self.pos_x = 0
self.pos_y = 0
self.pos = (self.pos_x, self.pos_y)
def init_cursor(self):
# draw a cursor
size = self.size
self.surface = pygame.Surface((size, size))
self.surface.set_alpha(150)
self.surface.fill( (255, 255, 255) )
self.surface = self.surface.convert_alpha()
# make a hole in the middle
x = y = int(size * 0.1)
width = height = int(size - 2*x)
_rect = (x, y, width, height)
_RGBA = (0, 0, 0, 0)
pygame.draw.rect(self.surface, _RGBA, _rect)
def move(self, direction):
# current pos
_x, _y = self.pos
# direction
x, y = direction
# add delta to current position
_x += x
_y += y
limit = self.limit
if _x > limit[0]: _x = limit[0]
if _x < 0: _x = 0
if _y > limit[1]: _y = limit[1]
if _y < 0: _y = 0
self.pos = (_x, _y)