mini-arcade-core 0.6.0__py3-none-any.whl → 0.6.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mini_arcade_core/game.py +46 -6
- {mini_arcade_core-0.6.0.dist-info → mini_arcade_core-0.6.1.dist-info}/METADATA +1 -1
- {mini_arcade_core-0.6.0.dist-info → mini_arcade_core-0.6.1.dist-info}/RECORD +5 -5
- {mini_arcade_core-0.6.0.dist-info → mini_arcade_core-0.6.1.dist-info}/WHEEL +0 -0
- {mini_arcade_core-0.6.0.dist-info → mini_arcade_core-0.6.1.dist-info}/licenses/LICENSE +0 -0
mini_arcade_core/game.py
CHANGED
|
@@ -5,6 +5,7 @@ Game core module defining the Game class and configuration.
|
|
|
5
5
|
from __future__ import annotations
|
|
6
6
|
|
|
7
7
|
from dataclasses import dataclass
|
|
8
|
+
from time import perf_counter, sleep
|
|
8
9
|
from typing import TYPE_CHECKING
|
|
9
10
|
|
|
10
11
|
from .backend import Backend
|
|
@@ -40,22 +41,31 @@ class Game:
|
|
|
40
41
|
def __init__(self, config: GameConfig):
|
|
41
42
|
"""
|
|
42
43
|
:param config: Game configuration options.
|
|
44
|
+
:type config: GameConfig
|
|
43
45
|
"""
|
|
44
46
|
self.config = config
|
|
45
47
|
self._current_scene: Scene | None = None
|
|
46
48
|
self._running: bool = False
|
|
47
49
|
self.backend: Backend | None = config.backend
|
|
48
50
|
|
|
51
|
+
if config.backend is None:
|
|
52
|
+
raise ValueError(
|
|
53
|
+
"GameConfig.backend must be set to a Backend instance"
|
|
54
|
+
)
|
|
55
|
+
self.backend: Backend = config.backend
|
|
56
|
+
|
|
49
57
|
def change_scene(self, scene: Scene):
|
|
50
58
|
"""
|
|
51
59
|
Swap the active scene. Concrete implementations should call
|
|
52
60
|
``on_exit``/``on_enter`` appropriately.
|
|
53
61
|
|
|
54
62
|
:param scene: The new scene to activate.
|
|
63
|
+
:type scene: Scene
|
|
55
64
|
"""
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
if self._current_scene is not None:
|
|
66
|
+
self._current_scene.on_exit()
|
|
67
|
+
self._current_scene = scene
|
|
68
|
+
self._current_scene.on_enter()
|
|
59
69
|
|
|
60
70
|
def quit(self):
|
|
61
71
|
"""Request that the main loop stops."""
|
|
@@ -69,7 +79,37 @@ class Game:
|
|
|
69
79
|
or another backend.
|
|
70
80
|
|
|
71
81
|
:param initial_scene: The scene to start the game with.
|
|
82
|
+
:type initial_scene: Scene
|
|
72
83
|
"""
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
84
|
+
backend = self.backend
|
|
85
|
+
backend.init(self.config.width, self.config.height, self.config.title)
|
|
86
|
+
|
|
87
|
+
self.change_scene(initial_scene)
|
|
88
|
+
|
|
89
|
+
self._running = True
|
|
90
|
+
target_dt = 1.0 / self.config.fps if self.config.fps > 0 else 0.0
|
|
91
|
+
last_time = perf_counter()
|
|
92
|
+
|
|
93
|
+
while self._running:
|
|
94
|
+
now = perf_counter()
|
|
95
|
+
dt = now - last_time
|
|
96
|
+
last_time = now
|
|
97
|
+
|
|
98
|
+
scene = self._current_scene
|
|
99
|
+
if scene is None:
|
|
100
|
+
break
|
|
101
|
+
|
|
102
|
+
for ev in backend.poll_events():
|
|
103
|
+
scene.handle_event(ev)
|
|
104
|
+
|
|
105
|
+
scene.update(dt)
|
|
106
|
+
|
|
107
|
+
backend.begin_frame()
|
|
108
|
+
scene.draw(backend)
|
|
109
|
+
backend.end_frame()
|
|
110
|
+
|
|
111
|
+
if target_dt > 0 and dt < target_dt:
|
|
112
|
+
sleep(target_dt - dt)
|
|
113
|
+
|
|
114
|
+
if self._current_scene is not None:
|
|
115
|
+
self._current_scene.on_exit()
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
mini_arcade_core/__init__.py,sha256=0PFa04KRSY3kT8YoD24zfFt92HYfrk6QrH8IlHbmeo4,1753
|
|
2
2
|
mini_arcade_core/backend.py,sha256=6_3-ni0EQJXfaSReavcrOeUOCNkdrjGctFn5q0D9nrw,1847
|
|
3
3
|
mini_arcade_core/entity.py,sha256=mAkedH0j14giBQFRpQjaym46uczbQDln6nbxy0WFAqU,1077
|
|
4
|
-
mini_arcade_core/game.py,sha256=
|
|
4
|
+
mini_arcade_core/game.py,sha256=5mLbi3IzgfRXBTwl88L-ooez16NtwLKLQZzYvMkLHco,3280
|
|
5
5
|
mini_arcade_core/scene.py,sha256=FEtywrnOBU8p0-t8oWGDELYBRRXOs4-Phe0dF7iSjKI,927
|
|
6
|
-
mini_arcade_core-0.6.
|
|
7
|
-
mini_arcade_core-0.6.
|
|
8
|
-
mini_arcade_core-0.6.
|
|
9
|
-
mini_arcade_core-0.6.
|
|
6
|
+
mini_arcade_core-0.6.1.dist-info/METADATA,sha256=pXNVRAEdlB52_Vz50sUTIPLoYLjMrPyvLfYFQsDXspw,8296
|
|
7
|
+
mini_arcade_core-0.6.1.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
8
|
+
mini_arcade_core-0.6.1.dist-info/licenses/LICENSE,sha256=3lHAuV0584cVS5vAqi2uC6GcsVgxUijvwvtZckyvaZ4,1096
|
|
9
|
+
mini_arcade_core-0.6.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|