-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
56 lines (42 loc) · 1.43 KB
/
game.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
import sys
import pygame as pg
from scenes import MainScene, SceneManager
from settings import Color, FPS, GAME_RESOLUTION, PathCtrl
class Game:
# region Pygame setup
pg.display.init()
pg.font.init()
pg.display.set_icon(pg.transform.scale(
pg.image.load(PathCtrl.get_path('assets/logo.png')), (90, 90))
)
# endregion
def __init__(self):
self.screen = pg.display.set_mode(GAME_RESOLUTION)
SceneManager().current = MainScene()
self.__clock = pg.time.Clock()
# region Private
def __process_all_draw(self) -> None:
self.screen.fill(Color.DARK_GREEN)
SceneManager().current.process_draw(self.screen)
SceneManager().current.additional_draw(self.screen)
pg.display.flip()
@staticmethod
def __process_all_events() -> None:
for event in pg.event.get():
if event.type == pg.QUIT:
sys.exit(0)
SceneManager().current.process_event(event)
SceneManager().current.additional_event(event)
@staticmethod
def __process_all_logic() -> None:
SceneManager().current.process_logic()
SceneManager().current.additional_logic()
# endregion
# region Public
def main_loop(self) -> None:
while True:
self.__process_all_logic()
self.__process_all_events()
self.__process_all_draw()
self.__clock.tick(FPS)
# endregion