-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.py
242 lines (171 loc) · 8.58 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import pygame, sys
from button import Button
def get_font(size): # Returns Press-Start-2P in the desired size
return pygame.font.Font("assets/font.ttf", size)
def game_over(screen, run, score: int, coins: int):
pygame.mixer.music.load('music/mario-dead.mp3')
pygame.mixer.music.play(1)
while True:
PLAY_MOUSE_POS = pygame.mouse.get_pos()
screen.fill("black")
PLAY_TEXT = get_font(90).render("GAME OVER!", True, "Red")
PLAY_RECT = PLAY_TEXT.get_rect(center=(660, 150))
screen.blit(PLAY_TEXT, PLAY_RECT)
SCORE_TEXT = get_font(45).render(f"Your score {score}", True, "White")
SCORE_RECT = SCORE_TEXT.get_rect(center=(660, 270))
screen.blit(SCORE_TEXT, SCORE_RECT)
COIN_TEXT = get_font(45).render(f"Coins {coins}", True, "Yellow")
COIN_RECT = COIN_TEXT.get_rect(center=(660, 360))
screen.blit(COIN_TEXT, COIN_RECT)
TRY_AGAIN = Button(image=None, pos=(640, 500),
text_input="TRY AGAIN", font=get_font(75), base_color="White", hovering_color="Green")
PLAY_BACK = Button(image=None, pos=(640, 620),
text_input="GO TO MENU", font=get_font(75), base_color="White", hovering_color="Orange")
PLAY_BACK.changeColor(PLAY_MOUSE_POS)
PLAY_BACK.update(screen)
TRY_AGAIN.changeColor(PLAY_MOUSE_POS)
TRY_AGAIN.update(screen)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if PLAY_BACK.checkForInput(PLAY_MOUSE_POS):
pygame.mixer.music.set_volume(1)
pygame.mixer.music.load('music/menu_background_music.mp3')
main_menu(screen, run)
elif TRY_AGAIN.checkForInput(PLAY_MOUSE_POS):
run()
pygame.display.update()
def win(screen, run, score: int, coins: int):
pygame.mixer.music.load('music/win.wav')
pygame.mixer.music.play(1)
while True:
PLAY_MOUSE_POS = pygame.mouse.get_pos()
screen.fill("white")
PLAY_TEXT = get_font(90).render("YOU WIN!", True, "Green")
PLAY_RECT = PLAY_TEXT.get_rect(center=(660, 150))
screen.blit(PLAY_TEXT, PLAY_RECT)
SCORE_TEXT = get_font(45).render(f"Your score {score}", True, "Blue")
SCORE_RECT = SCORE_TEXT.get_rect(center=(660, 270))
screen.blit(SCORE_TEXT, SCORE_RECT)
COIN_TEXT = get_font(45).render(f"Coins {coins}", True, "Yellow")
COIN_RECT = COIN_TEXT.get_rect(center=(660, 360))
screen.blit(COIN_TEXT, COIN_RECT)
PLAY_BACK = Button(image=None, pos=(640, 520),
text_input="GO TO MENU", font=get_font(75), base_color="Black", hovering_color="Red")
PLAY_BACK.changeColor(PLAY_MOUSE_POS)
PLAY_BACK.update(screen)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if PLAY_BACK.checkForInput(PLAY_MOUSE_POS):
pygame.mixer.music.set_volume(1)
pygame.mixer.music.load('music/menu_background_music.mp3')
main_menu(screen, run)
pygame.display.update()
def game_pause(screen, run):
pygame.mixer.music.pause()
coin_sound = pygame.mixer.Sound('music/pause.wav')
coin_sound.play(0)
while True:
PLAY_MOUSE_POS = pygame.mouse.get_pos()
screen.fill("White")
PLAY_TEXT = get_font(90).render("Game is pause", True, "Black")
PLAY_RECT = PLAY_TEXT.get_rect(center=(640, 160))
screen.blit(PLAY_TEXT, PLAY_RECT)
CONTINUE_PLAY = Button(image=None, pos=(640, 450),
text_input="CONTINUE", font=get_font(75), base_color="Black", hovering_color="Green")
MENU = Button(image=None, pos=(640, 600),
text_input="MENU", font=get_font(75), base_color="Black", hovering_color="Red")
CONTINUE_PLAY.changeColor(PLAY_MOUSE_POS)
CONTINUE_PLAY.update(screen)
MENU.changeColor(PLAY_MOUSE_POS)
MENU.update(screen)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if CONTINUE_PLAY.checkForInput(PLAY_MOUSE_POS):
pygame.mixer.music.unpause()
return
if MENU.checkForInput(PLAY_MOUSE_POS):
pygame.mixer.music.unpause()
pygame.mixer.music.load('music/menu_background_music.mp3')
main_menu(screen, run)
pygame.display.update()
def options(screen, run):
while True:
OPTIONS_MOUSE_POS = pygame.mouse.get_pos()
screen.fill("white")
OPTIONS_TEXT = get_font(45).render("Powered by:", True, "Black")
OPTIONS_RECT = OPTIONS_TEXT.get_rect(center=(640, 130))
ILYA = get_font(45).render('Ilya Andreevskii', True, "Black")
ILYA_RECT = OPTIONS_TEXT.get_rect(center=(500, 260))
PAVEL = get_font(45).render('Pavel Glytov', True, "Black")
PAVEL_RECT = OPTIONS_TEXT.get_rect(center=(580, 360))
ANDREW = get_font(45).render('Andrew Logvinov', True, "Black")
ANDREW_RECT = OPTIONS_TEXT.get_rect(center=(530, 460))
screen.blit(OPTIONS_TEXT, OPTIONS_RECT)
screen.blit(ILYA, ILYA_RECT)
screen.blit(PAVEL, PAVEL_RECT)
screen.blit(ANDREW, ANDREW_RECT)
OPTIONS_BACK = Button(image=None, pos=(640, 600),
text_input="BACK", font=get_font(75), base_color="Black", hovering_color="Green")
OPTIONS_BACK.changeColor(OPTIONS_MOUSE_POS)
OPTIONS_BACK.update(screen)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if OPTIONS_BACK.checkForInput(OPTIONS_MOUSE_POS):
main_menu(screen, run)
pygame.display.update()
def main_menu(screen, run):
pygame.init()
pygame.display.set_caption("Menu")
BG = pygame.image.load("assets/Background.png")
get_continued = True
if not pygame.mixer.music.get_busy():
pygame.mixer.music.load('music/menu_background_music.mp3')
pygame.mixer.music.play(-1)
while get_continued:
screen.blit(BG, (0, 0))
MENU_MOUSE_POS = pygame.mouse.get_pos()
MENU_TEXT = get_font(100).render("MAIN MENU", True, "#b68f40")
MENU_RECT = MENU_TEXT.get_rect(center=(640, 100))
PLAY_BUTTON = Button(image=pygame.image.load("assets/Play Rect.png"), pos=(640, 250),
text_input="PLAY", font=get_font(75), base_color="#d7fcd4", hovering_color="Green")
OPTIONS_BUTTON = Button(image=pygame.image.load("assets/Options Rect.png"), pos=(640, 400),
text_input="OPTIONS", font=get_font(75), base_color="#d7fcd4", hovering_color="Yellow")
QUIT_BUTTON = Button(image=pygame.image.load("assets/Quit Rect.png"), pos=(640, 550),
text_input="QUIT", font=get_font(75), base_color="#d7fcd4", hovering_color="Red")
screen.blit(MENU_TEXT, MENU_RECT)
for button in [PLAY_BUTTON, OPTIONS_BUTTON, QUIT_BUTTON]:
button.changeColor(MENU_MOUSE_POS)
button.update(screen)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if PLAY_BUTTON.checkForInput(MENU_MOUSE_POS):
params = run()
while params[0] != 'dead':
if params[0] == 'win':
win(screen, run, score=params[1], coins=params[2])
elif params[0] == 'lvl1':
params = run(params[3], params[2], params[1], 1)
elif params[0] == "lvl2":
params = run(params[3], params[2], params[1], 2)
game_over(screen, run, score=params[1], coins=params[2])
if OPTIONS_BUTTON.checkForInput(MENU_MOUSE_POS):
options(screen, run)
if QUIT_BUTTON.checkForInput(MENU_MOUSE_POS):
pygame.quit()
sys.exit()
pygame.display.update()