-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.py
70 lines (58 loc) · 2.45 KB
/
menu.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
import pygame
import sys
pygame.font.init()
TITLE_FONT = pygame.font.Font("fonts/Raleway-ExtraBold.ttf", 50)
SIDE_FONT = pygame.font.Font("fonts/Montserrat-SemiBold.ttf", 30)
BACKGROUND_COLOR = (37, 39, 77)
TEXT_COLOR = (255, 250, 250)
ACTIVE_COLOR = (255, 81, 0)
def draw_menu_button(surface, text, row, color, width, height):
rows_height = {1: 150, 2: 100, 3: 50, 4: 0, 5: -50}
label = SIDE_FONT.render(text, True, color)
button_x = width / 2 - label.get_width() / 2
surface.blit(label, (button_x, height / 2 - rows_height[row]))
def draw_menu(surface, menu_title, buttons, width, height, active):
menu_text = TITLE_FONT.render(menu_title, True, TEXT_COLOR)
surface.blit(menu_text, (width / 2 - menu_text.get_width() / 2, height / 2 - 250))
for i, v in enumerate(buttons, start=1):
if i == active:
draw_menu_button(surface, v, i, ACTIVE_COLOR, width, height)
else:
draw_menu_button(surface, v, i, TEXT_COLOR, width, height)
def pause(surface, active, width, height, main, main_menu, get_leaderboard, player):
buttons = ["RESUME", "RESTART", "MAIN MENU", "LEADERBOARD", "EXIT"]
paused = True
while paused:
surface.fill(BACKGROUND_COLOR)
draw_menu(surface, "PAUSE", buttons, width, height, active)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
paused = False
elif event.key == pygame.K_DOWN:
if active == 5:
active = 1
else:
active += 1
elif event.key == pygame.K_UP:
if active == 1:
active = 5
else:
active -= 1
elif event.key == pygame.K_RETURN:
if active == 1:
paused = False
elif active == 2:
player.restart_stats()
main(player)
elif active == 3:
main_menu(surface)
elif active == 4:
get_leaderboard(surface, width, height)
elif active == 5:
pygame.quit()
sys.exit()