feat(startscreen): implement button draw method
This commit is contained in:
+24
-1
@@ -22,6 +22,29 @@ class Button:
|
||||
def draw(self, screen):
|
||||
action = False
|
||||
|
||||
# todo
|
||||
# get current mous position
|
||||
mouse_pos = pygame.mouse.get_pos()
|
||||
|
||||
# check if mouse is over button
|
||||
if self.rect.collidepoint(mouse_pos):
|
||||
current_color = self.hover
|
||||
|
||||
# check if left mouse button is pressed
|
||||
if pygame.mouse.get_pressed()[0] == 0 and self.clicked:
|
||||
self.clicked = False
|
||||
action = True
|
||||
else:
|
||||
current_color = self.color
|
||||
self.clicked = False
|
||||
|
||||
# draw buttton
|
||||
pygame.draw.rect(screen, current_color, self.rect, border_radius = 12)
|
||||
|
||||
# render button text
|
||||
text_surface = self.font.render(self.text, True, (255, 255, 255))
|
||||
|
||||
# place text in the middle of the button
|
||||
text_rect = text_surface.get_rect(center=self.rect.center)
|
||||
screen.blit(text_surface, text_rect)
|
||||
|
||||
return action
|
||||
Reference in New Issue
Block a user