-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.py
71 lines (63 loc) · 2.81 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
import pygame
from pygame.locals import *
pygame.init()
pygame.mixer.init()
sound_select = pygame.mixer.Sound("sound.wav") # this is the sound given for seleciton
background = pygame.image.load('Board.png')
screenx = 600 # this will be the screen size
screeny = 600
screen2 = pygame.display.set_mode((screenx,screeny))
background = pygame.transform.scale(background,(screenx,screeny))
class Menu():
menu = []; #will be used to enter the requires list for a particular task
# the codes for different colors are initialised over here
black = (100,0,0)
blue = (200, 70, 10)
white = (220,70,80)
default_screen_color = white
def __init__(self,set_screen = screen2,screen_color = default_screen_color):
screen = set_screen
self.default_screen_color = screen_color
def menu_UI(self,current_menu):
pos = 0
screen2.blit(background, (0, 0))
blitBackground = False
while(True):
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit(0)
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
blitBackground = True
if pos != len(current_menu) - 1:
sound_select.play()
pos += 1
elif event.key == pygame.K_UP:
blitBackground = True
if pos != 0:
sound_select.play()
pos -= 1
elif event.key == pygame.K_SPACE:
return(pos)
else:
blitBackground = False
if pos ==len(current_menu):
blitBackground = False
pos = len(current_menu) - 1
if pos<0:
blitBackground = False
pos = 0
if(blitBackground):
screen2.blit(background,(0,0))
#pygame.display.update() #can uncomment this is there is no other screen updating system in the main program
for menu_pos in range(len(current_menu)):
if pos == menu_pos:
myfont = pygame.font.SysFont("arial", 50)
label = myfont.render('->' + current_menu[menu_pos], 2, self.black)
screen2.blit(label,(screenx//2-110,screeny//2))
else:
myfont = pygame.font.SysFont("arial", 40)
label = myfont.render(current_menu[menu_pos], 2, self.blue)
screen2.blit(label, (screenx//2-60,screeny//2 + (menu_pos - pos)*50))
#pygame.display.update()