Generated on 2025-07-15 21:28:24
This documentation was dynamically generated from the compiled module.
createScenecreateScene(name: str) -> None
Create a new empty scene. Note:
createSoundBuffercreateSoundBuffer(filename: str) -> int
Load a sound effect from a file and return its buffer ID.
Returns: int: Buffer ID for use with playSound() RuntimeError: If the file cannot be loaded
currentScenecurrentScene() -> str
Get the name of the currently active scene.
Returns: str: Name of the current scene
delTimerdelTimer(name: str) -> None
Stop and remove a timer. Note:
exitexit() -> None
Cleanly shut down the game engine and exit the application. Note:
findfind(name: str, scene: str = None) -> UIDrawable | None
Find the first UI element with the specified name. Note:
Returns: Frame, Caption, Sprite, Grid, or Entity if found; None otherwise Searches scene UI elements and entities within grids.
findAllfindAll(pattern: str, scene: str = None) -> list
Find all UI elements matching a name pattern.
Returns: list: All matching UI elements and entities
findAll('enemy*') # Find all elements starting with 'enemy'
findAll('*_button') # Find all elements ending with '_button'
getMetricsgetMetrics() -> dict
Get current performance metrics.
Returns: dict: Performance data with keys: - frame_time: Last frame duration in seconds - avg_frame_time: Average frame time - fps: Frames per second - draw_calls: Number of draw calls - ui_elements: Total UI element count - visible_elements: Visible element count - current_frame: Frame counter - runtime: Total runtime in seconds
getMusicVolumegetMusicVolume() -> int
Get the current music volume level.
Returns: int: Current volume (0-100)
getSoundVolumegetSoundVolume() -> int
Get the current sound effects volume level.
Returns: int: Current volume (0-100)
keypressScenekeypressScene(handler: callable) -> None
Set the keyboard event handler for the current scene.
def on_key(key, pressed):
if key == 'A' and pressed:
print('A key pressed')
mcrfpy.keypressScene(on_key)
loadMusicloadMusic(filename: str) -> None
Load and immediately play background music from a file. Note:
playSoundplaySound(buffer_id: int) -> None
Play a sound effect using a previously loaded buffer.
sceneUIsceneUI(scene: str = None) -> list
Get all UI elements for a scene.
Returns: list: All UI elements (Frame, Caption, Sprite, Grid) in the scene KeyError: If the specified scene doesn't exist
setMusicVolumesetMusicVolume(volume: int) -> None
Set the global music volume.
setScalesetScale(multiplier: float) -> None
Scale the game window size. Note:
setScenesetScene(scene: str, transition: str = None, duration: float = 0.0) -> None
Switch to a different scene with optional transition effect.
setSoundVolumesetSoundVolume(volume: int) -> None
Set the global sound effects volume.
setTimersetTimer(name: str, handler: callable, interval: int) -> None
Create or update a recurring timer. Note:
Animation object for animating UI properties
completecomplete() -> None
Complete the animation immediately by jumping to the final value.
get_current_value(...)
Get the current interpolated value
hasValidTargethasValidTarget() -> bool
Check if the animation still has a valid target.
Returns: True if the target still exists, False if it was destroyed.
startstart(target) -> None
Start the animation on a target UI element. Note:
updateUpdate the animation by deltaTime (returns True if still running)
Inherits from: Drawable
Caption(pos=None, font=None, text='', **kwargs) A text display UI element with customizable font and styling. Args: pos (tuple, optional): Position as (x, y) tuple. Default: (0, 0) font (Font, optional): Font object for text rendering. Default: engine default font text (str, optional): The text content to display. Default: '' Keyword Args: fill_color (Color): Text fill color. Default: (255, 255, 255, 255) outline_color (Color): Text outline color. Default: (0, 0, 0, 255) outline (float): Text outline thickness. Default: 0 font_size (float): Font size in points. Default: 16 click (callable): Click event handler. Default: None visible (bool): Visibility state. Default: True opacity (float): Opacity (0.0-1.0). Default: 1.0 z_index (int): Rendering order. Default: 0 name (str): Element name for finding. Default: None x (float): X position override. Default: 0 y (float): Y position override. Default: 0 Attributes: text (str): The displayed text content x, y (float): Position in pixels pos (Vector): Position as a Vector object font (Font): Font used for rendering font_size (float): Font size in points fill_color, outline_color (Color): Text appearance outline (float): Outline thickness click (callable): Click event handler visible (bool): Visibility state opacity (float): Opacity value z_index (int): Rendering order name (str): Element name w, h (float): Read-only computed size based on text and font
get_boundsGet bounding box as (x, y, width, height)
moveMove by relative offset (dx, dy)
resizeResize to new dimensions (width, height)
SFML Color Object
from_hexCreate Color from hex string (e.g., '#FF0000' or 'FF0000')
lerp(...)
Linearly interpolate between this color and another
to_hex(...)
Convert Color to hex string
Base class for all drawable UI elements
get_boundsGet bounding box as (x, y, width, height)
moveMove by relative offset (dx, dy)
resizeResize to new dimensions (width, height)
Entity(grid_pos=None, texture=None, sprite_index=0, **kwargs) A game entity that exists on a grid with sprite rendering. Args: grid_pos (tuple, optional): Grid position as (x, y) tuple. Default: (0, 0) texture (Texture, optional): Texture object for sprite. Default: default texture sprite_index (int, optional): Index into texture atlas. Default: 0 Keyword Args: grid (Grid): Grid to attach entity to. Default: None visible (bool): Visibility state. Default: True opacity (float): Opacity (0.0-1.0). Default: 1.0 name (str): Element name for finding. Default: None x (float): X grid position override. Default: 0 y (float): Y grid position override. Default: 0 Attributes: pos (tuple): Grid position as (x, y) tuple x, y (float): Grid position coordinates draw_pos (tuple): Pixel position for rendering gridstate (GridPointState): Visibility state for grid points sprite_index (int): Current sprite index visible (bool): Visibility state opacity (float): Opacity value name (str): Element name
at(...)
die(...)
Remove this entity from its grid
get_boundsGet bounding box as (x, y, width, height)
index(...)
Return the index of this entity in its grid's entity collection
moveMove by relative offset (dx, dy)
path_topath_to(x: int, y: int) -> bool
Find and follow path to target position using A* pathfinding.
Returns: True if a path was found and the entity started moving, False otherwise
resizeResize to new dimensions (width, height)
update_visibilityupdate_visibility() -> None
Update entity's visibility state based on current FOV. Recomputes which cells are visible from the entity's position and updates the entity's gridstate to track explored areas. This is called automatically when the entity moves if it has a grid with perspective set.
Iterable, indexable collection of Entities
append(...)
count(...)
extend(...)
index(...)
remove(...)
SFML Font Object
Inherits from: Drawable
Frame(pos=None, size=None, **kwargs) A rectangular frame UI element that can contain other drawable elements. Args: pos (tuple, optional): Position as (x, y) tuple. Default: (0, 0) size (tuple, optional): Size as (width, height) tuple. Default: (0, 0) Keyword Args: fill_color (Color): Background fill color. Default: (0, 0, 0, 128) outline_color (Color): Border outline color. Default: (255, 255, 255, 255) outline (float): Border outline thickness. Default: 0 click (callable): Click event handler. Default: None children (list): Initial list of child drawable elements. Default: None visible (bool): Visibility state. Default: True opacity (float): Opacity (0.0-1.0). Default: 1.0 z_index (int): Rendering order. Default: 0 name (str): Element name for finding. Default: None x (float): X position override. Default: 0 y (float): Y position override. Default: 0 w (float): Width override. Default: 0 h (float): Height override. Default: 0 clip_children (bool): Whether to clip children to frame bounds. Default: False Attributes: x, y (float): Position in pixels w, h (float): Size in pixels pos (Vector): Position as a Vector object fill_color, outline_color (Color): Visual appearance outline (float): Border thickness click (callable): Click event handler children (list): Collection of child drawable elements visible (bool): Visibility state opacity (float): Opacity value z_index (int): Rendering order name (str): Element name clip_children (bool): Whether to clip children to frame bounds
get_boundsGet bounding box as (x, y, width, height)
moveMove by relative offset (dx, dy)
resizeResize to new dimensions (width, height)
Inherits from: Drawable
Grid(pos=None, size=None, grid_size=None, texture=None, **kwargs) A grid-based UI element for tile-based rendering and entity management. Args: pos (tuple, optional): Position as (x, y) tuple. Default: (0, 0) size (tuple, optional): Size as (width, height) tuple. Default: auto-calculated from grid_size grid_size (tuple, optional): Grid dimensions as (grid_x, grid_y) tuple. Default: (2, 2) texture (Texture, optional): Texture containing tile sprites. Default: default texture Keyword Args: fill_color (Color): Background fill color. Default: None click (callable): Click event handler. Default: None center_x (float): X coordinate of center point. Default: 0 center_y (float): Y coordinate of center point. Default: 0 zoom (float): Zoom level for rendering. Default: 1.0 perspective (int): Entity perspective index (-1 for omniscient). Default: -1 visible (bool): Visibility state. Default: True opacity (float): Opacity (0.0-1.0). Default: 1.0 z_index (int): Rendering order. Default: 0 name (str): Element name for finding. Default: None x (float): X position override. Default: 0 y (float): Y position override. Default: 0 w (float): Width override. Default: auto-calculated h (float): Height override. Default: auto-calculated grid_x (int): Grid width override. Default: 2 grid_y (int): Grid height override. Default: 2 Attributes: x, y (float): Position in pixels w, h (float): Size in pixels pos (Vector): Position as a Vector object size (tuple): Size as (width, height) tuple center (tuple): Center point as (x, y) tuple center_x, center_y (float): Center point coordinates zoom (float): Zoom level for rendering grid_size (tuple): Grid dimensions (width, height) in tiles grid_x, grid_y (int): Grid dimensions texture (Texture): Tile texture atlas fill_color (Color): Background color entities (EntityCollection): Collection of entities in the grid perspective (int): Entity perspective index click (callable): Click event handler visible (bool): Visibility state opacity (float): Opacity value z_index (int): Rendering order name (str): Element name
at(...)
compute_astar_pathcompute_astar_path(x1: int, y1: int, x2: int, y2: int, diagonal_cost: float = 1.41) -> List[Tuple[int, int]]
Compute A* path between two points.
Returns: List of (x, y) tuples representing the path, empty list if no path exists
compute_dijkstracompute_dijkstra(root_x: int, root_y: int, diagonal_cost: float = 1.41) -> None
Compute Dijkstra map from root position.
compute_fovcompute_fov(x: int, y: int, radius: int = 0, light_walls: bool = True, algorithm: int = FOV_BASIC) -> None
Compute field of view from a position.
find_pathfind_path(x1: int, y1: int, x2: int, y2: int, diagonal_cost: float = 1.41) -> List[Tuple[int, int]]
Find A* path between two points.
Returns: List of (x, y) tuples representing the path, empty list if no path exists
get_boundsGet bounding box as (x, y, width, height)
get_dijkstra_distanceget_dijkstra_distance(x: int, y: int) -> Optional[float]
Get distance from Dijkstra root to position.
Returns: Distance as float, or None if position is unreachable or invalid
get_dijkstra_pathget_dijkstra_path(x: int, y: int) -> List[Tuple[int, int]]
Get path from position to Dijkstra root.
Returns: List of (x, y) tuples representing path to root, empty if unreachable
is_in_fovis_in_fov(x: int, y: int) -> bool
Check if a cell is in the field of view.
Returns: True if the cell is visible, False otherwise
moveMove by relative offset (dx, dy)
resizeResize to new dimensions (width, height)
UIGridPoint object
UIGridPointState object
Base class for object-oriented scenes
activate(...)
Make this the active scene
get_ui(...)
Get the UI element collection for this scene
register_keyboardRegister a keyboard handler function (alternative to overriding on_keypress)
Inherits from: Drawable
Sprite(pos=None, texture=None, sprite_index=0, **kwargs) A sprite UI element that displays a texture or portion of a texture atlas. Args: pos (tuple, optional): Position as (x, y) tuple. Default: (0, 0) texture (Texture, optional): Texture object to display. Default: default texture sprite_index (int, optional): Index into texture atlas. Default: 0 Keyword Args: scale (float): Uniform scale factor. Default: 1.0 scale_x (float): Horizontal scale factor. Default: 1.0 scale_y (float): Vertical scale factor. Default: 1.0 click (callable): Click event handler. Default: None visible (bool): Visibility state. Default: True opacity (float): Opacity (0.0-1.0). Default: 1.0 z_index (int): Rendering order. Default: 0 name (str): Element name for finding. Default: None x (float): X position override. Default: 0 y (float): Y position override. Default: 0 Attributes: x, y (float): Position in pixels pos (Vector): Position as a Vector object texture (Texture): The texture being displayed sprite_index (int): Current sprite index in texture atlas scale (float): Uniform scale factor scale_x, scale_y (float): Individual scale factors click (callable): Click event handler visible (bool): Visibility state opacity (float): Opacity value z_index (int): Rendering order name (str): Element name w, h (float): Read-only computed size based on texture and scale
get_boundsGet bounding box as (x, y, width, height)
moveMove by relative offset (dx, dy)
resizeResize to new dimensions (width, height)
SFML Texture Object
Timer(name, callback, interval, once=False) Create a timer that calls a function at regular intervals. Args: name (str): Unique identifier for the timer callback (callable): Function to call - receives (timer, runtime) args interval (int): Time between calls in milliseconds once (bool): If True, timer stops after first call. Default: False Attributes: interval (int): Time between calls in milliseconds remaining (int): Time until next call in milliseconds (read-only) paused (bool): Whether timer is paused (read-only) active (bool): Whether timer is active and not paused (read-only) callback (callable): The callback function once (bool): Whether timer stops after firing once Methods: pause(): Pause the timer, preserving time remaining resume(): Resume a paused timer cancel(): Stop and remove the timer restart(): Reset timer to start from beginning Example: def on_timer(timer, runtime): print(f'Timer {timer} fired at {runtime}ms') if runtime > 5000: timer.cancel() timer = mcrfpy.Timer('my_timer', on_timer, 1000) timer.pause() # Pause timer timer.resume() # Resume timer timer.once = True # Make it one-shot
cancelcancel() -> None
Cancel the timer and remove it from the timer system. The timer will no longer fire and cannot be restarted.
pausepause() -> None
Pause the timer, preserving the time remaining until next trigger. The timer can be resumed later with resume().
restartrestart() -> None
Restart the timer from the beginning. Resets the timer to fire after a full interval from now.
resumeresume() -> None
Resume a paused timer from where it left off. Has no effect if the timer is not paused.
Iterable, indexable collection of UI objects
append(...)
count(...)
extend(...)
index(...)
remove(...)
Iterator for a collection of UI objects
Iterator for a collection of UI objects
SFML Vector Object
angle(...)
Return the angle in radians from the positive X axis
copy(...)
Return a copy of this vector
distance_to(...)
Return the distance to another vector
dot(...)
Return the dot product with another vector
magnitude(...)
Return the length of the vector
magnitude_squared(...)
Return the squared length of the vector
normalize(...)
Return a unit vector in the same direction
Window singleton for accessing and modifying the game window properties
center(...)
Center the window on the screen
get(...)
Get the Window singleton instance
screenshot(...)
Take a screenshot. Pass filename to save to file, or get raw bytes if no filename.
FOV_BASIC
(int): 0FOV_DIAMOND
(int): 1FOV_PERMISSIVE_0
(int): 3FOV_PERMISSIVE_1
(int): 4FOV_PERMISSIVE_2
(int): 5FOV_PERMISSIVE_3
(int): 6FOV_PERMISSIVE_4
(int): 7FOV_PERMISSIVE_5
(int): 8FOV_PERMISSIVE_6
(int): 9FOV_PERMISSIVE_7
(int): 10FOV_PERMISSIVE_8
(int): 11FOV_RESTRICTIVE
(int): 12FOV_SHADOW
(int): 2