examples/

directory
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0

README

Examples

Choose an example by what you want to learn. Start with the starter and tutorial, use focused examples for individual features, then explore the integrated game.

Source on main follows the engine's development API. Release tags preserve source matching that release; standalone example modules are pinned to it when the release is tagged.

Start here

Project What it teaches What to try or observe Before reading
Starter Minimal project structure, input bindings, fixed-tick movement, and the runner Move the blue square with WASD; use this as your project scaffold Basic Go
Your first game The capstone tutorial game: movement, aiming, combat, audio, timers, collision, camera, and a state machine with restart Drive and aim the tank, survive enemy waves; SPACE starts and restarts runs All getting-started chapters

The tutorial is a complete game, not the shortest introduction to each API it uses. Use the focused examples below when you only need one feature.

Focused examples

Each example has one primary teaching purpose. Supporting controls, shapes, text, or gameplay make that feature observable; they are not a shared example framework.

Rendering and presentation
Project What it teaches What to try or observe Before reading
Wander Fixed-tick movement rendered with transform interpolation, using an embedded sheet region Watch the sprite move smoothly between randomly chosen targets Transforms and fixed ticks
Animation File-backed sheets, setup validation, explicit grid authoring, and animation completion SPACE pauses, R restarts, 1 plays once, and 2 loops; -author saves metadata without opening a window Sprites and asset loading
Primitives Rectangle, ellipse, and line drawables with different styles Compare the rows and columns for outlines, rotation, scale, and alpha Sprites and transforms
Text Text as a drawable, including changing content, tint, and scale Compare the static labels and changing text Sprites and asset loading
Camera Camera movement, rotation, zoom, and bounds Use arrows to move, A/D to rotate, and W/S to zoom; observe the bounded view Transforms and input bindings
Tween Caller-advanced tweening on fixed versus frame clocks Pause, change simulation speed, or restart; compare motion with tint progression Fixed and frame phases
Input and gameplay
Project What it teaches What to try or observe Before reading
Input bindings Named keyboard/gamepad bindings alongside raw cursor and wheel input Drive the tank, aim with the mouse, and zoom with Q/E or the wheel Entities, transforms, and cameras
Rebinding Restore controls, edit an owned draft, confirm/cancel, apply, and save F2 edits ping; choose a key, ENTER confirms, ESC cancels; restart to restore Input actions and typed preferences
Collision Circle/box detection, layer masks, triggers, and contact-entry reactions Move through hazards and pickups; observe health and score changes Queries and fixed systems
Raycast Segment queries against synchronized collider state, with layer filtering Aim with the cursor; inspect the displayed hit or miss Colliders and camera coordinates
Scenes Builder scenes, switching and additive instances, lifecycle hooks, and entity ownership SPACE changes location; S toggles the scanner in the field Entities, queries, and resources
State Queued mode changes, enter/exit hooks, restart, and lifecycle signals SPACE cycles modes; R restarts; compare Current/Pending and the hook/signal log Frame systems and input actions
Time control Simulation pause and scale while frame-phase controls keep running Pause or change speed; compare the orbiting bodies with the live status display Fixed and frame phases
Timer One-shot/repeating timers, completion state, and timer groups R restarts the one-shot, SPACE starts the held timer, and P pauses one group Components and fixed ticks
Signals Consuming engine signals, emitting game signals, and independent readers across phases Watch the repeating charge/countdown/launch sequence and its debug messages Timers and phase ordering
Scheduling Explicit Before/After insertion within one user phase Run the headless command; observe sample/apply/audit/report despite registration order Basic systems; no window required
Settings Restore, validate, apply, and save typed preferences Compare printed values across runs; writes to the OS user config directory by default, or a supplied -directory Basic Go; no running game required

Collision demonstrates detection and game-owned reactions, not physical separation or collision resolution. Settings is a command-line persistence example, not a preferences screen.

Audio

These examples embed shared recordings. Audio output is required to hear the behavior; attribution is in CREDITS.md.

Project What it teaches What to try or observe Before reading
Playback A persistent streamed player with declarative pause, restart, and live settings P pauses, R restarts, and UP/DOWN changes the volume Audio players and sources
One-shot Fire-and-forget effects on engine-owned entities, observed through Finished signals SPACE fires a sting; tap it repeatedly to overlap plays and watch the finish counter Playback example
Playlist Track selection, sequence looping, and source swaps that continue playback N/P select, R toggles repeat, and S swaps the source without interrupting the current track One-shot example
Mixing Mixer buses, fades, global pause policies, and per-player balance Adjust volumes with arrows, Q/A balances, F fades the music bus, ENTER pauses; SPACE effects play through the pause Playback example
Spatial Listener-relative playback with named attenuation curves Move the listener with WASD/arrows, switch curves with 1/2/3, and SPACE fires a spatial one-shot Transforms and audio players/listeners
State audio Music driven by a state machine through enter hooks, source swaps, and mixer ducks SPACE toggles explore/combat; the music, stings, and bus level follow the mode The state example and playback example

Integrated games

Project What it teaches What to try or observe Before reading
Signal salvage Scenes, signals, collision, timers, and system groups coordinating a complete round SPACE starts; collect five cores before timeout, avoid the pulse, and use ENTER to return to briefing Focused scenes, signals, timers, and collision examples

Use this game to see features cooperate, not as the first explanation of each API. The first-game tutorial above remains the guided route through building a game.

Run development examples

From the repository root, create a local Go workspace:

go work init .
go work use -r ./examples
go work use ./templates/starter

If the workspace already exists, skip init and run the use commands to include new modules. The ignored workspace resolves Castrum to the checkout without changing each module's dependency requirement.

Run an example from its directory:

cd examples/audio/playback
go run .

Run its tests from the same directory with go test ./.... Most runnable directories are standalone modules using the github.com/Leonard-Atorough/castrum-examples namespace. Spatial currently belongs to the root Castrum module and runs with the same go run . command from its directory. The audio/ parent contains shared assets, not a runnable command.

Root go test ./... does not traverse standalone modules. PR and release CI build, vet, and test those modules separately against the checkout; the root module includes the shared audio assets and spatial command. See Contributing for validation commands and the release lifecycle.

Run released examples

Check out the release tag you want to learn from and disable workspace resolution with GOWORK=off in your environment. Then run the example from its directory. The source and dependencies at that tag describe the same release.

Do not assume development source will run against the version currently recorded in its module file: new APIs may not exist in that published version yet. Use the workspace for development and a release tag for a released example.

Directories

Path Synopsis
Package audioassets embeds the music loops and stings shared by the audio examples.
Package audioassets embeds the music loops and stings shared by the audio examples.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL