60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
|
import pygame
|
||
|
|
||
|
# Event type constants.
|
||
|
MOUSEBUTTONDOWN = pygame.MOUSEBUTTONDOWN
|
||
|
MOUSEBUTTONUP = pygame.MOUSEBUTTONUP
|
||
|
MOUSEMOTION = pygame.MOUSEMOTION
|
||
|
|
||
|
class Render:
|
||
|
"""
|
||
|
Provides basic drawing functions via Pygame.
|
||
|
"""
|
||
|
def __init__(self, surface):
|
||
|
self.surface = surface
|
||
|
self.font = pygame.font.SysFont("Arial", 16)
|
||
|
|
||
|
def draw_rect(self, color, rect, border=0):
|
||
|
pygame.draw.rect(self.surface, color, rect, border)
|
||
|
|
||
|
def draw_text(self, text, pos, color=(255, 255, 255)):
|
||
|
text_surface = self.font.render(text, True, color)
|
||
|
self.surface.blit(text_surface, pos)
|
||
|
|
||
|
def draw_line(self, color, start_pos, end_pos, width=1):
|
||
|
pygame.draw.line(self.surface, color, start_pos, end_pos, width)
|
||
|
|
||
|
def draw_circle(self, color, center, radius, border=0):
|
||
|
pygame.draw.circle(self.surface, color, center, radius, border)
|
||
|
|
||
|
class Rect:
|
||
|
"""
|
||
|
A simple rectangle wrapper.
|
||
|
"""
|
||
|
def __init__(self, x, y, width, height):
|
||
|
self.rect = pygame.Rect(x, y, width, height)
|
||
|
|
||
|
@property
|
||
|
def x(self):
|
||
|
return self.rect.x
|
||
|
|
||
|
@property
|
||
|
def y(self):
|
||
|
return self.rect.y
|
||
|
|
||
|
@property
|
||
|
def width(self):
|
||
|
return self.rect.width
|
||
|
|
||
|
@property
|
||
|
def height(self):
|
||
|
return self.rect.height
|
||
|
|
||
|
def collidepoint(self, pos):
|
||
|
return self.rect.collidepoint(pos)
|
||
|
|
||
|
def get_mouse_pos():
|
||
|
return pygame.mouse.get_pos()
|
||
|
|
||
|
def get_mouse_pressed():
|
||
|
return pygame.mouse.get_pressed()
|