-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtons.py
35 lines (27 loc) · 1.12 KB
/
Buttons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import pygame
from Utils.Settings import Settings
class Buttons:
# X and Y are location of the button. The class itself will center the word.
def __init__(self, word, font, x, y, screen):
self.color = (255, 255, 255)
self.word = word
self.font = font
self.screen = screen
self.settings = Settings()
self.x = x
self.y = y
self.drawn = False
self.width = font.size(word)
self.button = pygame.Rect(self.x - self.width[0]/2 - 5, self.y - self.width[1]/2 - 5,
self.width[0] + 10, self.width[1] + 10)
def draw_button(self):
render = self.font.render(self.word, True, (255, 255, 255))
pygame.draw.rect(self.screen, self.settings.main_menu_button_color, self.button)
self.screen.blit(render, (self.x - self.width[0]/2, self.y - self.width[1]/2))
self.drawn = True
def collide_point(self, x, y):
return self.button.collidepoint((x, y)) and self.drawn
def update_drawn(self, boolean):
self.drawn = boolean
def change_color(self, color):
self.color = color