mini-arcade-core 0.9.8__tar.gz → 0.9.9__tar.gz

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.
Files changed (32) hide show
  1. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/PKG-INFO +1 -1
  2. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/pyproject.toml +1 -1
  3. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/__init__.py +7 -1
  4. mini_arcade_core-0.9.9/src/mini_arcade_core/managers/__init__.py +14 -0
  5. mini_arcade_core-0.9.9/src/mini_arcade_core/managers/base.py +91 -0
  6. mini_arcade_core-0.9.9/src/mini_arcade_core/managers/entity_manager.py +38 -0
  7. mini_arcade_core-0.9.9/src/mini_arcade_core/managers/overlay_manager.py +33 -0
  8. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/scenes/__init__.py +2 -2
  9. mini_arcade_core-0.9.9/src/mini_arcade_core/scenes/scene.py +93 -0
  10. mini_arcade_core-0.9.8/src/mini_arcade_core/scenes/scene.py +0 -149
  11. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/LICENSE +0 -0
  12. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/README.md +0 -0
  13. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/backend/__init__.py +0 -0
  14. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/backend/backend.py +0 -0
  15. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/backend/events.py +0 -0
  16. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/backend/types.py +0 -0
  17. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/cheats.py +0 -0
  18. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/entity.py +0 -0
  19. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/game.py +0 -0
  20. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/keymaps/__init__.py +0 -0
  21. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/keymaps/keys.py +0 -0
  22. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/keymaps/sdl.py +0 -0
  23. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/scenes/autoreg.py +0 -0
  24. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/scenes/registry.py +0 -0
  25. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/two_d/__init__.py +0 -0
  26. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/two_d/boundaries2d.py +0 -0
  27. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/two_d/collision2d.py +0 -0
  28. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/two_d/geometry2d.py +0 -0
  29. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/two_d/kinematics2d.py +0 -0
  30. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/two_d/physics2d.py +0 -0
  31. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/ui/__init__.py +0 -0
  32. {mini_arcade_core-0.9.8 → mini_arcade_core-0.9.9}/src/mini_arcade_core/ui/menu.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mini-arcade-core
3
- Version: 0.9.8
3
+ Version: 0.9.9
4
4
  Summary: Tiny scene-based game loop core for small arcade games.
5
5
  License: Copyright (c) 2025 Santiago Rincón
6
6
 
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [project]
6
6
  name = "mini-arcade-core"
7
- version = "0.9.8"
7
+ version = "0.9.9"
8
8
  description = "Tiny scene-based game loop core for small arcade games."
9
9
  authors = [
10
10
  { name = "Santiago Rincon", email = "rincores@gmail.com" },
@@ -14,7 +14,12 @@ from mini_arcade_core.cheats import CheatCode, CheatManager
14
14
  from mini_arcade_core.entity import Entity, KinematicEntity, SpriteEntity
15
15
  from mini_arcade_core.game import Game, GameConfig
16
16
  from mini_arcade_core.keymaps.keys import Key, keymap
17
- from mini_arcade_core.scenes import Scene, SceneRegistry, register_scene
17
+ from mini_arcade_core.scenes import (
18
+ Scene,
19
+ SceneRegistry,
20
+ SceneServices,
21
+ register_scene,
22
+ )
18
23
  from mini_arcade_core.two_d import (
19
24
  Bounds2D,
20
25
  KinematicData,
@@ -108,6 +113,7 @@ __all__ = [
108
113
  "register_scene",
109
114
  "CheatManager",
110
115
  "CheatCode",
116
+ "SceneServices",
111
117
  ]
112
118
 
113
119
  PACKAGE_NAME = "mini-arcade-core" # or whatever is in your pyproject.toml
@@ -0,0 +1,14 @@
1
+ """
2
+ Managers module for Mini Arcade Core.
3
+ Provides various manager classes for handling game entities and resources.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from mini_arcade_core.managers.entity_manager import EntityManager
9
+ from mini_arcade_core.managers.overlay_manager import OverlayManager
10
+
11
+ __all__ = [
12
+ "EntityManager",
13
+ "OverlayManager",
14
+ ]
@@ -0,0 +1,91 @@
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)
@@ -0,0 +1,38 @@
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)
@@ -0,0 +1,33 @@
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)
@@ -7,6 +7,6 @@ from __future__ import annotations
7
7
 
8
8
  from .autoreg import register_scene
9
9
  from .registry import SceneRegistry
10
- from .scene import Scene
10
+ from .scene import Scene, SceneServices
11
11
 
12
- __all__ = ["Scene", "register_scene", "SceneRegistry"]
12
+ __all__ = ["Scene", "register_scene", "SceneRegistry", "SceneServices"]
@@ -0,0 +1,93 @@
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,149 +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 typing import TYPE_CHECKING, Callable, List
9
-
10
- from mini_arcade_core.backend import Backend, Event
11
- from mini_arcade_core.entity import Entity
12
- from mini_arcade_core.two_d import Size2D
13
-
14
- if TYPE_CHECKING:
15
- from mini_arcade_core.game import Game
16
-
17
- OverlayFunc = Callable[[Backend], None]
18
-
19
-
20
- class Scene(ABC):
21
- """Base class for game scenes (states/screens)."""
22
-
23
- def __init__(self, game: Game):
24
- """
25
- :param game: Reference to the main Game object.
26
- :type game: Game
27
- """
28
- self.game = game
29
- self.entities: List[Entity] = []
30
- self.size: Size2D = Size2D(game.config.width, game.config.height)
31
- # overlays drawn on top of the scene
32
- self._overlays: List[OverlayFunc] = []
33
-
34
- def add_entity(self, *entities: Entity):
35
- """
36
- Register one or more entities in this scene.
37
-
38
- :param entities: One or more Entity instances to add.
39
- :type entities: Entity
40
- """
41
- self.entities.extend(entities)
42
-
43
- def remove_entity(self, entity: Entity):
44
- """
45
- Unregister a single entity, if present.
46
-
47
- :param entity: The Entity instance to remove.
48
- :type entity: Entity
49
- """
50
- if entity in self.entities:
51
- self.entities.remove(entity)
52
-
53
- def clear_entities(self):
54
- """Remove all entities from the scene."""
55
- self.entities.clear()
56
-
57
- def update_entities(self, dt: float):
58
- """
59
- Default update loop for all entities.
60
-
61
- :param dt: Time delta in seconds.
62
- :type dt: float
63
- """
64
- for ent in self.entities:
65
- ent.update(dt)
66
-
67
- def draw_entities(self, surface: Backend):
68
- """
69
- Default draw loop for all entities.
70
-
71
- :param surface: The backend surface to draw on.
72
- :type surface: Backend
73
- """
74
- for ent in self.entities:
75
- ent.draw(surface)
76
-
77
- def add_overlay(self, overlay: OverlayFunc):
78
- """
79
- Register an overlay (drawn every frame, after entities).
80
-
81
- :param overlay: A callable that takes a Backend and draws on it.
82
- :type overlay: OverlayFunc
83
- """
84
- self._overlays.append(overlay)
85
-
86
- def remove_overlay(self, overlay: OverlayFunc):
87
- """
88
- Unregister a previously added overlay.
89
-
90
- :param overlay: The overlay to remove.
91
- :type overlay: OverlayFunc
92
- """
93
- if overlay in self._overlays:
94
- self._overlays.remove(overlay)
95
-
96
- def clear_overlays(self):
97
- """Clear all registered overlays."""
98
- self._overlays.clear()
99
-
100
- def draw_overlays(self, surface: Backend):
101
- """
102
- Call all overlays. Scenes should call this at the end of draw().
103
-
104
- :param surface: The backend surface to draw on.
105
- :type surface: Backend
106
- """
107
- for overlay in self._overlays:
108
- overlay(surface)
109
-
110
- @abstractmethod
111
- def on_enter(self):
112
- """Called when the scene becomes active."""
113
-
114
- @abstractmethod
115
- def on_exit(self):
116
- """Called when the scene is replaced."""
117
-
118
- @abstractmethod
119
- def handle_event(self, event: Event):
120
- """
121
- Handle input / events (e.g. pygame.Event).
122
-
123
- :param event: The event to handle.
124
- :type event: Event
125
- """
126
-
127
- @abstractmethod
128
- def update(self, dt: float):
129
- """
130
- Update game logic. ``dt`` is the delta time in seconds.
131
-
132
- :param dt: Time delta in seconds.
133
- :type dt: float
134
- """
135
-
136
- @abstractmethod
137
- def draw(self, surface: Backend):
138
- """
139
- Render to the main surface.
140
-
141
- :param surface: The backend surface to draw on.
142
- :type surface: Backend
143
- """
144
-
145
- def on_pause(self):
146
- """Called when the game is paused."""
147
-
148
- def on_resume(self):
149
- """Called when the game is resumed."""