-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbutton.py
94 lines (72 loc) · 3.37 KB
/
button.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import pygame.font
class Button:
def __init__(self, ai, msg):
"""Initialize button attributes"""
self.screen = ai.screen
self.screen_rect = self.screen.get_rect()
# Set the dimensions and properties of the button
self.width, self.height = 200, 50
# self.button_color = (0, 185, 0)
self.text_color = (172,231,0)
self.font = pygame.font.Font("Font/fonts.ttf", 48)
# Build the button's rect object and center it
self.rect = pygame.Rect(0, 0, self.width, self.height)
self.rect.centerx += 540
self.rect.centery += 410
# The button message needs to be prepped once
self._prep_msg(msg)
def _prep_msg(self, msg):
"""Turn msg into rendered image and center text on the button"""
self.msg_image = self.font.render(msg, True, self.text_color)
self.msg_image_rect = self.msg_image.get_rect(center=(self.width / 2, self.height / 2))
self.msg_image_rect.centerx += 540
self.msg_image_rect.centery += 405
def draw_button(self):
# Draw blank button then draw message
self.screen.blit(self.msg_image, self.msg_image_rect)
class DButton:
def __init__(self, ai, msg):
"""Initialize button attributes"""
self.screen = ai.screen
self.screen_rect = self.screen.get_rect()
# Set the dimensions and properties of the button
self.width, self.height = 200, 50
# self.button_color = (0, 185, 0)
self.text_color = (0, 215, 165)
self.font = pygame.font.Font("Font/font.ttf", 48)
# The button message needs to be prepped once
self._prep_msg(msg)
def _prep_msg(self, msg):
"""Turn msg into rendered image and center text on the button"""
self.msg_image = self.font.render(msg, True, self.text_color)
self.msg_image_rect = self.msg_image.get_rect(center=(self.width / 2, self.height / 2))
self.msg_image_rect.centerx += 540
self.msg_image_rect.centery += 480
def draw_button(self):
# Draw blank button then draw message
self.screen.blit(self.msg_image, self.msg_image_rect)
class Sign:
def __init__(self, ai, msg):
"""Initialize button attributes"""
self.screen = ai.screen
self.screen_rect = self.screen.get_rect()
# Set the dimensions and properties of the button
self.width, self.height = 200, 50
# self.button_color = (0, 185, 0)
self.text_color = (172,231,0)
self.font = pygame.font.Font("Font/fonts.ttf", 32)
# Build the button's rect object and center it
self.rect = pygame.Rect(0, 0, self.width, self.height)
self.rect.centerx += 140
self.rect.centery += 210
# The button message needs to be prepped once
self._prep_msg(msg)
def _prep_msg(self, msg):
"""Turn msg into rendered image and center text on the button"""
self.msg_image = self.font.render(msg, True, self.text_color)
self.msg_image_rect = self.msg_image.get_rect(center=(self.width / 2, self.height / 2))
self.msg_image_rect.centerx += 540
self.msg_image_rect.centery += 500
def draw_button(self):
# Draw blank button then draw message
self.screen.blit(self.msg_image, self.msg_image_rect)