Rendering System¶
The rendering module provides an abstract renderer interface and Pygame implementation for visualizing the game.
Renderer Base¶
Abstract rendering interface.
This module provides the abstract renderer interface that different rendering backends can implement.
- class barebones_rpg.rendering.renderer.Color(r, g, b, a=255)[source]¶
Bases:
objectRGB color representation.
- __init__(r, g, b, a=255)¶
- class barebones_rpg.rendering.renderer.Colors[source]¶
Bases:
objectCommon color constants.
- BLACK = Color(r=0, g=0, b=0, a=255)¶
- WHITE = Color(r=255, g=255, b=255, a=255)¶
- RED = Color(r=255, g=0, b=0, a=255)¶
- GREEN = Color(r=0, g=255, b=0, a=255)¶
- BLUE = Color(r=0, g=0, b=255, a=255)¶
- YELLOW = Color(r=255, g=255, b=0, a=255)¶
- CYAN = Color(r=0, g=255, b=255, a=255)¶
- MAGENTA = Color(r=255, g=0, b=255, a=255)¶
- GRAY = Color(r=128, g=128, b=128, a=255)¶
- DARK_GRAY = Color(r=64, g=64, b=64, a=255)¶
- LIGHT_GRAY = Color(r=192, g=192, b=192, a=255)¶
- class barebones_rpg.rendering.renderer.Renderer(width, height, title='RPG Game')[source]¶
Bases:
ABCAbstract base class for renderers.
Different rendering backends (Pygame, terminal, web, etc.) implement this interface.
- abstractmethod draw_text(text, x, y, color=Color(r=255, g=255, b=255, a=255), font_size=16)[source]¶
Draw text.
- class barebones_rpg.rendering.renderer.UIElement(x, y, width, height)[source]¶
Bases:
ABCBase class for UI elements.
- class barebones_rpg.rendering.renderer.TextBox(x, y, width, height, text='', font_size=16, text_color=Color(r=255, g=255, b=255, a=255), bg_color=Color(r=0, g=0, b=0, a=255))[source]¶
Bases:
UIElementSimple text box UI element.
- __init__(x, y, width, height, text='', font_size=16, text_color=Color(r=255, g=255, b=255, a=255), bg_color=Color(r=0, g=0, b=0, a=255))[source]¶
Initialize text box.
Pygame Renderer¶
Pygame implementation of the renderer.
This provides a basic Pygame-based renderer for the framework.
- class barebones_rpg.rendering.pygame_renderer.PygameRenderer(width, height, title='RPG Game')[source]¶
Bases:
RendererPygame-based renderer implementation.
Example
>>> renderer = PygameRenderer(800, 600, "My RPG") >>> renderer.initialize() >>> renderer.clear() >>> renderer.draw_text("Hello World!", 100, 100) >>> renderer.present()
- class barebones_rpg.rendering.pygame_renderer.PygameGameLoop(game, renderer=None)[source]¶
Bases:
objectGame loop using Pygame renderer.
This integrates the Pygame renderer with the core Game class.
Example
>>> from barebones_rpg.core import Game, GameConfig >>> game = Game(GameConfig(title="My RPG")) >>> loop = PygameGameLoop(game) >>> loop.run()
- __init__(game, renderer=None)[source]¶
Initialize game loop.
- Parameters:
game (
Any) – Game instancerenderer (
Optional[PygameRenderer]) – Pygame renderer (creates default if None)
Tile Renderer¶
Tile-based rendering utilities.
This module provides rendering helpers specifically for tile-based maps, including grid rendering, entity rendering, and visual effects like movement highlights and path previews.
- class barebones_rpg.rendering.tile_renderer.TileRenderer(renderer, tile_size=32)[source]¶
Bases:
objectRenderer for tile-based maps and entities.
This class handles rendering of: - Tile grids with borders - Movement range highlights - Path previews - Hover effects - Entities on tiles - Entity HP bars
- Parameters:
- render_tile_grid(location, walkable_color=None, wall_color=None, grid_line_color=None)[source]¶
Render the tile grid for a location.
- Parameters:
- render_movement_highlights(valid_moves, current_position=None, highlight_color=None, padding=2)[source]¶
Render highlights for valid movement tiles.
- Parameters:
valid_moves (
Set[Tuple[int,int]]) – Set of valid move positionscurrent_position (
Optional[Tuple[int,int]]) – Position to exclude from highlighting (usually current position)highlight_color (
Optional[Color]) – Color for the highlight (default: blue)padding (
int) – Padding from tile edges in pixels
- render_path_preview(path, skip_first=True, path_color=None, padding=4)[source]¶
Render a path preview showing movement trajectory.
- render_entity(entity, faction_colors=None, draw_name=True, draw_hp_bar=True)[source]¶
Render an entity on a tile.
- render_entity_hp_bar(entity, bar_height=4, padding=2, bg_color=None, hp_color=None)[source]¶
Render an HP bar for an entity.
- render_location(location, valid_moves=None, path_preview=None, hover_tile=None, current_entity_position=None, draw_entity_names=True, draw_entity_hp_bars=True)[source]¶
Render a complete location with all entities and effects.
This is a convenience method that renders everything in the correct order.
- Parameters:
location (
Location) – The location to rendervalid_moves (
Optional[Set[Tuple[int,int]]]) – Set of valid move positions to highlightpath_preview (
Optional[List[Tuple[int,int]]]) – Path to previewhover_tile (
Optional[Tuple[int,int]]) – Tile being hovered overcurrent_entity_position (
Optional[Tuple[int,int]]) – Position of current entity (excluded from highlights)draw_entity_names (
bool) – Whether to draw entity namesdraw_entity_hp_bars (
bool) – Whether to draw entity HP bars
UI Components¶
Common UI components for RPG games.
This module provides reusable UI components like resource bars, turn indicators, quest displays, and instruction panels.
- class barebones_rpg.rendering.ui_components.UIComponents(renderer)[source]¶
Bases:
objectCollection of reusable UI components.
This class provides common UI elements that can be easily rendered in RPG games, such as turn indicators, resource bars, quest lists, etc.
- Parameters:
renderer (
Renderer) – The base renderer to use
- __init__(renderer)[source]¶
Initialize the UI components.
- Parameters:
renderer (
Renderer) – The base renderer to use
- render_turn_indicator(is_player_turn, position, player_text='YOUR TURN', enemy_text='ENEMY TURN', font_size=20)[source]¶
Render a turn indicator showing whose turn it is.
- render_resource_bar(label, current, maximum, position, font_size=20, text_color=None)[source]¶
Render a resource bar (HP, MP, AP, etc.).
- render_resource_bar_with_fill(label, current, maximum, position, bar_width=100, bar_height=20, font_size=16, fill_color=None, bg_color=None)[source]¶
Render a resource bar with a visual fill indicator.
- render_quest_list(quest_manager, position, max_quests=None, show_objectives=True, title='Active Quests:', title_font_size=16, quest_font_size=14, objective_font_size=12)[source]¶
Render a list of active quests with objectives.
- Parameters:
quest_manager (
QuestManager) – The quest manager containing questsmax_quests (
Optional[int]) – Maximum number of quests to show (None = all)show_objectives (
bool) – Whether to show objectivestitle (
str) – Title texttitle_font_size (
int) – Font size for the titlequest_font_size (
int) – Font size for quest namesobjective_font_size (
int) – Font size for objectives
- render_instructions(instructions, position, font_size=12, line_spacing=15, text_color=None)[source]¶
Render a list of instruction text.
- render_message_log(messages, position, max_messages=10, font_size=14, line_spacing=20, text_color=None)[source]¶
Render a message log (e.g., combat log).
- render_stat_panel(entity, position, show_name=True, show_hp=True, show_mp=True, show_atk=True, show_def=True, name_font_size=20, stat_font_size=16, line_spacing=20)[source]¶
Render a stat panel for an entity.
- Parameters:
entity (
Any) – Entity to show stats for (must have stats attribute)show_name (
bool) – Whether to show entity nameshow_hp (
bool) – Whether to show HPshow_mp (
bool) – Whether to show MPshow_atk (
bool) – Whether to show attackshow_def (
bool) – Whether to show defensename_font_size (
int) – Font size for the namestat_font_size (
int) – Font size for statsline_spacing (
int) – Spacing between lines
- render_title_screen_text(title, position, font_size=32, color=None)[source]¶
Render large title text.
- render_button(text, position, width, height, is_hovered=False, bg_color=None, hover_color=None, text_color=None, font_size=16)[source]¶
Render a button with hover effect.
- Parameters:
text (
str) – Button textwidth (
int) – Button widthheight (
int) – Button heightis_hovered (
bool) – Whether the button is being hoveredbg_color (
Optional[Color]) – Background color (default: dark gray)hover_color (
Optional[Color]) – Hover background color (default: lighter gray)font_size (
int) – Font size for the text
Click to Move¶
Click-to-move handler for tile-based games.
This module provides an input handler for click-based movement on tile maps, including hover effects, path previews, and click handling.
- class barebones_rpg.rendering.click_to_move.ClickToMoveHandler(tile_size, grid_width, grid_height, pathfinder=None)[source]¶
Bases:
objectHandler for click-to-move input on tile-based maps.
This class manages: - Mouse hover tracking - Path preview calculation - Click detection and tile selection - Callbacks for movement and interaction
- Parameters:
tile_size (
int) – Size of each tile in pixelsgrid_width (
int) – Width of the grid in tilesgrid_height (
int) – Height of the grid in tilespathfinder (
Optional[TilemapPathfinder]) – Optional pathfinder for path previews
- __init__(tile_size, grid_width, grid_height, pathfinder=None)[source]¶
Initialize the click-to-move handler.
- Parameters:
tile_size (
int) – Size of each tile in pixelsgrid_width (
int) – Width of the grid in tilesgrid_height (
int) – Height of the grid in tilespathfinder (
Optional[TilemapPathfinder]) – Optional pathfinder for path previews
- set_pathfinder(pathfinder)[source]¶
Set or update the pathfinder for path previews.
- Parameters:
pathfinder (
TilemapPathfinder) – The pathfinder to use
- handle_mouse_motion(event, valid_moves=None, current_position=None)[source]¶
Handle mouse motion events to update hover and path preview.
- class barebones_rpg.rendering.click_to_move.TileInteractionHandler(click_handler)[source]¶
Bases:
objectHigher-level handler for tile-based interactions.
This combines ClickToMoveHandler with logic for handling different types of interactions (movement, attacking, talking to NPCs, etc.)
- Parameters:
click_handler (
ClickToMoveHandler) – The click-to-move handler to use
- __init__(click_handler)[source]¶
Initialize the interaction handler.
- Parameters:
click_handler (
ClickToMoveHandler) – The click-to-move handler to use
- handle_tile_click(tile_pos, entity_at_tile, valid_moves)[source]¶
Handle a tile click with interaction logic.
- set_callbacks(on_move=None, on_attack_enemy=None, on_interact_npc=None, on_interact_item=None)[source]¶
Set interaction callbacks.
- Parameters:
on_move (
Optional[Callable[[Tuple[int,int]],None]]) – Callback when player moves to a tileon_attack_enemy (
Optional[Callable[[Any],None]]) – Callback when player attacks an enemyon_interact_npc (
Optional[Callable[[Any],None]]) – Callback when player interacts with NPCon_interact_item (
Optional[Callable[[Any],None]]) – Callback when player interacts with item