-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.pyw
More file actions
135 lines (102 loc) · 4.62 KB
/
main.pyw
File metadata and controls
135 lines (102 loc) · 4.62 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
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
""" Game core
"""
import pygame # graphics
# dependencies
from loguru import logger
import QuantumCore
from QuantumCore.app import App, mainloop
from GameData import settings # there is a rewrite
# core elements
from core.elements.locations import TestScene, Location # load game scenes
from core.skripts import Mods
# engine elements imports
import QuantumCore.time
from QuantumCore import config
class TestGame(App):
fps_fonts_colors = ('red', 'orange', 'yellow', 'green', 'cyan')
def __init__(self) -> None:
""" THE CORE OF THE GAME """
pygame.init(), pygame.font.init(), settings.rewrite_config() # Initializing game dependencies
""" init Engine (create context, window, camera, mesh and default scene) """
QuantumCore.init()
self.loading = QuantumCore.UI.InterfaceUI(['core', 'UI'], 'loading')
self.ingame_interface = QuantumCore.UI.InterfaceUI(['core', 'UI'], 'ingame_interface')
self.loading.itrf.step(8, 'Init Engine', 'Game Window')
""" working with pygame window """
config.APPLICATION_ICO_name = 'QuantumCore.png'
pygame.display.set_caption(
f"{settings.APPLICATION_NAME} v{settings.APPLICATION_VERSION}"
f" powered by {QuantumCore.name}({QuantumCore.short_name})"
) # for IDE
pygame.display.set_icon(
pygame.image.load( # for IDE
rf'{config.__ENGINE_DATA__}/{config.APPLICATION_ICO_path}/{config.APPLICATION_ICO_name}'
)
)
""" Additional variables """
self.clock = pygame.time.Clock()
QuantumCore.graphic.light.lights_list[0].clear()
self.test_scene: Location = TestScene(self).on_init()
QuantumCore.scene.scene = self.test_scene.load()
self.mods = Mods().search()
self.mods.load()
self.loading.itrf.step(98, stage='Init Game', status='additional variables and game font')
self.spec_keys: dict = {
'L-Ctrl': False
}
logger.debug('GAME ready\n\n')
pygame.event.set_grab(True), pygame.mouse.set_visible(False) # mouse - set static
def autosave(self):
if settings.autosave:
new_name = self.test_scene.builder.name().split('_autosave')[0] + f'_autosave'
settings.write_datafile(
{
'game': {
'save_name': new_name
}
}
)
self.test_scene.builder.write(new_name)
def events(self) -> None:
""" Event handling """
for event in pygame.event.get():
""" Exit of App to button "close" """
if event.type == pygame.QUIT:
self.autosave()
App.running = False
elif event.type == pygame.KEYDOWN:
""" Detect KEY DOWN """
if event.key == pygame.K_LCTRL:
self.spec_keys['L-Ctrl'] = True
elif self.spec_keys['L-Ctrl'] and event.key == pygame.K_r:
settings.rewrite_config()
QuantumCore.window.resset()
elif self.spec_keys['L-Ctrl'] and event.key == pygame.K_g:
logger.warning('GAME - TEST RISE\n\n')
raise Exception("TEST RISE - USE 'raise - Exception' and call traceback")
elif self.spec_keys['L-Ctrl'] and event.key == pygame.K_q:
self.autosave()
App.running = False
elif event.type == pygame.KEYUP:
if event.key == pygame.K_LCTRL:
self.spec_keys['L-Ctrl'] = False
elif event.type == pygame.MOUSEBUTTONDOWN:
""" Detect MOUSE BUTTON DOWN """
@staticmethod
def get_time() -> None:
""" updating game time """
QuantumCore.time.list_['rotate'] = pygame.time.get_ticks()*0.001
def update_app(self) -> None:
""" updating the application itself (CPU) """
self.get_time()
""" main update """
QuantumCore.scene.scene.__update__()
def update_window(self) -> None:
""" Rendering the application itself (GPU) """
QuantumCore.scene.scene.__render__()
self.ingame_interface.itrf.go(int(self.clock.get_fps()))
# main pygame updating
pygame.display.flip()
QuantumCore.time.delta = self.clock.tick(config.fps)
if __name__ == '__main__':
mainloop(TestGame)