-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.py
More file actions
201 lines (164 loc) · 7.65 KB
/
system.py
File metadata and controls
201 lines (164 loc) · 7.65 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import pygame
from themes.colors import *
from themes.animations import *
from grid import *
from themes.themes import *
class button():
def __init__(self, x, y,width,height, theme_type,text=''):
self.theme_type = theme_type
self.color = themes[self.theme_type]["inactive_button_color"]
self.x = x
self.y = y
self.width = width
self.height = height
self.text = text
def draw(self,win,theme_type,outline=True):
mouse_pos = pygame.mouse.get_pos()
if self.x < mouse_pos[0] < self.x + self.width and self.y < mouse_pos[1] < self.y + self.height:
self.color = themes[theme_type]["active_button_color"]
else:
self.color = themes[theme_type]["inactive_button_color"]
if outline:
pygame.draw.rect(win, themes[theme_type]["button_outline_color"], (self.x-2,self.y-2,self.width+4,self.height+4),0)
pygame.draw.rect(win, self.color, (self.x,self.y,self.width,self.height),0)
if self.text != '':
font = pygame.font.SysFont('verdana', 20)
text = font.render(self.text, 1, themes[theme_type]["button_text_color"])
win.blit(text, (self.x + (self.width/2 - text.get_width()/2), self.y + (self.height/2 - text.get_height()/2)))
def is_hover(self, pos):
#Pos is the mouse position or a tuple of (x,y) coordinates
if pos[0] > self.x-self.height//2 and pos[0] < self.x + self.width+self.height//2:
if pos[1] > self.y and pos[1] < self.y + self.height:
return True
return False
def toggle_color(self):
if(self.color == themes[self.theme_type]["inactive_button_color"]):
self.color = themes[self.theme_type]["active_button_color"]
else:
self.color = themes[self.theme_type]["inactive_button_color"]
class screen():
def __init__(self, x,y,width,height,text='',color=SCREEN_COLOR):
self.color = color
self.x = x
self.y = y
self.width = width
self.height = height
self.label1 = ""
self.text1 = text
self.text2 = ""
self.text3 = ""
self.text4 = ""
self.error_message = ""
def set_label1(self, label):
self.label1 = label
def set_text1(self, text):
self.text1 = text
def set_text2(self, text):
self.text2 = text
def set_text3(self, text):
self.text3 = text
def set_text4(self, text):
self.text4 = text
def set_error_message(self, text):
self.error_message = text
def get_text1(self):
return self.text1
def draw(self,win,theme_type,outline=None):
if outline:
pygame.draw.rect(win, outline, (self.x-2,self.y-2,self.width+4,self.height+4),0)
pygame.draw.rect(win, themes[theme_type]["output_screen_color"], (self.x,self.y,self.width,self.height),0)
if self.label1 != '':
font = pygame.font.SysFont('verdana', 20)
label = font.render(self.label1, 1, (0,0,0))
win.blit(label, (self.x + 10, self.y + 10))
if self.text1 != '':
font = pygame.font.SysFont('verdana', 30)
text = font.render(self.text1, 1, (0,0,0))
win.blit(text, (self.x + (self.width/2 - text.get_width()/2), self.y + (self.height/2 - text.get_height()/2) - 80))
if self.text2 != '':
font = pygame.font.SysFont('verdana', 30)
text = font.render(self.text2, 1, (0,0,0))
win.blit(text, (self.x + (self.width/2 - text.get_width()/2)+15, self.y + (self.height/2 - text.get_height()/2)))
if self.error_message!='':
font = pygame.font.SysFont('verdana', 30)
error_message = font.render(self.error_message, 1, themes[theme_type]["font_color"])
win.blit(error_message, (self.x + (self.width/3 - text.get_width()/2), self.y + (self.height/2 - text.get_height()/2)))
if self.text3 != '':
font = pygame.font.SysFont('verdana', 30)
text = font.render(self.text3, 1, (0,0,0))
win.blit(text, (self.x + (self.width/2 - text.get_width()/2)+15 , 50 + self.y + (self.height/2 - text.get_height()/2)))
if self.text4 != '':
font = pygame.font.SysFont('verdana', 15)
lines = self.text4.split('\n')
for i, line in enumerate(lines):
text = font.render(line, 1, (0,0,0))
win.blit(text, (self.x+10, self.y + (self.height/2 - text.get_height()/2) - 45+ i*font.get_height()))
def is_hover(self, pos):
#Pos is the mouse position or a tuple of (x,y) coordinates
if pos[0] > self.x and pos[0] < self.x + self.width:
if pos[1] > self.y and pos[1] < self.y + self.height:
return True
return False
def create_button(button, image, position):
button["image"] = image
button["rect"] = image.get_rect(topleft=position)
def is_hover(button, pos):
if button["rect"].collidepoint(pos):
return True
else:
return False
def draw(win, grid, rows, width, algorithms, mazes, back_button, mode_button, sound_button, options, output, theme_type, menu = True):
win.fill(themes[theme_type]["menu_bg_color"])
for row in grid:
for node in row:
if theme_type == "Synth":
node.theme_type = "Synth"
node.draw(win)
draw_grid(win, grid, width, theme_type)
if menu:
n = 17
delta = 700
ht = 900
width = ht
w = 1600
font = pygame.font.SysFont('verdana', 35)
text = font.render("Path Finding Algorithms", 1, themes[theme_type]["heading_color"])
top = 0
end = ht//40
win.blit(back_button["image"], back_button["rect"])
win.blit(text, ((width+delta//10)-20, (end-top)/2.5))
win.blit(mode_button["image"], mode_button["rect"])
win.blit(sound_button["image"], sound_button["rect"])
for algorithm in algorithms:
if theme_type == "Synth":
algorithm.theme_type = "Synth"
else:
algorithm.theme_type = "Default"
algorithm.draw(win,theme_type=theme_type)
text = font.render("Generate Maze", 1, themes[theme_type]["heading_color"])
but_height = ht//15
top += (4.3*but_height)
end += (1.9*(3*but_height//2)) + but_height + ht//12
win.blit(text, (width+delta//5.2, (end-top) + top))
for maze in mazes:
if theme_type == "Synth":
maze.theme_type = "Synth"
else:
maze.theme_type = "Default"
maze.draw(win,theme_type=theme_type)
end += (1.3*(3*but_height//2)) + ht//6
top += (1.7*but_height//2)
text = font.render("Grid Settings", 1, themes[theme_type]["heading_color"])
win.blit(text, (width+delta//4.7, ((end-top)/2) + top))
for option in options:
if theme_type == "Synth":
option.theme_type = "Synth"
else:
option.theme_type = "Default"
option.draw(win,theme_type=theme_type)
if theme_type == "Synth":
output.theme_type = "Synth"
else:
output.theme_type = "Default"
output.draw(win,theme_type=theme_type)
pygame.display.update()