-
Notifications
You must be signed in to change notification settings - Fork 23
/
menu.py
174 lines (133 loc) · 5.05 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
import pygame
import pygame_menu
import game
from enums.algorithm import Algorithm
COLOR_BACKGROUND = (153, 153, 255)
COLOR_BLACK = (0, 0, 0)
COLOR_WHITE = (255, 255, 255)
FPS = 60.0
MENU_BACKGROUND_COLOR = (102, 102, 153)
MENU_TITLE_COLOR = (51, 51, 255)
WINDOW_SCALE = 0.75
pygame.display.init()
INFO = pygame.display.Info()
TILE_SIZE = int(INFO.current_h * 0.035)
WINDOW_SIZE = (13 * TILE_SIZE, 13 * TILE_SIZE)
clock = None
player_alg = Algorithm.PLAYER
en1_alg = Algorithm.DIJKSTRA
en2_alg = Algorithm.DFS
en3_alg = Algorithm.DIJKSTRA
show_path = True
surface = pygame.display.set_mode(WINDOW_SIZE)
def change_path(value, c):
global show_path
show_path = c
def change_player(value, c):
global player_alg
player_alg = c
def change_enemy1(value, c):
global en1_alg
en1_alg = c
def change_enemy2(value, c):
global en2_alg
en2_alg = c
def change_enemy3(value, c):
global en3_alg
en3_alg = c
def run_game():
game.game_init(surface, show_path, player_alg, en1_alg, en2_alg, en3_alg, TILE_SIZE)
def main_background():
global surface
surface.fill(COLOR_BACKGROUND)
def menu_loop():
pygame.init()
pygame.display.set_caption('Bomberman')
clock = pygame.time.Clock()
menu_theme = pygame_menu.Theme(
selection_color=COLOR_WHITE,
widget_font=pygame_menu.font.FONT_BEBAS,
title_font_size=TILE_SIZE,
title_font_color=COLOR_BLACK,
title_font=pygame_menu.font.FONT_BEBAS,
widget_font_color=COLOR_BLACK,
widget_font_size=int(TILE_SIZE*0.7),
background_color=MENU_BACKGROUND_COLOR,
title_background_color=MENU_TITLE_COLOR,
)
play_menu = pygame_menu.Menu(
theme=menu_theme,
height=int(WINDOW_SIZE[1] * WINDOW_SCALE),
width=int(WINDOW_SIZE[0] * WINDOW_SCALE),
title='Play menu'
)
play_options = pygame_menu.Menu(
theme=menu_theme,
height=int(WINDOW_SIZE[1] * WINDOW_SCALE),
width=int(WINDOW_SIZE[0] * WINDOW_SCALE),
title='Options'
)
play_options.add.selector("Character 1", [("Player", Algorithm.PLAYER), ("DFS", Algorithm.DFS),
("DIJKSTRA", Algorithm.DIJKSTRA), ("None", Algorithm.NONE)], onchange=change_player)
play_options.add.selector("Character 2", [("DIJKSTRA", Algorithm.DIJKSTRA), ("DFS", Algorithm.DFS),
("None", Algorithm.NONE)], onchange=change_enemy1)
play_options.add.selector("Character 3", [("DIJKSTRA", Algorithm.DIJKSTRA), ("DFS", Algorithm.DFS),
("None", Algorithm.NONE)], onchange=change_enemy2, default=1)
play_options.add.selector("Character 4", [("DIJKSTRA", Algorithm.DIJKSTRA), ("DFS", Algorithm.DFS),
("None", Algorithm.NONE)], onchange=change_enemy3)
play_options.add.selector("Show path", [("Yes", True), ("No", False)], onchange=change_path)
play_options.add.button('Back', pygame_menu.events.BACK)
play_menu.add.button('Start',
run_game)
play_menu.add.button('Options', play_options)
play_menu.add.button('Return to main menu', pygame_menu.events.BACK)
about_menu_theme = pygame_menu.themes.Theme(
selection_color=COLOR_WHITE,
widget_font=pygame_menu.font.FONT_BEBAS,
title_font_size=TILE_SIZE,
title_font_color=COLOR_BLACK,
title_font=pygame_menu.font.FONT_BEBAS,
widget_font_color=COLOR_BLACK,
widget_font_size=int(TILE_SIZE*0.5),
background_color=MENU_BACKGROUND_COLOR,
title_background_color=MENU_TITLE_COLOR
)
about_menu = pygame_menu.Menu(
theme=about_menu_theme,
height=int(WINDOW_SIZE[1] * WINDOW_SCALE),
width=int(WINDOW_SIZE[0] * WINDOW_SCALE),
overflow=False,
title='About'
)
about_menu.add.label("Player controls: ")
about_menu.add.label("Movement: Arrows")
about_menu.add.label("Plant bomb: Space")
about_menu.add.label("Author: Michal Sliwa")
about_menu.add.label("Sprite: ")
about_menu.add.label("https://opengameart.org/ content/bomb-party-the-complete-set", wordwrap=True)
about_menu.add.vertical_margin(25)
about_menu.add.button('Return to main menu', pygame_menu.events.BACK)
main_menu = pygame_menu.Menu(
theme=menu_theme,
height=int(WINDOW_SIZE[1] * WINDOW_SCALE),
width=int(WINDOW_SIZE[0] * WINDOW_SCALE),
onclose=pygame_menu.events.EXIT,
title='Main menu'
)
main_menu.add.button('Play', play_menu)
main_menu.add.button('About', about_menu)
main_menu.add.button('Quit', pygame_menu.events.EXIT)
running = True
while running:
clock.tick(FPS)
main_background()
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
running = False
if main_menu.is_enabled():
main_menu.mainloop(surface, main_background)
pygame.display.flip()
exit()
if __name__ == "__main__":
menu_loop()