Skip to content

Overview

NtinosTheGamer2324 edited this page Mar 7, 2026 · 1 revision

Blit Engine - 2D Game Framework

Blit Engine is a complete 2D game development framework for ModuOS, built on top of NodGL.

🎮 What is Blit?

Blit is a high-level game framework that makes creating 2D games easy:

  • 🎨 Entity/Sprite System - Manage game objects easily
  • 🕹️ Input Handling - Simple keyboard and mouse support
  • 💥 Collision Detection - Built-in collision helpers
  • 🧮 Math Utilities - Random numbers, distance, clamping
  • GPU Accelerated - Uses NodGL for fast rendering

📍 Location

Blit Engine is located in the EXTERNAL/ directory as an independent project:

EXTERNAL/Blit/
├── include/          - Header files (Blit.h, BlitStudio.h)
├── src/              - Engine source code
├── tools/            - BlitStudio visual editor
├── examples/         - Example games
├── docs/             - Complete documentation
├── build/            - Build output
├── Makefile          - Build system
└── build.sh          - Build script

🚀 Quick Start

Build Blit Engine

cd EXTERNAL/Blit
./build.sh all

This builds:

  • libBlit.a - The engine library
  • blitstudio.sqr - Visual level editor
  • 4 example games - Shooter, Pong, Platformer, Breakout

Install to System

./build.sh install

Installs Blit system-wide for use in all projects.

Your First Game

#include "Blit.h"
#include "libc.h"

int md_main(long argc, char **argv) {
    BlitEngine engine;
    blit_init(&engine);
    
    Sprite *player = blit_sprite_create_circle(&engine, 16, 0xFF00FF00);
    int x = 100, y = 100;
    
    while (blit_is_running(&engine)) {
        blit_update_input(&engine);
        
        if (blit_key_down(&engine, KEY_W)) y -= 3;
        if (blit_key_down(&engine, KEY_S)) y += 3;
        if (blit_key_down(&engine, KEY_A)) x -= 3;
        if (blit_key_down(&engine, KEY_D)) x += 3;
        
        blit_begin_frame(&engine, 0xFF000000);
        blit_sprite_draw(&engine, player, x, y);
        blit_end_frame(&engine);
    }
    
    blit_sprite_free(&engine, player);
    blit_shutdown(&engine);
    return 0;
}

Compile Your Game

# After installation
gcc -I include -c mygame.c -o mygame.o
ld -T userland/user.ld mygame.o userland/libBlit.a \
   userland/lib_NodGL.a userland/libc.a -o mygame.sqr

# Or directly from EXTERNAL
gcc -I EXTERNAL/Blit/include -I include -c mygame.c -o mygame.o
ld -T userland/user.ld mygame.o EXTERNAL/Blit/build/libBlit.a \
   userland/lib_NodGL.a userland/libc.a -o mygame.sqr

🛠️ BlitStudio - Visual Editor

BlitStudio is a visual level editor for creating games without code!

Running BlitStudio

cd EXTERNAL/Blit/build
./blitstudio.sqr

Features

  • Visual Editing - Click to place, drag to move objects
  • Grid System - Snap objects to grid for perfect alignment
  • Multiple Modes - SELECT, ENTITY, COLLISION, TEST
  • Save/Load - Persistent level files
  • Export Code - Generate C code from levels

Controls

Key Action
TAB Cycle modes
F1 Toggle help
G Toggle grid
Ctrl+S Save level
Ctrl+O Load level
Ctrl+E Export as C
DELETE Delete selected
ESC Exit

📚 Documentation

Complete documentation is in EXTERNAL/Blit/docs/:

Core Documentation

Detailed Guides

BlitStudio

🎮 Example Games

Four complete example games included:

Shooter (shooter.sqr)

Space shooter with bullets, enemies, and scoring.

Pong (pong.sqr)

Classic pong - player vs CPU with AI.

Platformer (platformer.sqr)

Jump and run game with platforms and coins.

Breakout (breakout.sqr)

Brick-breaking paddle game.

All source code in EXTERNAL/Blit/examples/

🔧 API Overview

Engine Core

blit_init(&engine);              // Initialize
blit_shutdown(&engine);          // Cleanup
blit_update_input(&engine);      // Update input
blit_begin_frame(&engine, color); // Start frame
blit_end_frame(&engine);         // Present frame
blit_is_running(&engine);        // Check if running

Sprites

Sprite* blit_sprite_create_color(&engine, w, h, color);
Sprite* blit_sprite_create_circle(&engine, radius, color);
Sprite* blit_sprite_create(&engine, w, h, pixels);
void blit_sprite_draw(&engine, sprite, x, y);
void blit_sprite_free(&engine, sprite);

Entities

Entity* blit_entity_create(x, y, w, h, sprite);
void blit_entity_update(entity);
void blit_entity_draw(&engine, entity);
int blit_entity_collides(e1, e2);
int blit_entity_on_screen(&engine, entity);
void blit_entity_clamp_to_screen(&engine, entity);
void blit_entity_free(entity);

Drawing

void blit_draw_rect(&engine, x, y, w, h, color);
void blit_draw_rect_outline(&engine, x, y, w, h, color, thickness);
void blit_draw_line(&engine, x0, y0, x1, y1, color, thickness);
void blit_draw_circle(&engine, cx, cy, radius, color);
void blit_draw_text(&engine, text, x, y, color);

Input

int blit_key_down(&engine, KEY_W);
int blit_key_pressed(&engine, KEY_SPACE);
int blit_mouse_down(&engine, MOUSE_LEFT);
int blit_mouse_clicked(&engine, MOUSE_LEFT);

Collision & Math

int blit_rects_overlap(x1, y1, w1, h1, x2, y2, w2, h2);
int blit_point_in_rect(px, py, rx, ry, rw, rh);
float blit_distance(x1, y1, x2, y2);
float blit_clamp(value, min, max);
int blit_random_int(min, max);
float blit_random_float();

🏗️ Integration with ModuOS Build

To integrate Blit into the main ModuOS build system, add to your main Makefile:

# Build Blit Engine
.PHONY: blit
blit:
	$(MAKE) -C EXTERNAL/Blit all
	$(MAKE) -C EXTERNAL/Blit install

# Add as dependency to userland apps
userland_apps: blit

Then Blit will be built automatically with ModuOS!

🎯 When to Use Blit

Use Blit Engine if you want to:

  • ✅ Make 2D games quickly
  • ✅ Use high-level game objects (entities, sprites)
  • ✅ Have built-in collision detection
  • ✅ Focus on gameplay, not rendering details
  • ✅ Prototype games rapidly

Use NodGL directly if you want to:

  • ⚙️ Full control over rendering
  • ⚙️ Custom graphics effects
  • ⚙️ Non-game graphics applications
  • ⚙️ Maximum performance tuning

📖 Comparison: NodGL vs Blit

Feature NodGL Blit Engine
Level Low High
Purpose Graphics API Game Framework
Entities Manual Built-in
Collision DIY Built-in
Input Manual events Simple functions
Learning Curve Moderate Easy
Best For Graphics apps 2D games

🤝 Contributing

Want to improve Blit Engine?

  • Add new features
  • Create more examples
  • Improve BlitStudio
  • Write tutorials
  • Report bugs

See EXTERNAL/Blit/README.md for details.

📜 License

Blit Engine is part of ModuOS and licensed under GPL v2.0.


Ready to make games? Head to EXTERNAL/Blit/ and run ./build.sh all! 🚀

See also:

Clone this wiki locally