-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenus.py
248 lines (209 loc) · 9.81 KB
/
menus.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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
"""
Monza Game - Menus
Description: Contains functions and logic related to the game's main menu and post-game menu.
Author(s): Daniel Sotelo, Jiajun Xu, Vladyslav Korenyak
Date: 09/10/2023
Version: 2.0
"""
# Import libraries
import pygame
import sys
from settings import *
from game_objects import Button
from utils import draw_mit_license_and_authors, plot_graphs
# Create main menu
def main_menu(screen):
font = pygame.font.Font(None, 36)
manual_image = pygame.image.load("assets/main_menu/manual.png")
controller_image = pygame.image.load("assets/main_menu/controller.png")
buttons = [
Button(50, 550, 300, 80, "Manual Gameplay", manual_image),
Button(SCREEN_WIDTH - 390, 550, 340, 80, "Controller Gameplay", controller_image)
]
# Create title
title_image = pygame.image.load("assets/main_menu/title_menu.png")
title_image = pygame.transform.scale(title_image, (554, 156))
# Create main menu image
img = pygame.image.load("assets/main_menu/menu.png")
img_rect = img.get_rect(center=(SCREEN_WIDTH//2, SCREEN_HEIGHT//2))
while True:
screen.fill(BEIGE)
draw_mit_license_and_authors(screen, BROWN)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
if buttons[0].is_clicked(pos, event):
return "diff_menu_manual"
if buttons[1].is_clicked(pos, event):
return "diff_menu_controller"
# Draw the title and image
title_rect = title_image.get_rect(center=(SCREEN_WIDTH // 2, 100))
screen.blit(title_image, title_rect)
screen.blit(img, img_rect)
# Draw the buttons
for button in buttons:
button.draw(screen, font, BROWN)
pygame.display.flip()
# Define the difficulty selection menu
def diff_menu(screen):
font = pygame.font.Font(None, 36)
buttons = [
Button(20, 375, 175, 250, "Beginner", None, 1),
Button(215, 375, 175, 250, "Intermediate", None, 1),
Button(410, 375, 175, 250, "Expert", None, 1),
Button(605, 375, 175, 250, "Legendary", None, 1),
Button(10, 660, 80, 30, "Back", None, 1, 25)
]
# Difficulty images
beginner_image = pygame.image.load("assets/diff_menu/beginner.png")
intermediate_image = pygame.image.load("assets/diff_menu/intermediate.png")
expert_image = pygame.image.load("assets/diff_menu/expert.png")
legendary_image = pygame.image.load("assets/diff_menu/legendary.png")
beginner_image = pygame.transform.scale(beginner_image, (120, 107))
intermediate_image = pygame.transform.scale(intermediate_image, (120, 107))
expert_image = pygame.transform.scale(expert_image, (120, 107))
legendary_image = pygame.transform.scale(legendary_image, (120, 107))
# Create title
title_image = pygame.image.load("assets/main_menu/title_menu.png")
title_image = pygame.transform.scale(title_image, (554, 156))
while True:
screen.fill(BEIGE)
draw_mit_license_and_authors(screen, BROWN)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
if buttons[0].is_clicked(pos, event):
return 0
if buttons[1].is_clicked(pos, event):
return 1
if buttons[2].is_clicked(pos, event):
return 2
if buttons[3].is_clicked(pos, event):
return 3
if buttons[4].is_clicked(pos, event):
return "main_menu"
# Draw the title and images
title_rect = title_image.get_rect(center = (SCREEN_WIDTH // 2, 125))
screen.blit(title_image, title_rect)
beginner_rect = beginner_image.get_rect(center = (107.5, 290))
screen.blit(beginner_image, beginner_rect)
intermediate_rect = intermediate_image.get_rect(center = (302.5, 290))
screen.blit(intermediate_image, intermediate_rect)
expert_rect = expert_image.get_rect(center = (497.5, 290))
screen.blit(expert_image, expert_rect)
legendary_rect = legendary_image.get_rect(center = (692.5, 290))
screen.blit(legendary_image, legendary_rect)
# Draw the buttons
for button in buttons:
button.draw(screen, font, BROWN)
pygame.display.flip()
# Define the controllers menu
def controllers_menu(screen):
font = pygame.font.Font(None, 36)
buttons = [
Button(65, 375, 180, 250, ["Controller 1", " ", "Sliding Mode", "Controller", "(SMC)"], None, 1),
Button(310, 375, 180, 250, ["Controller 2", " ", "Fuzzy Logic", " ", " "], None, 1),
Button(555, 375, 180, 250, ["Controller 3", " ", "Reinforcement", "Learning", " "], None, 1),
Button(10, 660, 80, 30, "Back", None, 1, 25)
]
# Controller images
controller_image = pygame.image.load("assets/controllers_menu/SMC.png") # Cambiar imagenes cuando tengamos las ideas para cada uno de los controladores
controller_image = pygame.transform.scale(controller_image, (80, 80))
# Create title
title_image = pygame.image.load("assets/main_menu/title_menu.png")
title_image = pygame.transform.scale(title_image, (554, 156))
while True:
screen.fill(BEIGE)
draw_mit_license_and_authors(screen, BROWN)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
if buttons[0].is_clicked(pos, event):
return 1
if buttons[1].is_clicked(pos, event):
return 2
if buttons[2].is_clicked(pos, event):
return 3
if buttons[3].is_clicked(pos, event):
return "diff_menu_controller"
# Draw the title and images
title_rect = title_image.get_rect(center = (SCREEN_WIDTH // 2, 125))
screen.blit(title_image, title_rect)
controller_rect = controller_image.get_rect(center = (155, 290))
screen.blit(controller_image, controller_rect)
controller_rect = controller_image.get_rect(center = (400, 290))
screen.blit(controller_image, controller_rect)
controller_rect = controller_image.get_rect(center = (645, 290))
screen.blit(controller_image, controller_rect)
# Draw the buttons
for button in buttons:
button.draw(screen, font, BROWN)
pygame.display.flip()
# Define post-game menu
def post_game_menu(screen, result, positions, mode):
font = pygame.font.Font(None, 36)
# Load and scale images
win_image = pygame.image.load("assets/postgame_menu/win_game.png")
win_image = pygame.transform.scale(win_image, (275, 241))
try_image = pygame.image.load("assets/postgame_menu/exit_utile_area.png")
try_image = pygame.transform.scale(try_image, (300, 241))
try_again_button = pygame.image.load("assets/postgame_menu/try_again.png")
main_menu_button = pygame.image.load("assets/postgame_menu/main_menu.png")
plot_graphs_button = pygame.image.load("assets/postgame_menu/plot_graphs.png")
exit_button = pygame.image.load("assets/postgame_menu/exit.png")
# Define buttons
buttons = [
Button(100, 310, 275, 150, "Try Again", try_again_button),
Button(100, 490, 275, 150, "Main Menu", main_menu_button),
Button(425, 310, 275, 150, "Plot Graphs", plot_graphs_button),
Button(425, 490, 275, 150, "Exit", exit_button)
]
while True:
screen.fill(BEIGE)
draw_mit_license_and_authors(screen, BROWN)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
if buttons[0].is_clicked(pos, event):
if mode == "manual":
return "start_game_manual"
else:
return "start_game_controller"
if buttons[1].is_clicked(pos, event):
return "main_menu"
if buttons[2].is_clicked(pos, event):
plot_graphs(positions)
pygame.quit()
sys.exit()
if buttons[3].is_clicked(pos, event):
pygame.quit()
sys.exit()
# Display a message related to the result of the game (Win/Lose)
if result == "win":
message_1 = "Congratulations! You have reached the end! :D"
screen.blit(win_image, ((SCREEN_WIDTH - win_image.get_width()) // 2, 60))
elif result == "lose":
message_1 = "The coin has exited the utile area! :("
screen.blit(try_image, ((SCREEN_WIDTH - try_image.get_width()) // 2, 60))
elif result == "lost_contact":
message_1 = "The coin has lost contact with the rail! :("
screen.blit(try_image, ((SCREEN_WIDTH - try_image.get_width()) // 2, 60))
text_1 = font.render(message_1, True, BROWN)
rect_1 = text_1.get_rect(center = (SCREEN_WIDTH // 2, 50))
screen.blit(text_1, rect_1)
# Draw the buttons
for button in buttons:
button.draw(screen, font, BROWN)
pygame.display.flip()