Skip to main content

Module engine

Module engine 

Source
Expand description

Engine core: Context, game loop, and window configuration.

§Why game-gem > macroquad (architecture)

Featuremacroquadgame-gem
Entry point#[macroquad::main] proc macroPlain fn main() + Game::run()
State managementGlobal variablesTrait-based GameState
Error handlingPanicsResult types
Context passingGlobal functionsExplicit &mut Context parameter
ModularityAll-or-nothingFeature-gated modules
Multiple windowsNoPlanned
Custom game loopNoFixed timestep, variable, or custom

§Minimal example

use game_gem::prelude::*;

struct MyGame;

impl GameState for MyGame {
    fn update(&mut self, ctx: &mut Context) {
        if ctx.input.keyboard.is_pressed(KeyCode::Escape) {
            ctx.quit();
        }
    }
    fn render(&mut self, ctx: &mut Context) {
        ctx.graphics.clear(Color::SKY_BLUE);
        ctx.graphics.draw_circle(ctx, 400.0, 300.0, 50.0, Color::RED);
    }
}

fn main() {
    Game::new()
        .window_title("My Game")
        .window_size(800, 600)
        .run(MyGame);
}

Structs§

Context
The main context object passed to all game state methods.
Game
The game builder. Configure your game and run it.
GraphicsContext
Graphics context that collects draw commands.
WindowConfig
Window configuration builder.

Enums§

DrawCommand
Drawing operations that the game can issue each frame.

Traits§

GameState
The main game state trait. Implement this for your game.