Runnable sample programs. Work from the repository root so working-directory defaults (e.g. rpg_save.json) match the comments in each file.
If you have moonbasic from Releases:
moonbasic new MyGame
cd MyGame
moonrun main.mbTo run the samples below, clone this repo or download the source ZIP — release archives do not include examples/.
Runnable copies of Full example blocks in docs/systems/guides/:
| Folder | Run |
|---|---|
| guides/ | moonrun examples/guides/game_loop.mb |
| guides/math/ | moonrun examples/guides/math/math_2d_chase.mb |
Check any file: moonbasic --check examples/guides/game_loop.mb
Use the official compiled distribution from GitHub Releases — not go run, not a locally built moonrun. Extract the full runtime zip/tar.gz so you have moonbasic and moonrun next to each other.
- Download and extract the full runtime archive for your OS (Windows or Linux x64).
- Get the
examples/folder: clone this repo or download the repository ZIP from GitHub (release archives do not includeexamples/). - Open a terminal at the repository root (the folder that contains
examples/). Either add the folder where you extractedmoonbasic/moonrunto yourPATH, or invoke them with a full path to those.exe/ binaries.
Check all samples (no window, from repo root):
# PowerShell — every examples/**/*.mb file
Get-ChildItem -Recurse examples -Filter *.mb | ForEach-Object { go run . --check $_.FullName }
# Or with installed moonbasic:
moonbasic --check examples/spin_cube/main.mbAll 57 example scripts in examples/ are kept in sync with moonbasic --check.
Run a sample (opens a window):
moonrun examples/spin_cube/main.mbWindows (same idea):
moonbasic.exe --check examples\spin_cube\main.mb
moonrun.exe examples\spin_cube\main.mbmoonbasic— compiles.mb→.mbcnext to the source; usemoonbasic path/to/main.mbif you only want bytecode.moonrun— runs.mbor.mbcwith the full engine. The distributionmoonruncompiles in-process when needed.
More: docs/GETTING_STARTED.md (including Ship your game for packaging your own .mb / .mbc for players). OS/DLL notes: README-RELEASE.txt in the full-runtime archive.
| Folder | Description |
|---|---|
| gui_basics | raygui: window box, label, button |
| gui_theme | GUI.THEMEAPPLY — embedded official raygui .rgs themes |
| gui_form | Text field, slider, checkbox, tab bar |
| gui_counter | raygui + optional TTF; small interactive demo |
| game_math_helpers | Compile-only exercise of HDIST, YAWFROMXZ, SMOOTHERSTEP, … (GAME_MATH_HELPERS) |
| spin_cube | 3D camera, lit cube, Transform.* matrix + grid, resource cleanup |
| sphere_drop | Jolt PHYSICS3D: click to spawn colored spheres on a platform, orbit camera, cull fallen balls (Windows or Linux full runtime) |
| pong | 2D rectangles + default-font HUD |
| platformer | Simple platform collision |
| tilemap | Tiled TMX load, draw, collision layer |
| gamepad | Controller axes + buttons |
| fps | Top-down arena + moving targets |
| racing | Top-down car + checkpoints / lap counter |
| rpg | Tile-style movement + JSON save on exit |
| mario64 | 3D hop — main.mb (Draw3D), main_entities.mb (MoveEntity, EntityHitsType, TranslateEntity — see ENTITY.md), plus teaching variants in README.md |
| terrain_chase | Procedural Terrain.* + World.* streaming, Camera.OrbitEntity, WASD, slow XZ-seeking enemies (TERRAIN.md) |
| high_fidelity | Blitz-style 3D template (any resolution): Graphics3D, SetMSAA, UpdatePhysics, RENDER.Begin3D, DrawEntities (see GETTING_STARTED) |
These demos use Draw.Text for on-screen text so you do not need a .ttf in assets/. For your own projects, add fonts under assets/fonts/ and use Font.Load (see FONT reference).
- Getting started — install, use the compiler, first window
- Programming guide — game loop, namespaces, platforms
- Examples (narrative) — same ideas with inline explanations
- GUI reference —
GUI.*/ raygui