-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.py
183 lines (162 loc) · 6.37 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File: menu.py
# Description: An instance of one menu
import pygame
import os
import math
from config import *
RED = (255,0,0)
MAGENTA = (255, 56, 156)
ORANGE = (240, 240, 0)
GREEN = (0,255,0)
BLUE = (0,0,255)
BLU = (83,190,255)
WHITE = (255,255,255)
BLACK = (0,0,0)
GREY = (127, 127, 127)
LGRAY = (200, 200, 200)
DGRAY = (55, 55, 55)
def texty(name,size):
matched = pygame.font.match_font('verdana, arial')
Texty = pygame.font.Font(matched, size)
return Texty
class Menu:
AERIALPANE_W = 795
AERIALPANE_H = 768
STRIPPANE_TOP = 152
STRIPPANE_H = 44
def __init__(self, screen):
self.SCREEN_W = screen.get_size()[0]
self.SCREEN_H = screen.get_size()[1]
#Imagey type stuff
self.font = pygame.font.Font(None, 30)
self.screen = screen
self.menuEnd = 0
self.selection = 0
self.timeWithoutUIEvent = 0
#Initialisation Stuff Done
def __mouseMenuOver(self,pos):
if ((520 < pos[0] < 710) and (360 < pos[1] < 385)):
return 0
elif ((520 < pos[0] < 710) and (385 < pos[1] < 420)):
return 1
elif ((520 < pos[0] < 710) and (420 < pos[1] < 450)):
return 2
elif ((520 < pos[0] < 710) and (450 < pos[1] < 480)):
return 3
else:
return -1
def __mouseMenuSelection(self,pos):
if ((520 < pos[0] < 710) and (360 < pos[1] < 385)):
return 0
elif ((520 < pos[0] < 710) and (385 < pos[1] < 420)):
return 1
elif ((520 < pos[0] < 710) and (420 < pos[1] < 450)):
return 2
elif ((520 < pos[0] < 710) and (450 < pos[1] < 480)):
return 3
else:
return -1
def __handleUserInteraction(self):
for event in pygame.event.get():
if(event.type == pygame.MOUSEBUTTONDOWN):
self.timeWithoutUIEvent = 0
ret = self.__mouseMenuSelection(event.pos)
if (ret == 3):
self.menuEnd = Config.CODE_KILL
elif (ret == 2):
self.menuEnd = Config.MENU_CODE_HIGH_SCORE
elif (ret == 1):
self.menuEnd = Config.MENU_CODE_DEMO
elif (ret == 0):
self.menuEnd = Config.MENU_CODE_START
break
elif(event.type == pygame.MOUSEMOTION):
self.timeWithoutUIEvent = 0
a = self.__mouseMenuOver(event.pos)
if (0 <= a <= 3):
self.selection = a
elif(event.type == pygame.QUIT):
self.menuEnd = Config.CODE_KILL
break
elif(event.type == pygame.KEYDOWN):
self.timeWithoutUIEvent = 0
if(event.key == pygame.K_ESCAPE):
self.menuEnd = Config.CODE_KILL
break
elif(event.key == pygame.K_UP):
self.selection = (self.selection - 1) % 4
break
elif(event.key == pygame.K_DOWN):
self.selection = (self.selection + 1) % 4
break
elif(event.key == pygame.K_SPACE or event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER):
if (self.selection == 3):
self.menuEnd = Config.CODE_KILL
elif (self.selection == 2):
self.menuEnd = Config.MENU_CODE_HIGH_SCORE
elif (self.selection == 1):
self.menuEnd = Config.MENU_CODE_DEMO
elif (self.selection == 0):
self.menuEnd = Config.MENU_CODE_START
break
def start(self):
Texty = texty(None,30)
Bigtex = texty(None,60) #large text
selection = 0
shift0 = 40
shift1 = 40
shift2 = 40
START = Texty.render("START", 0,WHITE)
DEMO = Texty.render("Demo",0,WHITE)
OPTIONS = Texty.render("HIGH SCORES",0,WHITE)
EXIT = Texty.render("EXIT",0,WHITE)
timer = 0
boxrect = pygame.Rect((18,48),(185,35))
erectpos = (0,420)
clock = pygame.time.Clock()
self.menuEnd = 0
while self.menuEnd == 0:
timepassed = clock.tick(Config.FRAMERATE)
self.timeWithoutUIEvent += timepassed
if (self.timeWithoutUIEvent > Config.GAME_DEMOTIMEOUT):
self.menuEnd = Config.MENU_CODE_DEMO
self.timeWithoutUIEvent = 0
self.__handleUserInteraction()
pygame.draw.rect(self.screen, BLACK, pygame.Rect(0, 0, self.SCREEN_W, self.SCREEN_H))
#Create Menu Items depending on current selection.
shift0 = 0
shift1 = 0
shift2 = 0
shift3 = 0
if (self.selection == 0):
START = Texty.render("START",0,GREEN)
DEMO = Texty.render("Demo",0,WHITE)
OPTIONS = Texty.render("HIGH SCORES",0,WHITE)
EXIT = Texty.render("EXIT",0,WHITE)
shift0=40
elif (self.selection == 1):
START = Texty.render("START",0,WHITE)
DEMO = Texty.render("Demo",0,GREEN)
OPTIONS = Texty.render("HIGH SCORES",0,WHITE)
EXIT = Texty.render("EXIT",0,WHITE)
shift1=40
elif (self.selection == 2):
START = Texty.render("START",0,WHITE)
DEMO = Texty.render("Demo",0,WHITE)
OPTIONS = Texty.render("HIGH SCORES",0,GREEN)
EXIT = Texty.render("EXIT",0,WHITE)
shift2=40
elif (self.selection == 3):
START = Texty.render("START",0,WHITE)
DEMO = Texty.render("Demo",0,WHITE)
OPTIONS = Texty.render("HIGH SCORES",0,WHITE)
EXIT = Texty.render("EXIT",0,GREEN)
shift3=40
#Draw Menu
self.screen.blit(START,(shift0+520,360))
self.screen.blit(DEMO, (shift1+520,390))
self.screen.blit(OPTIONS,(shift2+520,420))
self.screen.blit(EXIT,(shift3+520,450))
#Draw Screen
pygame.display.flip()
return self.menuEnd