-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenus.py
147 lines (117 loc) · 6.24 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
import pygame
def show_game_over_screen(screen, score, background, restart_button, main_menu_button):
title_font = pygame.font.Font('fonts/PressStart2P.ttf', 40)
score_font = pygame.font.Font('fonts/PressStart2P.ttf', 30)
#Blit Background
for i in range(0, 2):
screen.blit(background, (i * background.get_width(), 0 ))
screen.blit(background, (0, 0))
# Blit Text
title_text = title_font.render("Game Over", True, (255, 0, 0))
score_text = score_font.render(f'Score: {score}', True, (255, 0, 0))
screen.blit(score_text, (screen.get_width() / 2 - score_text.get_width() / 2, screen.get_height() / 2 - score_text.get_height() / 2 + 5))
screen.blit(title_text, (screen.get_width() / 2 - title_text.get_width() / 2, screen.get_height() / 2 - title_text.get_height() / 2 - 45))
# Buttons
button_surface = pygame.Surface((main_menu_button.get_width() + restart_button.get_width() + 50, main_menu_button.get_height()))
button_surface.fill((0, 0, 0, 0))
button_surface.blit(restart_button, (0, 0))
button_surface.blit(main_menu_button, (button_surface.get_width() - main_menu_button.get_width(), 0))
screen.blit(button_surface, (screen.get_width() // 2 - button_surface.get_width() // 2, screen.get_height() / 2 - button_surface.get_height() / 2 + 75))
restart_button_rect = pygame.Rect(
(screen.get_width() // 2 - button_surface.get_width() // 2,
screen.get_height() / 2 - button_surface.get_height() / 2 + 75),
restart_button.get_size()
)
main_menu_button_rect = pygame.Rect(
(screen.get_width() // 2 + button_surface.get_width() // 2 - main_menu_button.get_width(),
screen.get_height() / 2 - button_surface.get_height() / 2 + 75),
main_menu_button.get_size()
)
pygame.display.flip()
# Wait for user input to restart or quit
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
return False
if event.type == pygame.MOUSEBUTTONDOWN:
if restart_button_rect.collidepoint(event.pos):
return True # Restart the game
if main_menu_button_rect.collidepoint(event.pos):
return False # Go to main menu
def show_main_menu(screen, play_button, quit_button, background):
title_font = pygame.font.Font('fonts/PressStart2P.ttf', 40)
title_text = title_font.render("Space Adventures", True, (255, 255, 255))
# Background code
for i in range(0, 2):
screen.blit(background, (i * background.get_width(), 0 ))
screen.blit(background, (0, 0))
# Blit Text
screen.blit(title_text, (screen.get_width() / 2 - title_text.get_width() / 2, screen.get_height() / 2 - title_text.get_height() / 2 - 50))
# Buttons
button_surface = pygame.Surface((play_button.get_width() * 2 + 50, play_button.get_height()))
button_surface.fill((0, 0, 0, 0))
button_surface.blit(play_button, (0, 0))
button_surface.blit(quit_button, (button_surface.get_width() - quit_button.get_width(), 0))
screen.blit(button_surface, (screen.get_width() // 2 - button_surface.get_width() // 2, screen.get_height() / 2 - button_surface.get_height() / 2 + 50))
play_button_rect = pygame.Rect(
(screen.get_width() // 2 - button_surface.get_width() // 2,
screen.get_height() / 2 - button_surface.get_height() / 2 + 50),
play_button.get_size()
)
quit_button_rect = pygame.Rect(
(screen.get_width() // 2 + button_surface.get_width() // 2 - quit_button.get_width(),
screen.get_height() / 2 - button_surface.get_height() / 2 + 50),
quit_button.get_size()
)
pygame.display.flip()
# Wait for user input to play or quit
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
return False
if event.type == pygame.MOUSEBUTTONDOWN:
if play_button_rect.collidepoint(event.pos):
return True # Start the game
if quit_button_rect.collidepoint(event.pos):
pygame.quit()
return False # Quit the game
def show_paused_screen(screen, resume_button, quit_button):
paused_surface = pygame.Surface((screen.get_width(), screen.get_height()))
# Set the transparency
paused_surface.set_alpha(100)
paused_surface.fill((0, 0, 0,))
screen.blit(paused_surface, (0, 0))
# Blit Text
title_font = pygame.font.Font('fonts/PressStart2P.ttf', 30)
instruction_font = pygame.font.Font('fonts/PressStart2P.ttf', 15)
title_text = title_font.render("Paused", True, (255, 255, 255))
screen.blit(title_text, (screen.get_width() / 2 - title_text.get_width() / 2, screen.get_height() / 2 - title_text.get_height() / 2 - 50))
# Buttons
button_surface = pygame.Surface((resume_button.get_width() + quit_button.get_width() + 50, resume_button.get_height()))
button_surface.fill((0, 0, 0, 0))
button_surface.blit(resume_button, (0, 0))
button_surface.blit(quit_button, (button_surface.get_width() - quit_button.get_width(), 0))
screen.blit(button_surface, (screen.get_width() // 2 - button_surface.get_width() // 2, screen.get_height() / 2 - button_surface.get_height() / 2 + 35))
pygame.display.flip()
resume_button_rect = pygame.Rect(
(screen.get_width() // 2 - button_surface.get_width() // 2,
screen.get_height() / 2 - button_surface.get_height() / 2 + 35),
resume_button.get_size()
)
quit_button_rect = pygame.Rect(
(screen.get_width() // 2 + button_surface.get_width() // 2 - quit_button.get_width(),
screen.get_height() / 2 - button_surface.get_height() / 2 + 35),
quit_button.get_size()
)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
return False
if event.type == pygame.MOUSEBUTTONDOWN:
if resume_button_rect.collidepoint(event.pos):
return True # Start the game
if quit_button_rect.collidepoint(event.pos):
return False # Quit the game