McRogueFace API Reference

Generated on 2025-07-10 01:13:53

This documentation was dynamically generated from the compiled module.

Table of Contents

Functions

createScenecreateScene(name: str) -> None

Create a new empty scene. Note:

Arguments:

createSoundBuffercreateSoundBuffer(filename: str) -> int

Load a sound effect from a file and return its buffer ID.

Arguments:

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:

Arguments:

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:

Arguments:

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.

Arguments:

Returns: list: All matching UI elements and entities

Example:

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.

Arguments:

Example:

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:

Arguments:

playSoundplaySound(buffer_id: int) -> None

Play a sound effect using a previously loaded buffer.

Arguments:

sceneUIsceneUI(scene: str = None) -> list

Get all UI elements for a scene.

Arguments:

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.

Arguments:

setScalesetScale(multiplier: float) -> None

Scale the game window size. Note:

Arguments:

setScenesetScene(scene: str, transition: str = None, duration: float = 0.0) -> None

Switch to a different scene with optional transition effect.

Arguments:

setSoundVolumesetSoundVolume(volume: int) -> None

Set the global sound effects volume.

Arguments:

setTimersetTimer(name: str, handler: callable, interval: int) -> None

Create or update a recurring timer. Note:

Arguments:

Classes

Animation

Animation object for animating UI properties

Methods:

get_current_value(...)

Get the current interpolated value

start(...)

Start the animation on a target UIDrawable

updateUpdate the animation by deltaTime (returns True if still running)

Caption

Inherits from: Drawable

Caption(text='', x=0, y=0, font=None, fill_color=None, outline_color=None, outline=0, click=None) A text display UI element with customizable font and styling. Args: text (str): The text content to display. Default: '' x (float): X position in pixels. Default: 0 y (float): Y position in pixels. Default: 0 font (Font): Font object for text rendering. Default: engine default font 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 click (callable): Click event handler. Default: None Attributes: text (str): The displayed text content x, y (float): Position in pixels font (Font): Font used for rendering fill_color, outline_color (Color): Text appearance outline (float): Outline thickness click (callable): Click event handler visible (bool): Visibility state z_index (int): Rendering order w, h (float): Read-only computed size based on text and font

Methods:

get_boundsGet bounding box as (x, y, width, height)
moveMove by relative offset (dx, dy)
resizeResize to new dimensions (width, height)

Color

SFML Color Object

Methods:

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

Drawable

Base class for all drawable UI elements

Methods:

get_boundsGet bounding box as (x, y, width, height)
moveMove by relative offset (dx, dy)
resizeResize to new dimensions (width, height)

Entity

Inherits from: Drawable

UIEntity objects

Methods:

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.

x: Target X coordinate
y: Target Y coordinate

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.

EntityCollection

Iterable, indexable collection of Entities

Methods:

append(...)
count(...)
extend(...)
index(...)
remove(...)

Font

SFML Font Object

Methods:

Frame

Inherits from: Drawable

Frame(x=0, y=0, w=0, h=0, fill_color=None, outline_color=None, outline=0, click=None, children=None) A rectangular frame UI element that can contain other drawable elements. Args: x (float): X position in pixels. Default: 0 y (float): Y position in pixels. Default: 0 w (float): Width in pixels. Default: 0 h (float): Height in pixels. Default: 0 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 Attributes: x, y (float): Position in pixels w, h (float): Size in pixels 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 z_index (int): Rendering order clip_children (bool): Whether to clip children to frame bounds

Methods:

get_boundsGet bounding box as (x, y, width, height)
moveMove by relative offset (dx, dy)
resizeResize to new dimensions (width, height)

Grid

Inherits from: Drawable

Grid(x=0, y=0, grid_size=(20, 20), texture=None, tile_width=16, tile_height=16, scale=1.0, click=None) A grid-based tilemap UI element for rendering tile-based levels and game worlds. Args: x (float): X position in pixels. Default: 0 y (float): Y position in pixels. Default: 0 grid_size (tuple): Grid dimensions as (width, height) in tiles. Default: (20, 20) texture (Texture): Texture atlas containing tile sprites. Default: None tile_width (int): Width of each tile in pixels. Default: 16 tile_height (int): Height of each tile in pixels. Default: 16 scale (float): Grid scaling factor. Default: 1.0 click (callable): Click event handler. Default: None Attributes: x, y (float): Position in pixels grid_size (tuple): Grid dimensions (width, height) in tiles tile_width, tile_height (int): Tile dimensions in pixels texture (Texture): Tile texture atlas scale (float): Scale multiplier points (list): 2D array of GridPoint objects for tile data entities (list): Collection of Entity objects in the grid background_color (Color): Grid background color click (callable): Click event handler visible (bool): Visibility state z_index (int): Rendering order

Methods:

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.

x1: Starting X coordinate
y1: Starting Y coordinate
x2: Target X coordinate
y2: Target Y coordinate
diagonal_cost: Cost of diagonal movement (default: 1.41)

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.

root_x: X coordinate of the root/target
root_y: Y coordinate of the root/target
diagonal_cost: Cost of diagonal movement (default: 1.41)
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.

x: X coordinate of the viewer
y: Y coordinate of the viewer
radius: Maximum view distance (0 = unlimited)
light_walls: Whether walls are lit when visible
algorithm: FOV algorithm to use (FOV_BASIC, FOV_DIAMOND, FOV_SHADOW, FOV_PERMISSIVE_0-8)
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.

x1: Starting X coordinate
y1: Starting Y coordinate
x2: Target X coordinate
y2: Target Y coordinate
diagonal_cost: Cost of diagonal movement (default: 1.41)

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.

x: X coordinate to query
y: Y coordinate to query

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.

x: Starting X coordinate
y: Starting Y coordinate

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.

x: X coordinate to check
y: Y coordinate to check

Returns: True if the cell is visible, False otherwise

moveMove by relative offset (dx, dy)
resizeResize to new dimensions (width, height)

GridPoint

UIGridPoint object

Methods:

GridPointState

UIGridPointState object

Methods:

Scene

Base class for object-oriented scenes

Methods:

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)

Sprite

Inherits from: Drawable

Sprite(x=0, y=0, texture=None, sprite_index=0, scale=1.0, click=None) A sprite UI element that displays a texture or portion of a texture atlas. Args: x (float): X position in pixels. Default: 0 y (float): Y position in pixels. Default: 0 texture (Texture): Texture object to display. Default: None sprite_index (int): Index into texture atlas (if applicable). Default: 0 scale (float): Sprite scaling factor. Default: 1.0 click (callable): Click event handler. Default: None Attributes: x, y (float): Position in pixels texture (Texture): The texture being displayed sprite_index (int): Current sprite index in texture atlas scale (float): Scale multiplier click (callable): Click event handler visible (bool): Visibility state z_index (int): Rendering order w, h (float): Read-only computed size based on texture and scale

Methods:

get_boundsGet bounding box as (x, y, width, height)
moveMove by relative offset (dx, dy)
resizeResize to new dimensions (width, height)

Texture

SFML Texture Object

Methods:

Timer

Timer object for scheduled callbacks

Methods:

cancel(...)

Cancel the timer and remove it from the system

pause(...)

Pause the timer

restart(...)

Restart the timer from the current time

resume(...)

Resume a paused timer

UICollection

Iterable, indexable collection of UI objects

Methods:

append(...)
count(...)
extend(...)
index(...)
remove(...)

UICollectionIter

Iterator for a collection of UI objects

Methods:

UIEntityCollectionIter

Iterator for a collection of UI objects

Methods:

Vector

SFML Vector Object

Methods:

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

Window singleton for accessing and modifying the game window properties

Methods:

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.

Constants