-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.py
85 lines (71 loc) · 2.44 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import pygame
import button
pygame.init()
#create game window
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Main Menu")
#game variables
game_paused = False
menu_state = "main"
#define fonts
font = pygame.font.SysFont("arialblack", 40)
#define colours
TEXT_COL = (255, 255, 255)
#load button images
resume_img = pygame.image.load("images/button_resume.png").convert_alpha()
options_img = pygame.image.load("images/button_options.png").convert_alpha()
quit_img = pygame.image.load("images/button_quit.png").convert_alpha()
video_img = pygame.image.load('images/button_video.png').convert_alpha()
audio_img = pygame.image.load('images/button_audio.png').convert_alpha()
keys_img = pygame.image.load('images/button_keys.png').convert_alpha()
back_img = pygame.image.load('images/button_back.png').convert_alpha()
#create button instances
resume_button = button.Button(304, 125, resume_img, 1)
options_button = button.Button(297, 250, options_img, 1)
quit_button = button.Button(336, 375, quit_img, 1)
video_button = button.Button(226, 75, video_img, 1)
audio_button = button.Button(225, 200, audio_img, 1)
keys_button = button.Button(246, 325, keys_img, 1)
back_button = button.Button(332, 450, back_img, 1)
def draw_text(text, font, text_col, x, y):
img = font.render(text, True, text_col)
screen.blit(img, (x, y))
#game loop
run = True
while run:
screen.fill((52, 78, 91))
#check if game is paused
if game_paused == True:
#check menu state
if menu_state == "main":
#draw pause screen buttons
if resume_button.draw(screen):
game_paused = False
if options_button.draw(screen):
menu_state = "options"
if quit_button.draw(screen):
run = False
#check if the options menu is open
if menu_state == "options":
#draw the different options buttons
if video_button.draw(screen):
print("Video Settings")
if audio_button.draw(screen):
print("Audio Settings")
if keys_button.draw(screen):
print("Change Key Bindings")
if back_button.draw(screen):
menu_state = "main"
else:
draw_text("Press SPACE to pause", font, TEXT_COL, 160, 250)
#event handler
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
game_paused = True
if event.type == pygame.QUIT:
run = False
pygame.display.update()
pygame.quit()