mini_arcade_core.backend¶
Backend module for rendering and input abstraction. Defines the Backend interface and related types. This is the only part of the code that talks to SDL/pygame directly.
Submodules¶
Classes¶
Interface for audio operations. |
|
Interface that any rendering/input backend must implement. |
|
Interface for frame capture operations. |
|
Interface for input operations. |
|
Interface for rendering operations. |
|
Interface for text rendering operations. |
|
Represents a game window. |
Package Contents¶
- class mini_arcade_core.backend.AudioProtocol[source]¶
Bases:
ProtocolInterface for audio operations.
- init(frequency: int = 44100, channels: int = 2, chunk_size: int = 2048)[source]¶
Initialize audio subsystem.
- Parameters:
frequency (int) – Audio frequency in Hz.
channels (int) – Number of audio channels (1=mono, 2=stereo).
chunk_size (int) – Size of audio chunks.
- load_sound(sound_id: str, path: str)[source]¶
Load a sound file.
- Parameters:
sound_id (str) – Unique identifier for the sound.
path (str) – File path to the sound.
- play_sound(sound_id: str, loops: int = 0)[source]¶
Play a loaded sound.
- Parameters:
sound_id (str) – Unique identifier for the sound.
loops (int) – Number of times to loop the sound.
- set_master_volume(volume: int)[source]¶
Set the master volume.
- Parameters:
volume (int) – Volume level (0-128).
- class mini_arcade_core.backend.Backend[source]¶
Bases:
ProtocolInterface that any rendering/input backend must implement. mini-arcade-core only talks to this protocol, never to SDL/pygame directly.
Each sub-capability is exposed as a typed protocol attribute so that systems or draw helpers can accept only the slice they need (e.g.
RenderProtocolorTextProtocol) instead of the full backend.- Variables:
(WindowProtocol) (window) – Window management interface.
(AudioProtocol) (audio) – Audio management interface.
(InputProtocol) (input) – Input management interface.
(RenderProtocol) (render) – Rendering interface.
(TextProtocol) (text) – Text rendering interface.
(CaptureProtocol) (capture) – Frame capture interface.
- window: WindowProtocol¶
- audio: AudioProtocol¶
- input: InputProtocol¶
- render: RenderProtocol¶
- text: TextProtocol¶
- capture: CaptureProtocol¶
- init()[source]¶
Initialize the backend and open a window. Should be called once before the main loop.
- class mini_arcade_core.backend.CaptureProtocol[source]¶
Bases:
ProtocolInterface for frame capture operations.
- class mini_arcade_core.backend.InputProtocol[source]¶
Bases:
ProtocolInterface for input operations.
- poll() Iterable[mini_arcade_core.backend.events.Event][source]¶
Get the list of input events since the last call.
- Returns:
Iterable of Event instances.
- Return type:
Iterable[Event]
- class mini_arcade_core.backend.RenderProtocol[source]¶
Bases:
ProtocolInterface for rendering operations.
- set_clear_color(r: int, g: int, b: int)[source]¶
Set the clear color for the renderer.
- Parameters:
r (int) – Red component (0-255).
g (int) – Green component (0-255).
b (int) – Blue component (0-255).
- draw_rect(x: int, y: int, w: int, h: int, color=(255, 255, 255))[source]¶
Draw a filled rectangle.
- Parameters:
x (int) – The x-coordinate of the rectangle.
y (int) – The y-coordinate of the rectangle.
w (int) – The width of the rectangle.
h (int) – The height of the rectangle.
color (tuple[int, int, int] | tuple[int, int, int, int]) – The color of the rectangle as an (R, G, B) or (R, G, B, A) tuple.
- draw_line(x1: int, y1: int, x2: int, y2: int, color=(255, 255, 255), thickness: int = 1)[source]¶
Draw a line between two points.
- Parameters:
x1 (int) – The x-coordinate of the start point.
y1 (int) – The y-coordinate of the start point.
x2 (int) – The x-coordinate of the end point.
y2 (int) – The y-coordinate of the end point.
color (tuple[int, int, int] | tuple[int, int, int, int]) – The color of the line as an (R, G, B) or (R, G, B, A) tuple.
- set_clip_rect(x: int, y: int, w: int, h: int)[source]¶
Set the clipping rectangle.
- Parameters:
x (int) – The x-coordinate of the clipping rectangle.
y (int) – The y-coordinate of the clipping rectangle.
w (int) – The width of the clipping rectangle.
h (int) – The height of the clipping rectangle.
- create_texture_rgba(w: int, h: int, pixels: bytes, pitch: int | None = None) int[source]¶
Create a texture from RGBA pixel data.
- Parameters:
w (int) – The width of the texture.
h (int) – The height of the texture.
pixels (bytes) – The pixel data in RGBA format.
pitch (int | None) – The number of bytes in a row of pixel data. If None, defaults to w * 4.
- destroy_texture(tex: int) None[source]¶
Destroy a texture.
- Parameters:
tex (int) – The texture ID to destroy.
- draw_texture(tex: int, x: int, y: int, w: int, h: int, angle_deg: float = 0.0)[source]¶
Draw a texture at the specified position and size.
- Parameters:
tex (int) – The texture ID.
x (int) – The x-coordinate to draw the texture.
y (int) – The y-coordinate to draw the texture.
w (int) – The width to draw the texture.
h (int) – The height to draw the texture.
angle_deg (float) – Clockwise rotation angle in degrees around texture center.
- draw_texture_tiled_y(tex_id: int, x: int, y: int, w: int, h: int)[source]¶
Draw a texture repeated vertically to fill (w,h). Assumes you can resolve tex_id -> pygame.Surface, and supports scaling width.
- Parameters:
tex_id (int) – The texture ID.
x (int) – The x-coordinate to draw the texture.
y (int) – The y-coordinate to draw the texture.
w (int) – The width to draw the texture.
h (int) – The height to draw the texture.
- draw_circle(x: int, y: int, radius: int, color=(255, 255, 255))[source]¶
Draw a filled circle.
- Parameters:
x – Center x
y – Center y
radius – Radius in pixels
color – (R,G,B) or (R,G,B,A)
- draw_poly(points: list[tuple[int, int]], color=(255, 255, 255), filled: bool = True)[source]¶
Draw a polygon defined by a list of points.
- Parameters:
points (list[tuple[int, int]]) – List of (x, y) tuples defining the vertices of the polygon.
color (tuple[int, int, int] | tuple[int, int, int, int]) – The color of the polygon as an (R, G, B) or (R, G, B, A) tuple.
filled (bool) – Whether to draw a filled polygon or just the outline.
- class mini_arcade_core.backend.TextProtocol[source]¶
Bases:
ProtocolInterface for text rendering operations.
- measure(text: str, font_size: int | None = None, font_name: str | None = None) tuple[int, int][source]¶
Measure the width and height of the given text.
- Parameters:
text (str) – The text to measure.
font_size (int | None) – The font size to use for measurement.
font_name (str | None) – Optional named font configured by the backend.
- Returns:
A tuple containing the width and height of the text.
- Return type:
tuple[int, int]
- draw(x: int, y: int, text: str, color=(255, 255, 255), font_size: int | None = None, font_name: str | None = None)[source]¶
Draw the given text at the specified position.
- Parameters:
x (int) – The x-coordinate to draw the text.
y (int) – The y-coordinate to draw the text.
text (str) – The text to draw.
color (tuple[int, int, int] | tuple[int, int, int, int]) – The color of the text as an (R, G, B) or (R, G, B, A) tuple.
font_size (int | None) – The font size to use for drawing.
font_name (str | None) – Optional named font configured by the backend.
- class mini_arcade_core.backend.WindowProtocol[source]¶
Bases:
ProtocolRepresents a game window.
- width: int¶
- height: int¶
- resize(width: int, height: int)[source]¶
Resize the window.
- Parameters:
width (int) – New width in pixels.
height (int) – New height in pixels.