-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlauncher.py
155 lines (116 loc) · 4.26 KB
/
launcher.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
__all__ = ['main']
import os
import sys
import pygame
import pygame_menu
from pygame_menu.examples import create_example_window
from random import randrange
from typing import Tuple, Any, Optional, List
# Var
FPS = 60
WINDOW_SIZE = (1280, 720)
clock: Optional['pygame.time.Clock'] = None
main_menu: Optional['pygame_menu.Menu'] = None
surface: Optional['pygame.Surface'] = None
def invader_special():
os.system(os.path.join(os.getcwd(),"Pac-Patrouille", "pacpatrouille.py"))
def main_background() -> None:
"""
Function used by menus, draw on background while menu is active.
:return: None
"""
global surface
surface.fill((128, 0, 128))
def pac2pac():
os.system(os.path.join(os.getcwd(),"pacman", "pacman.pyw"))
def main(test: bool = False) -> None:
"""
Main program.
:param test: Indicate function is being tested
:return: None
"""
# -------------------------------------------------------------------------
# Globals
# -------------------------------------------------------------------------
global clock
global main_menu
global surface
# -------------------------------------------------------------------------
# Create window
# -------------------------------------------------------------------------
surface = create_example_window('2PacMan', WINDOW_SIZE)
clock = pygame.time.Clock()
# -------------------------------------------------------------------------
# Create menus: Play Menu
# -------------------------------------------------------------------------
play_menu = pygame_menu.Menu(
height=WINDOW_SIZE[1] * 1,
title='Jouer au jeu !',
width=WINDOW_SIZE[0] * 1
)
global user_name
submenu_theme = pygame_menu.themes.THEME_DEFAULT.copy()
# submenu_theme.widget_font_size = 15
play_submenu = pygame_menu.Menu(
height=WINDOW_SIZE[1] * 1,
theme=submenu_theme,
title='Mode spécial',
width=WINDOW_SIZE[0] * 1
)
play_submenu.add.button('Mode Pac Patrouille', invader_special)
play_submenu.add.button('Retour', pygame_menu.events.BACK)
# user_name = play_menu.add.text_input('Name: ', default='John Doe', maxchar=10)
# Essai d'exporter un nom choisi vers le programme du jeu
play_menu.add.button('Jouer !', pac2pac)
play_menu.add.button('Secrets', play_submenu)
play_menu.add.button('Retour', pygame_menu.events.BACK)
# -------------------------------------------------------------------------
# Create menus:About
# -------------------------------------------------------------------------
about_theme = pygame_menu.themes.THEME_DEFAULT.copy()
about_theme.widget_margin = (0, 0)
about_menu = pygame_menu.Menu(
height=WINDOW_SIZE[1] * 1,
theme=about_theme,
title='A propos',
width=WINDOW_SIZE[0] * 1
)
about_menu.add.label('Groupe 4')
about_menu.add.button('Retour', pygame_menu.events.BACK)
# -------------------------------------------------------------------------
# Create menus: Main
# -------------------------------------------------------------------------
main_theme = pygame_menu.themes.THEME_DEFAULT.copy()
main_menu = pygame_menu.Menu(
height=WINDOW_SIZE[1] * 1,
theme=main_theme,
title='Menu principal',
width=WINDOW_SIZE[0] * 1
)
main_menu.add.button('Jouer', play_menu)
main_menu.add.button('A propos', about_menu)
main_menu.add.button('Quitter', pygame_menu.events.EXIT)
# -------------------------------------------------------------------------
# Main loop
# -------------------------------------------------------------------------
while True:
# Tick
clock.tick(FPS)
# Paint background
main_background()
# Application events
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
exit()
# Main menu
if main_menu.is_enabled():
main_menu.mainloop(surface, main_background,
disable_loop=test, fps_limit=FPS)
# Flip surface
pygame.display.flip()
# At first loop returns
if test:
break
if __name__ == '__main__':
main()