Code-Reference
- class core.Core(title='GameCore <3', size=(480, 480), update=None, start=None, fixed_update=None, background_color=(0, 0, 0, 0), fps=30, display=0, window_flags=pygame.DOUBLEBUF, window_depth=32)
Main game framework for managing the game loop, rendering, and engines.
- Variables:
window – main draw surface.
window_size – (X,Y) Dimensions of the game window.
background_color – Background color of the game window.
is_running – Indicates if the game is running.
locked_fps – Target frames per second for the game loop.
- __init__(title='GameCore <3', size=(480, 480), update=None, start=None, fixed_update=None, background_color=(0, 0, 0, 0), fps=30, display=0, window_flags=pygame.DOUBLEBUF, window_depth=32)
Initializes the Core framework.
- Parameters:
title (str) – Title of the game window.
size (tuple) – Dimensions of the game window.
update (callable) – Update function for the game loop.
start (callable) – Start function executed at the beginning.
fixed_update (callable) – Function executed at fixed intervals.
background_color (tuple) – Background color of the window.
fps (int) – Target frames per second.
display (int) – Display index for the game window.
window_flags (int) – Pygame flags for the window.
window_depth (int) – Bit depth for the window.
- get_layer_surface(name)
Retrieves the surface associated with a specific layer by its name.
- Parameters:
name (str) – The name of the layer whose surface is to be retrieved.
- Returns:
The surface object of the specified layer.
- Return type:
pygame.Surface
- remove_layer_surface(name)
Removes a layer and its associated surface by name.
- Parameters:
name (str) – The name of the layer to remove.
- move_layer_surface(name, position)
Updates the position of an existing layer’s surface.
- Parameters:
name (str) – The name of the layer whose surface position is to be updated.
position (tuple[int, int]) – The new top-left position of the surface in (x, y) coordinates.
- create_layer_surface(name=None, width=0, height=0, x=0, y=0, render_layer: int = 0, fill_after_draw=True)
Creates a new rendering layer surface.
- Parameters:
name (str) – Name of the surface.
width (int) – Width of the surface.
height (int) – Height of the surface.
x (int) – X-coordinate of the surface.
y (int) – Y-coordinate of the surface.
render_layer (int) – Rendering order of the surface.
fill_after_draw (bool) – Auto-fill the surface after drawing.
- Returns:
The created surface.
- Return type:
pygame.Surface
- create_surface(size=None)
Creates a new surface with specified dimensions.
- Parameters:
size (tuple[int, int], optional) – The size of the surface as a (width, height) tuple. Defaults to the size of the main window if not specified.
- Returns:
A new surface object with the specified or default size.
- Return type:
pygame.Surface
- draw_surface(surface, position=None)
Draws a surface onto the main window at a specified position.
- Parameters:
surface (pygame.Surface) – The surface to draw.
position (tuple[int, int], optional) – The top-left position where the surface will be drawn, specified as a (x, y) tuple. Defaults to (0, 0).
- get_engine_by_class(searchClass)
Finds and returns the first engine of a specific class type.
- Parameters:
searchClass (type) – The class type of the engine to search for.
- Returns:
The first engine instance matching the specified class type, or None if no match is found.
- Return type:
Engine or None
- Raises:
TypeError – If the provided searchClass is not a class.
- get_engines_by_class(searchClass)
Retrieves all engines of a specific class type.
- Parameters:
searchClass (type) – The class type of engines to search for.
- Returns:
A list of all engines matching the specified class type.
- Return type:
list[Engine]
- Raises:
TypeError – If the provided searchClass is not a class.
- __weakref__
list of weak references to the object (if defined)
- instantiate(engine, **kwargs)
Creates and initializes a new instance of an engine class at runtime. This method is particularly suitable for creating prefabs, which are reusable templates for engines.
- Parameters:
engine (type) – The engine class to instantiate. Must be a subclass of Engine.
kwargs – Optional parameters to pass to the engine’s awake method.
- Returns:
The instantiated and initialized engine instance.
- Return type:
- Raises:
TypeError – If the provided engine is not a subclass of Engine.
- class core.Coroutine(func, interval=None, loop_condition=<function Coroutine.<lambda>>, call_delay=None, func_args=None, func_kwargs=None)
Represents a coroutine that periodically executes a function.
- Variables:
is_dead – Indicates whether the coroutine is inactive.
- __init__(func, interval=None, loop_condition=<function Coroutine.<lambda>>, call_delay=None, func_args=None, func_kwargs=None)
Initializes the Coroutine.
- Parameters:
func (callable) – The function to execute periodically. The function can update the ‘interval’, ‘func_args’, and ‘func_kwargs’ by returning them in a dictionary.
interval (float) – The time interval (in milliseconds) between executions.
loop_condition (callable) – A function returning a boolean that determines if the coroutine should continue.
call_delay (float) – Initial delay before the first execution (in milliseconds).
func_args (tuple) – Positional arguments to pass to func.
func_kwargs (dict) – Keyword arguments to pass to func.
- __weakref__
list of weak references to the object (if defined)
- class core.Engine(core)
Represents a game engine responsible for managing coroutines and state machines.
- Variables:
core – Reference to the Core instance managing the game loop.
is_enabled – Indicates whether the engine is active.
priority_layer – Determines the order of engine execution.
state_machines – List of state machines managed by the engine.
- __init__(core)
Initializes the Engine.
- Parameters:
core (Core) – The Core instance managing the game loop.
- enable(**kwargs)
Enables the engine and triggers related events.
- Parameters:
kwargs (dict) – Additional data passed to the on_enable method.
- disable()
Disables the engine and triggers related events.
- start_func_as_coroutine(func, **kwargs)
Starts a function as a coroutine.
- Parameters:
func (callable) – The function to execute as a coroutine.
kwargs (dict) – Arguments for the coroutine, including interval, call_delay, and all other parameters of the Coroutine class.
- start_coroutine(coroutine)
Adds a Coroutine instance to the list of active coroutines.
- Parameters:
coroutine (Coroutine) – The Coroutine instance to start.
- start_coroutines(coroutines)
Adds multiple Coroutine instances to the list of active coroutines.
- Parameters:
coroutines (list) – List of Coroutine instances to start.
- awake(**kwargs)
Called once at the beginning of the engine’s lifecycle for initialization.
- Parameters:
kwargs (dict) – Optional arguments for initialization.
- on_enable(inject=None)
Called when the engine is enabled.
- Parameters:
inject (dict) – Optional data to inject during enabling.
- on_disable()
Called when the engine is disabled.
- start()
Called when the engine starts.
- update()
Called continuously during the game loop.
- fixed_update()
Called at fixed intervals during the game loop.
- on_destroy()
Called before the engine is destroyed.
- __weakref__
list of weak references to the object (if defined)
- class core.Prefab
Base class for engine-related components, preventing immediate execution.
- __weakref__
list of weak references to the object (if defined)
- class core.SurfaceStack
Manages a stack of rendering surfaces for organized layer-based rendering.
- __init__()
Initializes a SurfaceStack.
- add_element(name, surface, render_layer: int, surface_render_position: tuple, fill_after_draw=True)
Adds a new surface element to the stack.
- Parameters:
name (str) – Unique name for the surface.
surface (pygame.Surface) – The surface to add.
render_layer (int) – The rendering order.
surface_render_position (tuple) – Position of the surface in the window.
fill_after_draw (bool) – Indicates if the surface should auto-fill after rendering.
- remove_element(name)
Removes a surface element from the stack.
- Parameters:
name (str) – Name of the surface to remove.
- get_surface(name)
Retrieves a surface by name.
- Parameters:
name (str) – Name of the surface.
- Returns:
The requested surface.
- Return type:
pygame.Surface
- get_element(name)
Retrieves a SurfaceStackElement by name.
- Parameters:
name (str) – Name of the element.
- Returns:
The requested element.
- Return type:
SurfaceStackElement:
- draw(core)
Draws all surfaces in the stack.
- Parameters:
core (Core) – Reference to the Core instance for rendering.
- print()
Prints information about all surfaces in the stack.
- __weakref__
list of weak references to the object (if defined)
- class core.SurfaceStackElement
Represents an individual element in a stack of rendering surfaces.
- Variables:
name – Name identifier for the surface.
surface – The surface object to render.
render_layer – The rendering order for the surface.
surface_render_position – Position of the surface in the window.
auto_fill – Indicates if the surface should auto-fill after rendering.
- __init__()
Initializes a SurfaceStackElement.
- print()
Prints information about the surface element.
- __weakref__
list of weak references to the object (if defined)
- class core.sprite.Slicer
Base class for slicing a surface into smaller sections. Provides a generic interface for subclasses to implement specific slicing behavior.
- slice(surface: pygame.Surface)
Placeholder function, returns the input surface without modification.
- Parameters:
surface – A pygame.Surface object to be sliced.
- Returns:
The original surface.
- __weakref__
list of weak references to the object (if defined)