mini-arcade-core 0.9.9__py3-none-any.whl → 1.0.0__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/__init__.py +44 -80
- mini_arcade_core/backend/__init__.py +0 -5
- mini_arcade_core/backend/backend.py +9 -0
- mini_arcade_core/backend/events.py +1 -1
- mini_arcade_core/{keymaps/sdl.py → backend/sdl_map.py} +1 -1
- mini_arcade_core/bus.py +57 -0
- mini_arcade_core/engine/__init__.py +0 -0
- mini_arcade_core/engine/commands.py +169 -0
- mini_arcade_core/engine/game.py +354 -0
- mini_arcade_core/engine/render/__init__.py +0 -0
- mini_arcade_core/engine/render/packet.py +56 -0
- mini_arcade_core/engine/render/pipeline.py +39 -0
- mini_arcade_core/managers/__init__.py +0 -14
- mini_arcade_core/managers/cheats.py +186 -0
- mini_arcade_core/managers/inputs.py +286 -0
- mini_arcade_core/runtime/__init__.py +0 -0
- mini_arcade_core/runtime/audio/__init__.py +0 -0
- mini_arcade_core/runtime/audio/audio_adapter.py +13 -0
- mini_arcade_core/runtime/audio/audio_port.py +17 -0
- mini_arcade_core/runtime/capture/__init__.py +0 -0
- mini_arcade_core/runtime/capture/capture_adapter.py +143 -0
- mini_arcade_core/runtime/capture/capture_port.py +32 -0
- mini_arcade_core/runtime/context.py +53 -0
- mini_arcade_core/runtime/file/__init__.py +0 -0
- mini_arcade_core/runtime/file/file_adapter.py +20 -0
- mini_arcade_core/runtime/file/file_port.py +31 -0
- mini_arcade_core/runtime/input/__init__.py +0 -0
- mini_arcade_core/runtime/input/input_adapter.py +49 -0
- mini_arcade_core/runtime/input/input_port.py +31 -0
- mini_arcade_core/runtime/input_frame.py +71 -0
- mini_arcade_core/runtime/scene/__init__.py +0 -0
- mini_arcade_core/runtime/scene/scene_adapter.py +97 -0
- mini_arcade_core/runtime/scene/scene_port.py +149 -0
- mini_arcade_core/runtime/services.py +35 -0
- mini_arcade_core/runtime/window/__init__.py +0 -0
- mini_arcade_core/runtime/window/window_adapter.py +26 -0
- mini_arcade_core/runtime/window/window_port.py +47 -0
- mini_arcade_core/scenes/__init__.py +0 -12
- mini_arcade_core/scenes/autoreg.py +1 -1
- mini_arcade_core/scenes/registry.py +21 -19
- mini_arcade_core/scenes/sim_scene.py +41 -0
- mini_arcade_core/scenes/systems/__init__.py +0 -0
- mini_arcade_core/scenes/systems/base_system.py +40 -0
- mini_arcade_core/scenes/systems/system_pipeline.py +57 -0
- mini_arcade_core/sim/__init__.py +0 -0
- mini_arcade_core/sim/protocols.py +41 -0
- mini_arcade_core/sim/runner.py +222 -0
- mini_arcade_core/spaces/__init__.py +0 -0
- mini_arcade_core/spaces/d2/__init__.py +0 -0
- mini_arcade_core/{two_d → spaces/d2}/collision2d.py +25 -28
- mini_arcade_core/{two_d → spaces/d2}/geometry2d.py +18 -0
- mini_arcade_core/{two_d → spaces/d2}/kinematics2d.py +5 -8
- mini_arcade_core/{two_d → spaces/d2}/physics2d.py +9 -0
- mini_arcade_core/ui/__init__.py +0 -14
- mini_arcade_core/ui/menu.py +415 -56
- mini_arcade_core/utils/__init__.py +10 -0
- mini_arcade_core/utils/deprecated_decorator.py +45 -0
- mini_arcade_core/utils/logging.py +174 -0
- {mini_arcade_core-0.9.9.dist-info → mini_arcade_core-1.0.0.dist-info}/METADATA +1 -1
- mini_arcade_core-1.0.0.dist-info/RECORD +65 -0
- {mini_arcade_core-0.9.9.dist-info → mini_arcade_core-1.0.0.dist-info}/WHEEL +1 -1
- mini_arcade_core/cheats.py +0 -235
- mini_arcade_core/entity.py +0 -71
- mini_arcade_core/game.py +0 -287
- mini_arcade_core/keymaps/__init__.py +0 -15
- mini_arcade_core/managers/base.py +0 -91
- mini_arcade_core/managers/entity_manager.py +0 -38
- mini_arcade_core/managers/overlay_manager.py +0 -33
- mini_arcade_core/scenes/scene.py +0 -93
- mini_arcade_core/two_d/__init__.py +0 -30
- mini_arcade_core-0.9.9.dist-info/RECORD +0 -31
- /mini_arcade_core/{keymaps → backend}/keys.py +0 -0
- /mini_arcade_core/{two_d → spaces/d2}/boundaries2d.py +0 -0
- {mini_arcade_core-0.9.9.dist-info → mini_arcade_core-1.0.0.dist-info}/licenses/LICENSE +0 -0
mini_arcade_core/game.py
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Game core module defining the Game class and configuration.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from __future__ import annotations
|
|
6
|
-
|
|
7
|
-
import os
|
|
8
|
-
from dataclasses import dataclass
|
|
9
|
-
from datetime import datetime
|
|
10
|
-
from pathlib import Path
|
|
11
|
-
from time import perf_counter, sleep
|
|
12
|
-
from typing import TYPE_CHECKING, Literal, Union
|
|
13
|
-
|
|
14
|
-
from PIL import Image # type: ignore[import]
|
|
15
|
-
|
|
16
|
-
from mini_arcade_core.backend import Backend
|
|
17
|
-
from mini_arcade_core.scenes import SceneRegistry
|
|
18
|
-
|
|
19
|
-
if TYPE_CHECKING: # avoid runtime circular import
|
|
20
|
-
from mini_arcade_core.scenes import Scene
|
|
21
|
-
|
|
22
|
-
SceneOrId = Union["Scene", str]
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@dataclass
|
|
26
|
-
class GameConfig:
|
|
27
|
-
"""
|
|
28
|
-
Configuration options for the Game.
|
|
29
|
-
|
|
30
|
-
:ivar width: Width of the game window in pixels.
|
|
31
|
-
:ivar height: Height of the game window in pixels.
|
|
32
|
-
:ivar title: Title of the game window.
|
|
33
|
-
:ivar fps: Target frames per second.
|
|
34
|
-
:ivar background_color: RGB background color.
|
|
35
|
-
:ivar backend: Optional Backend instance to use for rendering and input.
|
|
36
|
-
"""
|
|
37
|
-
|
|
38
|
-
width: int = 800
|
|
39
|
-
height: int = 600
|
|
40
|
-
title: str = "Mini Arcade Game"
|
|
41
|
-
fps: int = 60
|
|
42
|
-
background_color: tuple[int, int, int] = (0, 0, 0)
|
|
43
|
-
backend: Backend | None = None
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
Difficulty = Literal["easy", "normal", "hard", "insane"]
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
@dataclass
|
|
50
|
-
class GameSettings:
|
|
51
|
-
"""
|
|
52
|
-
Game settings that can be modified during gameplay.
|
|
53
|
-
|
|
54
|
-
:ivar difficulty: Current game difficulty level.
|
|
55
|
-
"""
|
|
56
|
-
|
|
57
|
-
difficulty: Difficulty = "normal"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
@dataclass
|
|
61
|
-
class _StackEntry:
|
|
62
|
-
scene: "Scene"
|
|
63
|
-
as_overlay: bool = False
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
class Game:
|
|
67
|
-
"""Core game object responsible for managing the main loop and active scene."""
|
|
68
|
-
|
|
69
|
-
def __init__(
|
|
70
|
-
self, config: GameConfig, registry: SceneRegistry | None = None
|
|
71
|
-
):
|
|
72
|
-
"""
|
|
73
|
-
:param config: Game configuration options.
|
|
74
|
-
:type config: GameConfig
|
|
75
|
-
|
|
76
|
-
:param registry: Optional SceneRegistry for scene management.
|
|
77
|
-
:type registry: SceneRegistry | None
|
|
78
|
-
|
|
79
|
-
:raises ValueError: If the provided config does not have a valid Backend.
|
|
80
|
-
"""
|
|
81
|
-
self.config = config
|
|
82
|
-
self._current_scene: Scene | None = None
|
|
83
|
-
self._running: bool = False
|
|
84
|
-
|
|
85
|
-
if config.backend is None:
|
|
86
|
-
raise ValueError(
|
|
87
|
-
"GameConfig.backend must be set to a Backend instance"
|
|
88
|
-
)
|
|
89
|
-
self.backend: Backend = config.backend
|
|
90
|
-
self.registry = registry or SceneRegistry(_factories={})
|
|
91
|
-
self._scene_stack: list[_StackEntry] = []
|
|
92
|
-
self.settings = GameSettings()
|
|
93
|
-
|
|
94
|
-
def current_scene(self) -> "Scene | None":
|
|
95
|
-
"""
|
|
96
|
-
Get the currently active scene.
|
|
97
|
-
|
|
98
|
-
:return: The active Scene instance, or None if no scene is active.
|
|
99
|
-
:rtype: Scene | None
|
|
100
|
-
"""
|
|
101
|
-
return self._scene_stack[-1].scene if self._scene_stack else None
|
|
102
|
-
|
|
103
|
-
def change_scene(self, scene: SceneOrId):
|
|
104
|
-
"""
|
|
105
|
-
Swap the active scene. Concrete implementations should call
|
|
106
|
-
``on_exit``/``on_enter`` appropriately.
|
|
107
|
-
|
|
108
|
-
:param scene: The new scene to activate.
|
|
109
|
-
:type scene: SceneOrId
|
|
110
|
-
"""
|
|
111
|
-
scene = self._resolve_scene(scene)
|
|
112
|
-
|
|
113
|
-
while self._scene_stack:
|
|
114
|
-
entry = self._scene_stack.pop()
|
|
115
|
-
entry.scene.on_exit()
|
|
116
|
-
|
|
117
|
-
self._scene_stack.append(_StackEntry(scene=scene, as_overlay=False))
|
|
118
|
-
scene.on_enter()
|
|
119
|
-
|
|
120
|
-
def push_scene(self, scene: SceneOrId, as_overlay: bool = False):
|
|
121
|
-
"""
|
|
122
|
-
Push a scene on top of the current one.
|
|
123
|
-
If as_overlay=True, underlying scene(s) may still be drawn but never updated.
|
|
124
|
-
|
|
125
|
-
:param scene: The scene to push onto the stack.
|
|
126
|
-
:type scene: SceneOrId
|
|
127
|
-
|
|
128
|
-
:param as_overlay: Whether to treat the scene as an overlay.
|
|
129
|
-
:type as_overlay: bool
|
|
130
|
-
"""
|
|
131
|
-
scene = self._resolve_scene(scene)
|
|
132
|
-
|
|
133
|
-
top = self.current_scene()
|
|
134
|
-
if top is not None:
|
|
135
|
-
top.on_pause()
|
|
136
|
-
|
|
137
|
-
self._scene_stack.append(
|
|
138
|
-
_StackEntry(scene=scene, as_overlay=as_overlay)
|
|
139
|
-
)
|
|
140
|
-
scene.on_enter()
|
|
141
|
-
|
|
142
|
-
def pop_scene(self) -> "Scene | None":
|
|
143
|
-
"""
|
|
144
|
-
Pop the top scene. If stack becomes empty, quit.
|
|
145
|
-
|
|
146
|
-
:return: The popped Scene instance, or None if the stack is now empty.
|
|
147
|
-
:rtype: Scene | None
|
|
148
|
-
"""
|
|
149
|
-
if not self._scene_stack:
|
|
150
|
-
return None
|
|
151
|
-
|
|
152
|
-
popped = self._scene_stack.pop()
|
|
153
|
-
popped.scene.on_exit()
|
|
154
|
-
|
|
155
|
-
top = self.current_scene()
|
|
156
|
-
if top is None:
|
|
157
|
-
self.quit()
|
|
158
|
-
return popped.scene
|
|
159
|
-
|
|
160
|
-
top.on_resume()
|
|
161
|
-
return popped.scene
|
|
162
|
-
|
|
163
|
-
def _visible_stack(self) -> list["Scene"]:
|
|
164
|
-
"""
|
|
165
|
-
Return the list of scenes that should be drawn (base + overlays).
|
|
166
|
-
We draw from the top-most non-overlay scene upward.
|
|
167
|
-
"""
|
|
168
|
-
if not self._scene_stack:
|
|
169
|
-
return []
|
|
170
|
-
|
|
171
|
-
# find top-most base scene (as_overlay=False)
|
|
172
|
-
base_idx = 0
|
|
173
|
-
for i in range(len(self._scene_stack) - 1, -1, -1):
|
|
174
|
-
if not self._scene_stack[i].as_overlay:
|
|
175
|
-
base_idx = i
|
|
176
|
-
break
|
|
177
|
-
|
|
178
|
-
return [e.scene for e in self._scene_stack[base_idx:]]
|
|
179
|
-
|
|
180
|
-
def quit(self):
|
|
181
|
-
"""Request that the main loop stops."""
|
|
182
|
-
self._running = False
|
|
183
|
-
|
|
184
|
-
def run(self, initial_scene: SceneOrId):
|
|
185
|
-
"""
|
|
186
|
-
Run the main loop starting with the given scene.
|
|
187
|
-
|
|
188
|
-
This is intentionally left abstract so you can plug pygame, pyglet,
|
|
189
|
-
or another backend.
|
|
190
|
-
|
|
191
|
-
:param initial_scene: The scene to start the game with.
|
|
192
|
-
:type initial_scene: SceneOrId
|
|
193
|
-
"""
|
|
194
|
-
backend = self.backend
|
|
195
|
-
backend.init(self.config.width, self.config.height, self.config.title)
|
|
196
|
-
|
|
197
|
-
br, bg, bb = self.config.background_color
|
|
198
|
-
backend.set_clear_color(br, bg, bb)
|
|
199
|
-
|
|
200
|
-
self.change_scene(initial_scene)
|
|
201
|
-
|
|
202
|
-
self._running = True
|
|
203
|
-
target_dt = 1.0 / self.config.fps if self.config.fps > 0 else 0.0
|
|
204
|
-
last_time = perf_counter()
|
|
205
|
-
|
|
206
|
-
while self._running:
|
|
207
|
-
now = perf_counter()
|
|
208
|
-
dt = now - last_time
|
|
209
|
-
last_time = now
|
|
210
|
-
|
|
211
|
-
top = self.current_scene()
|
|
212
|
-
if top is None:
|
|
213
|
-
break
|
|
214
|
-
|
|
215
|
-
for ev in backend.poll_events():
|
|
216
|
-
top.handle_event(ev)
|
|
217
|
-
|
|
218
|
-
top.update(dt)
|
|
219
|
-
|
|
220
|
-
backend.begin_frame()
|
|
221
|
-
for scene in self._visible_stack():
|
|
222
|
-
scene.draw(backend)
|
|
223
|
-
backend.end_frame()
|
|
224
|
-
|
|
225
|
-
if target_dt > 0 and dt < target_dt:
|
|
226
|
-
sleep(target_dt - dt)
|
|
227
|
-
|
|
228
|
-
# exit remaining scenes
|
|
229
|
-
while self._scene_stack:
|
|
230
|
-
entry = self._scene_stack.pop()
|
|
231
|
-
entry.scene.on_exit()
|
|
232
|
-
|
|
233
|
-
@staticmethod
|
|
234
|
-
def _convert_bmp_to_image(bmp_path: str, out_path: str) -> bool:
|
|
235
|
-
"""
|
|
236
|
-
Convert a BMP file to another image format using Pillow.
|
|
237
|
-
|
|
238
|
-
:param bmp_path: Path to the input BMP file.
|
|
239
|
-
:type bmp_path: str
|
|
240
|
-
|
|
241
|
-
:param out_path: Path to the output image file.
|
|
242
|
-
:type out_path: str
|
|
243
|
-
|
|
244
|
-
:return: True if conversion was successful, False otherwise.
|
|
245
|
-
:rtype: bool
|
|
246
|
-
"""
|
|
247
|
-
try:
|
|
248
|
-
img = Image.open(bmp_path)
|
|
249
|
-
img.save(out_path) # Pillow chooses format from extension
|
|
250
|
-
return True
|
|
251
|
-
# Justification: Pillow can raise various exceptions on failure
|
|
252
|
-
# pylint: disable=broad-exception-caught
|
|
253
|
-
except Exception:
|
|
254
|
-
return False
|
|
255
|
-
# pylint: enable=broad-exception-caught
|
|
256
|
-
|
|
257
|
-
def screenshot(
|
|
258
|
-
self, label: str | None = None, directory: str = "screenshots"
|
|
259
|
-
) -> str | None:
|
|
260
|
-
"""
|
|
261
|
-
Ask backend to save a screenshot. Returns the file path or None.
|
|
262
|
-
|
|
263
|
-
:param label: Optional label to include in the filename.
|
|
264
|
-
:type label: str | None
|
|
265
|
-
|
|
266
|
-
:param directory: Directory to save screenshots in.
|
|
267
|
-
:type directory: str
|
|
268
|
-
|
|
269
|
-
:return: The file path of the saved screenshot, or None on failure.
|
|
270
|
-
:rtype: str | None
|
|
271
|
-
"""
|
|
272
|
-
os.makedirs(directory, exist_ok=True)
|
|
273
|
-
stamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
274
|
-
label = label or "shot"
|
|
275
|
-
filename = f"{stamp}_{label}"
|
|
276
|
-
bmp_path = os.path.join(directory, f"{filename}.bmp")
|
|
277
|
-
|
|
278
|
-
if self.backend.capture_frame(bmp_path):
|
|
279
|
-
out_path = Path(directory) / f"{filename}.png"
|
|
280
|
-
self._convert_bmp_to_image(bmp_path, str(out_path))
|
|
281
|
-
return str(out_path)
|
|
282
|
-
return None
|
|
283
|
-
|
|
284
|
-
def _resolve_scene(self, scene: SceneOrId) -> "Scene":
|
|
285
|
-
if isinstance(scene, str):
|
|
286
|
-
return self.registry.create(scene, self)
|
|
287
|
-
return scene
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Keymaps for Mini Arcade Core.
|
|
3
|
-
Includes key definitions and default key mappings.
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from __future__ import annotations
|
|
7
|
-
|
|
8
|
-
from .keys import Key, keymap
|
|
9
|
-
from .sdl import SDL_KEYCODE_TO_KEY
|
|
10
|
-
|
|
11
|
-
__all__ = [
|
|
12
|
-
"Key",
|
|
13
|
-
"keymap",
|
|
14
|
-
"SDL_KEYCODE_TO_KEY",
|
|
15
|
-
]
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Base manager classes for handling collections of items.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from __future__ import annotations
|
|
6
|
-
|
|
7
|
-
from dataclasses import dataclass, field
|
|
8
|
-
from typing import Callable, Generic, Iterable, List, Protocol, TypeVar
|
|
9
|
-
|
|
10
|
-
from mini_arcade_core.backend.backend import Backend
|
|
11
|
-
|
|
12
|
-
# ---- shared types ----
|
|
13
|
-
T = TypeVar("T")
|
|
14
|
-
OverlayFunc = Callable[[Backend], None]
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class Drawable(Protocol):
|
|
18
|
-
"""Defines a drawable entity."""
|
|
19
|
-
|
|
20
|
-
def draw(self, surface: Backend):
|
|
21
|
-
"""
|
|
22
|
-
Draw the entity on the given surface.
|
|
23
|
-
|
|
24
|
-
:param surface: The backend surface to draw on.
|
|
25
|
-
:type surface: Backend
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class Updatable(Protocol):
|
|
30
|
-
"""Defines an updatable entity."""
|
|
31
|
-
|
|
32
|
-
def update(self, dt: float):
|
|
33
|
-
"""
|
|
34
|
-
Update the entity state.
|
|
35
|
-
|
|
36
|
-
:param dt: Time delta in seconds.
|
|
37
|
-
:type dt: float
|
|
38
|
-
"""
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
class EntityLike(Drawable, Updatable, Protocol):
|
|
42
|
-
"""Defines a game entity."""
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
@dataclass
|
|
46
|
-
class ListManager(Generic[T]):
|
|
47
|
-
"""
|
|
48
|
-
Generic manager for a list of items.
|
|
49
|
-
|
|
50
|
-
:ivar items (List[T]): List of managed items.
|
|
51
|
-
"""
|
|
52
|
-
|
|
53
|
-
items: List[T] = field(default_factory=list)
|
|
54
|
-
|
|
55
|
-
def add(self, *items: T):
|
|
56
|
-
"""
|
|
57
|
-
Add one or more items to the manager.
|
|
58
|
-
|
|
59
|
-
:param items: One or more items to add.
|
|
60
|
-
:type items: T
|
|
61
|
-
"""
|
|
62
|
-
self.items.extend(items)
|
|
63
|
-
|
|
64
|
-
def add_many(self, items: Iterable[T]):
|
|
65
|
-
"""
|
|
66
|
-
Add multiple items to the manager.
|
|
67
|
-
|
|
68
|
-
:param items: An iterable of items to add.
|
|
69
|
-
:type items: Iterable[T]
|
|
70
|
-
"""
|
|
71
|
-
self.items.extend(items)
|
|
72
|
-
|
|
73
|
-
def remove(self, item: T):
|
|
74
|
-
"""
|
|
75
|
-
Remove a single item from the manager, if present.
|
|
76
|
-
|
|
77
|
-
:param item: The item to remove.
|
|
78
|
-
:type item: T
|
|
79
|
-
"""
|
|
80
|
-
if item in self.items:
|
|
81
|
-
self.items.remove(item)
|
|
82
|
-
|
|
83
|
-
def clear(self):
|
|
84
|
-
"""Clear all items from the manager."""
|
|
85
|
-
self.items.clear()
|
|
86
|
-
|
|
87
|
-
def __iter__(self):
|
|
88
|
-
return iter(self.items)
|
|
89
|
-
|
|
90
|
-
def __len__(self) -> int:
|
|
91
|
-
return len(self.items)
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Entity manager for handling a collection of entities.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from __future__ import annotations
|
|
6
|
-
|
|
7
|
-
from dataclasses import dataclass
|
|
8
|
-
|
|
9
|
-
from mini_arcade_core.backend import Backend
|
|
10
|
-
|
|
11
|
-
from .base import EntityLike, ListManager
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@dataclass
|
|
15
|
-
class EntityManager(ListManager[EntityLike]):
|
|
16
|
-
"""
|
|
17
|
-
Manages a collection of entities within a scene.
|
|
18
|
-
"""
|
|
19
|
-
|
|
20
|
-
def update(self, dt: float):
|
|
21
|
-
"""
|
|
22
|
-
Update all managed entities.
|
|
23
|
-
|
|
24
|
-
:param dt: Time delta in seconds.
|
|
25
|
-
:type dt: float
|
|
26
|
-
"""
|
|
27
|
-
for ent in list(self.items):
|
|
28
|
-
ent.update(dt)
|
|
29
|
-
|
|
30
|
-
def draw(self, surface: "Backend"):
|
|
31
|
-
"""
|
|
32
|
-
Draw all managed entities.
|
|
33
|
-
|
|
34
|
-
:param surface: The backend surface to draw on.
|
|
35
|
-
:type surface: Backend
|
|
36
|
-
"""
|
|
37
|
-
for ent in list(self.items):
|
|
38
|
-
ent.draw(surface)
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Overlay manager for handling a collection of overlays.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from __future__ import annotations
|
|
6
|
-
|
|
7
|
-
from dataclasses import dataclass
|
|
8
|
-
from typing import TYPE_CHECKING, Callable
|
|
9
|
-
|
|
10
|
-
from mini_arcade_core.backend import Backend
|
|
11
|
-
from mini_arcade_core.managers.base import ListManager
|
|
12
|
-
|
|
13
|
-
if TYPE_CHECKING:
|
|
14
|
-
from mini_arcade_core.game import Game
|
|
15
|
-
|
|
16
|
-
OverlayFunc = Callable[[Backend], None]
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@dataclass
|
|
20
|
-
class OverlayManager(ListManager[OverlayFunc]):
|
|
21
|
-
"""
|
|
22
|
-
Manages a collection of overlays within a scene.
|
|
23
|
-
"""
|
|
24
|
-
|
|
25
|
-
def draw(self, surface: "Backend"):
|
|
26
|
-
"""
|
|
27
|
-
Call all overlays. Scenes should call this at the end of draw().
|
|
28
|
-
|
|
29
|
-
:param surface: The backend surface to draw on.
|
|
30
|
-
:type surface: Backend
|
|
31
|
-
"""
|
|
32
|
-
for overlay in self.items:
|
|
33
|
-
overlay(surface)
|
mini_arcade_core/scenes/scene.py
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Base class for game scenes (states/screens).
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from __future__ import annotations
|
|
6
|
-
|
|
7
|
-
from abc import ABC, abstractmethod
|
|
8
|
-
from dataclasses import dataclass, field
|
|
9
|
-
from typing import TYPE_CHECKING, List, Optional
|
|
10
|
-
|
|
11
|
-
from mini_arcade_core.backend import Backend, Event
|
|
12
|
-
from mini_arcade_core.entity import Entity
|
|
13
|
-
from mini_arcade_core.managers import EntityManager, OverlayManager
|
|
14
|
-
from mini_arcade_core.two_d import Size2D
|
|
15
|
-
|
|
16
|
-
if TYPE_CHECKING:
|
|
17
|
-
from mini_arcade_core.game import Game
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
@dataclass
|
|
21
|
-
class SceneServices:
|
|
22
|
-
"""
|
|
23
|
-
Container for scene services like entity and overlay managers.
|
|
24
|
-
|
|
25
|
-
:ivar entities: EntityManager for managing scene entities.
|
|
26
|
-
:ivar overlays: OverlayManager for managing scene overlays.
|
|
27
|
-
"""
|
|
28
|
-
|
|
29
|
-
entities: EntityManager = field(default_factory=EntityManager)
|
|
30
|
-
overlays: OverlayManager = field(default_factory=OverlayManager)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class Scene(ABC):
|
|
34
|
-
"""Base class for game scenes (states/screens)."""
|
|
35
|
-
|
|
36
|
-
def __init__(
|
|
37
|
-
self,
|
|
38
|
-
game: Game,
|
|
39
|
-
*,
|
|
40
|
-
services: Optional[SceneServices] = None,
|
|
41
|
-
):
|
|
42
|
-
"""
|
|
43
|
-
:param game: Reference to the main Game object.
|
|
44
|
-
:type game: Game
|
|
45
|
-
"""
|
|
46
|
-
self.game = game
|
|
47
|
-
self.entities: List[Entity] = []
|
|
48
|
-
self.size: Size2D = Size2D(game.config.width, game.config.height)
|
|
49
|
-
|
|
50
|
-
self.services: SceneServices = (
|
|
51
|
-
services if services is not None else SceneServices()
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
@abstractmethod
|
|
55
|
-
def on_enter(self):
|
|
56
|
-
"""Called when the scene becomes active."""
|
|
57
|
-
|
|
58
|
-
@abstractmethod
|
|
59
|
-
def on_exit(self):
|
|
60
|
-
"""Called when the scene is replaced."""
|
|
61
|
-
|
|
62
|
-
@abstractmethod
|
|
63
|
-
def handle_event(self, event: Event):
|
|
64
|
-
"""
|
|
65
|
-
Handle input / events (e.g. pygame.Event).
|
|
66
|
-
|
|
67
|
-
:param event: The event to handle.
|
|
68
|
-
:type event: Event
|
|
69
|
-
"""
|
|
70
|
-
|
|
71
|
-
@abstractmethod
|
|
72
|
-
def update(self, dt: float):
|
|
73
|
-
"""
|
|
74
|
-
Update game logic. ``dt`` is the delta time in seconds.
|
|
75
|
-
|
|
76
|
-
:param dt: Time delta in seconds.
|
|
77
|
-
:type dt: float
|
|
78
|
-
"""
|
|
79
|
-
|
|
80
|
-
@abstractmethod
|
|
81
|
-
def draw(self, surface: Backend):
|
|
82
|
-
"""
|
|
83
|
-
Render to the main surface.
|
|
84
|
-
|
|
85
|
-
:param surface: The backend surface to draw on.
|
|
86
|
-
:type surface: Backend
|
|
87
|
-
"""
|
|
88
|
-
|
|
89
|
-
def on_pause(self):
|
|
90
|
-
"""Called when the game is paused."""
|
|
91
|
-
|
|
92
|
-
def on_resume(self):
|
|
93
|
-
"""Called when the game is resumed."""
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Two-dimensional utilities and components for Mini Arcade Core.
|
|
3
|
-
Includes 2D entities, boundaries, and physics.
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from __future__ import annotations
|
|
7
|
-
|
|
8
|
-
from .boundaries2d import (
|
|
9
|
-
RectKinematic,
|
|
10
|
-
RectSprite,
|
|
11
|
-
VerticalBounce,
|
|
12
|
-
VerticalWrap,
|
|
13
|
-
)
|
|
14
|
-
from .collision2d import RectCollider
|
|
15
|
-
from .geometry2d import Bounds2D, Position2D, Size2D
|
|
16
|
-
from .kinematics2d import KinematicData
|
|
17
|
-
from .physics2d import Velocity2D
|
|
18
|
-
|
|
19
|
-
__all__ = [
|
|
20
|
-
"Bounds2D",
|
|
21
|
-
"Position2D",
|
|
22
|
-
"Size2D",
|
|
23
|
-
"KinematicData",
|
|
24
|
-
"Velocity2D",
|
|
25
|
-
"RectCollider",
|
|
26
|
-
"RectKinematic",
|
|
27
|
-
"RectSprite",
|
|
28
|
-
"VerticalBounce",
|
|
29
|
-
"VerticalWrap",
|
|
30
|
-
]
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
mini_arcade_core/__init__.py,sha256=m9wELq1seQQE13tfU6DT7XinC07yzo5KTS1KEA0MQNs,3804
|
|
2
|
-
mini_arcade_core/backend/__init__.py,sha256=w-6QTUngdIYZuvEU3B8zL-vXyKbyLDVucbt7yKZdLlc,379
|
|
3
|
-
mini_arcade_core/backend/backend.py,sha256=dLXTtLn5qURftWOWOVQd2ouuZmJpbiOl11KMIDRk2us,4026
|
|
4
|
-
mini_arcade_core/backend/events.py,sha256=usn2HTk5-5ZiaU2IjbrNRpEj_4uoaiqfY3qufQLYy0w,2929
|
|
5
|
-
mini_arcade_core/backend/types.py,sha256=SuiwXGNmXCZxfPsww6zj3V_NK7k4jpoCuzMn19afS-g,175
|
|
6
|
-
mini_arcade_core/cheats.py,sha256=J0HPLUC6sARXNl_CtUaWhWoo9A0vEjQcIHP6XJUPrNQ,7133
|
|
7
|
-
mini_arcade_core/entity.py,sha256=vDe2v7GajyGaqckBYeD3cjs--pOTFrDNhMIdf7PZsJQ,1759
|
|
8
|
-
mini_arcade_core/game.py,sha256=C8flMXn_DMHWDmr5FVrTey_nUHabwja8wSaialNMcLg,8526
|
|
9
|
-
mini_arcade_core/keymaps/__init__.py,sha256=_5Y5_61XT5TsOhbb6p2EPzvjCNN9hCPoxTgj_TAfBvA,258
|
|
10
|
-
mini_arcade_core/keymaps/keys.py,sha256=LTg20SwLBI3kpPIiTNpq2yBft_QUGj-iNFSNm9M-Fus,3010
|
|
11
|
-
mini_arcade_core/keymaps/sdl.py,sha256=Tb0amkbmYjYkEkYnMZ6i9QWjwXBkEHIm13-gEMUYENM,2060
|
|
12
|
-
mini_arcade_core/managers/__init__.py,sha256=ZpWVxqUq2lbLdrtPR75ipSmykp3fpm9nQrQHP15sGJI,352
|
|
13
|
-
mini_arcade_core/managers/base.py,sha256=D2CCde_zbsrlLNzs3v3qgYpRu9QgmFlzOfdfFIwf5xs,2023
|
|
14
|
-
mini_arcade_core/managers/entity_manager.py,sha256=mBgSFgdZ73f5ZZ-_GtvnqOFWuSySX5QJZrZ77sH4qes,831
|
|
15
|
-
mini_arcade_core/managers/overlay_manager.py,sha256=LTywwhSigjGiCKqULBGjKJPT6xyYgeoKXfhPEoOw8Nk,801
|
|
16
|
-
mini_arcade_core/scenes/__init__.py,sha256=MXaWaDvwf0ycd5GZ_9DhPQ7tWqsp-ECWTOZpGZarcRE,323
|
|
17
|
-
mini_arcade_core/scenes/autoreg.py,sha256=b4V0jaA65I2hnT2f___rg_pT556OjrtoNjIRdZrXBaI,1009
|
|
18
|
-
mini_arcade_core/scenes/registry.py,sha256=0B3iSvepydwMpELQz8cRaQeAU0pR1Fz9O1YtWshLjQw,3226
|
|
19
|
-
mini_arcade_core/scenes/scene.py,sha256=MrHAHf-su6xrLXi4y1opxJWy0YF-yLfSN6rOvSHPqCc,2384
|
|
20
|
-
mini_arcade_core/two_d/__init__.py,sha256=iWjm39RYDEshxSmiIWyGWa6Qr9O2gnHfOpzrl63FUro,626
|
|
21
|
-
mini_arcade_core/two_d/boundaries2d.py,sha256=H1HkCR1422MkQIEve2DFKvnav4RpvtLx-qTMxzmdDMQ,2610
|
|
22
|
-
mini_arcade_core/two_d/collision2d.py,sha256=jR5bOmqUaedxRzwFoKBgn7k-ozwklB4RP9pUTVk6aUw,1716
|
|
23
|
-
mini_arcade_core/two_d/geometry2d.py,sha256=js791mMpsE_YbEoqtTOsOxNSflvKgSk6VeVKhj9N318,1282
|
|
24
|
-
mini_arcade_core/two_d/kinematics2d.py,sha256=NFMiIzDYqDquyg_EhD7EQBJ_Sz4RncmkEjfls9NwkPs,2102
|
|
25
|
-
mini_arcade_core/two_d/physics2d.py,sha256=qIq86qWVuvcnLIMEPH6xx7XQO4tQhfiMZY6FseuVOR8,1636
|
|
26
|
-
mini_arcade_core/ui/__init__.py,sha256=RmcZXfBFFmL09j_Bo1LHagRjiKYajuySPilIUNjc3KQ,248
|
|
27
|
-
mini_arcade_core/ui/menu.py,sha256=J3hYY46xOHLN65WSet4-cnQU7L5pu48scjLJUW9IkEM,13681
|
|
28
|
-
mini_arcade_core-0.9.9.dist-info/METADATA,sha256=G7IK6yFjXiaGPHQr9_DcedeRXQAmhWlgXCcjyHslr1U,8188
|
|
29
|
-
mini_arcade_core-0.9.9.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
30
|
-
mini_arcade_core-0.9.9.dist-info/licenses/LICENSE,sha256=3lHAuV0584cVS5vAqi2uC6GcsVgxUijvwvtZckyvaZ4,1096
|
|
31
|
-
mini_arcade_core-0.9.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|