You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
792 B
27 lines
792 B
import pygame as pg
|
|
from sprite import Sprite
|
|
|
|
SIZE = 24
|
|
UNIT = SIZE//4
|
|
COLOR =(255,0,0)
|
|
C_POINT = (2,2)
|
|
SHAPE = (
|
|
(0,1), C_POINT, (4,1),
|
|
(3,0), C_POINT, (3,4),
|
|
(4,3), C_POINT, (0,3),
|
|
(1,4), C_POINT, (1,0),
|
|
)
|
|
|
|
|
|
class Crosshair(Sprite):
|
|
def __init__(self, scr_rect):
|
|
super().__init__((SIZE,)*2)
|
|
self.rect.x = scr_rect.centerx - self.rect.width / 2
|
|
self.rect.y = scr_rect.centery - self.rect.height / 2
|
|
self.image.fill(self.image.get_colorkey())
|
|
scaled_shape = [(x*UNIT, y*UNIT) for x, y in SHAPE]
|
|
pg.draw.polygon(self.image, COLOR, scaled_shape)
|
|
|
|
def update(self, new_pos):
|
|
self.rect.x = new_pos.x - self.rect.width / 2
|
|
self.rect.y = new_pos.y - self.rect.height / 2
|
|
|