-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathpause_scene.py
More file actions
62 lines (47 loc) · 1.69 KB
/
pause_scene.py
File metadata and controls
62 lines (47 loc) · 1.69 KB
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
from typing import Generator
from pygame import Rect
from pygame.event import Event
from pacman.data_core import Cfg, EvenType, FontCfg, event_append
from pacman.misc import is_esc_pressed
from pacman.objects import Text
from pacman.objects.buttons import Btn, BtnController
from .base import BlurScene, SceneManager
class PauseScene(BlurScene):
# region Private
def _generate_objects(self) -> Generator:
yield Text("PAUSE", 40, font=FontCfg.TITLE).move_center(Cfg.RESOLUTION.h_width, 35)
yield BtnController(self.__get_buttons())
@staticmethod
def __stop_game() -> None:
from .menu_scene import MenuScene
event_append(EvenType.GET_SETTINGS)
SceneManager().reset(MenuScene())
@staticmethod
def __restart_game() -> None:
from pacman.scenes.main_scene import MainScene
event_append(EvenType.GET_SETTINGS)
SceneManager().reset(MainScene())
def __get_buttons(self) -> list[Btn]:
names = [
("CONTINUE", SceneManager().pop),
("RESTART", self.__restart_game),
("MENU", self.__stop_game),
]
buttons = []
for i, (txt, fn) in enumerate(names):
buttons.append(
Btn(
rect=Rect(0, 0, 180, 40),
text=txt,
function=fn,
text_size=FontCfg.BUTTON_TEXT_SIZE,
).move_center(Cfg.RESOLUTION.h_width, 100 + 45 * i)
)
return buttons
# endregion
# region Public
def process_event(self, event: Event) -> None:
super().process_event(event)
if is_esc_pressed(event):
SceneManager().pop()
# endregion