-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathengine.py
More file actions
63 lines (56 loc) · 1.89 KB
/
engine.py
File metadata and controls
63 lines (56 loc) · 1.89 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
63
import pygame
from pygin.draw import Draw
from pygin.scene import Scene
from pygin.time import Time
from pygin.input import Input
class Engine:
screen_width = 240
screen_height = 426
game_name = "Untitled"
game_display = None
scenes = None
@classmethod
def start_game(cls, game_settings):
"""
Start the Balance coroutine with pygame
:param game_settings: settings of the Balance
"""
cls.set_game_settings(game_settings)
Time.start_coroutine(cls.game)
Time.start_game()
@classmethod
def set_game_settings(cls, game_settings):
"""
set up some Balance settings on engine
:param game_settings: settings of the Balance
"""
if hasattr(game_settings, "scenes_list"):
cls.scenes = game_settings.scenes_list
else:
raise Exception("No scenes_list in game_settings file!")
if hasattr(game_settings, "game_name"):
cls.game_name = game_settings.game_name
if hasattr(game_settings, "screen_width"):
cls.screen_width = game_settings.screen_width
if hasattr(game_settings, "screen_height"):
cls.screen_height = game_settings.screen_height
@classmethod
async def game(cls):
"""
Async method that will be the coroutine where the Balance will run in
"""
pygame.mixer.pre_init(44100, -16, 1, 512)
pygame.init()
cls.game_display = pygame.display.set_mode((cls.screen_width, cls.screen_height))
pygame.display.set_caption(cls.game_name)
Scene.scenes_list = cls.scenes
Draw.set_game_display(cls.game_display, cls.screen_width, cls.screen_height)
Input.set_engine_reference(cls)
Scene.start_first_scene()
@classmethod
def end_game(cls):
"""
Quits the Balance
"""
pygame.quit()
quit()