Welcome to McRogueFace! This guide will help you get up and running with your first game.
Before installing McRogueFace, ensure you have:
# Install dependencies (Ubuntu/Debian)
sudo apt-get update
sudo apt-get install build-essential cmake git libsfml-dev python3.12-dev
# Clone the repository
git clone https://github.com/jmcb/McRogueFace.git
cd McRogueFace
# Build the project
make
# Run the example game
cd build
./mcrogueface
# Clone the repository
git clone https://github.com/jmcb/McRogueFace.git
cd McRogueFace
# Build with CMake
mkdir build
cd build
cmake ..
cmake --build .
# Run the example game
mcrogueface.exe
Let’s create a simple “Hello World” game to understand the basics.
Create a new file scripts/hello_game.py
in your build directory:
import mcrfpy
# Create a new scene
mcrfpy.createScene("main")
# Create a title
title = mcrfpy.Caption(400, 100, "Hello McRogueFace!")
title.font = mcrfpy.default_font
title.font_size = 32
title.font_color = (255, 255, 255) # White
title.centered = True
# Create instructions
instructions = mcrfpy.Caption(400, 200, "Press ESC to exit")
instructions.font = mcrfpy.default_font
instructions.font_size = 18
instructions.font_color = (200, 200, 200) # Light gray
instructions.centered = True
# Add a background frame
background = mcrfpy.Frame(200, 50, 400, 200)
background.bgcolor = (64, 64, 128) # Blue-gray
background.outline = 2
# Add elements to the scene
ui = mcrfpy.sceneUI("main")
ui.append(background)
ui.append(title)
ui.append(instructions)
# Handle keyboard input
def handle_keys(key):
if key == "Escape":
mcrfpy.exit()
print(f"Key pressed: {key}")
# Register the keyboard handler
mcrfpy.keypressScene(handle_keys)
# Switch to our scene
mcrfpy.setScene("main")
./mcrogueface
Your game should display a window with a blue-gray background, white title text, and respond to the ESC key.
Scenes are containers for your game states (menu, gameplay, game over, etc.):
# Create scenes
mcrfpy.createScene("menu")
mcrfpy.createScene("game")
mcrfpy.createScene("gameover")
# Switch between scenes
mcrfpy.setScene("menu") # Show the menu
McRogueFace provides several UI element types:
text = mcrfpy.Caption(x, y, "Your text here")
text.font = mcrfpy.default_font
text.font_size = 24
text.font_color = (255, 255, 255) # RGB
text.centered = True # Center on x,y position
# Load a texture (sprite sheet)
texture = mcrfpy.Texture("assets/sprites.png", 16, 16) # 16x16 tiles
# Create a sprite
sprite = mcrfpy.Sprite(x, y)
sprite.texture = texture
sprite.sprite_index = 0 # Which tile to show
sprite.scale = (2.0, 2.0) # Make it bigger
frame = mcrfpy.Frame(x, y, width, height)
frame.bgcolor = (50, 50, 50) # Dark gray
frame.outline = 2 # 2-pixel border
frame.outline_color = (255, 255, 255) # White border
# Create a 20x15 grid of 32x32 pixel tiles
grid = mcrfpy.Grid(x, y, 20, 15, texture, 32, 32)
# Set individual tiles
grid.set_tile(tile_x, tile_y, sprite_index)
Handle keyboard input with callback functions:
def on_keypress(key):
if key == "w" or key == "Up":
# Move up
pass
elif key == "s" or key == "Down":
# Move down
pass
elif key == "Space":
# Action
pass
mcrfpy.keypressScene(on_keypress)
Create game loops using timers:
def game_update(runtime):
# This runs every 100ms
# Update game logic here
player.move()
check_collisions()
# Set a timer to call game_update every 100ms
mcrfpy.setTimer("gameloop", game_update, 100)
# Stop the timer
mcrfpy.delTimer("gameloop")
Now that you understand the basics:
src/scripts/
build
directoryassets/
directoryHappy game development with McRogueFace!