-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.py
54 lines (46 loc) · 2.11 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
from config import *
from utility import *
import pygame
class Menu:
def __init__(self, display) -> None:
self.logo = image_load(LOGO, (600, 174))
self.button_list = [MENU_FONT.render('AI mode', True, 'black'), MENU_FONT.render('Play', True, 'black'),
MENU_FONT.render('Quit', True, 'black')]
self.running = True
self.cur_text = SCORES_FONT.render('Press ENTER', True, 'darkgrey')
self.display = display
self.selected = 0
self.mode = 1
self.show()
def show(self) -> None:
while self.running:
self.display.fill(MENU_COLOR)
self.display.blit(self.logo, (65, 70))
self.display.blit(self.cur_text, (270, 430))
pygame.draw.rect(self.display, 'SpringGreen', pygame.Rect(250, 270 + self.selected * 50 + 5, 40, 40))
pygame.draw.rect(self.display, 'black', pygame.Rect(250, 270 + self.selected * 50 + 5, 40, 40), 3)
for n, i in enumerate(self.button_list):
self.display.blit(i, (300, 270 + 50 * n))
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
if self.selected + 1 < len(self.button_list):
self.selected += 1
SWITCH_SOUND.play()
if event.key == pygame.K_UP:
if self.selected - 1 >= 0:
self.selected -= 1
SWITCH_SOUND.play()
if event.key == pygame.K_RETURN:
if self.selected == 1:
self.mode = 1
pygame.mixer.music.play(-1)
elif self.selected == 0:
self.mode = 0
pygame.mixer.music.play(-1)
else:
quit()
self.running = False
pygame.display.flip()