Your first gamepreview
Install the game tools, build and play the bundled Pong, change it, and run it without a window.
In this tutorial you'll install the moxzi.game tools, build the Pong example that comes with them, play it, and change its colours. It takes about ten minutes.
You need an Apple Silicon Mac.
1. Install#
Install the compiler and the game tools. They're separate downloads; the game tools are about 35 MB because they include a 3D renderer.
curl -fsSL https://moxzi.ai/install.sh | sh
curl -fsSL https://moxzi.ai/install-game.sh | sh
Tell the game tools where the compiler is. Add these lines to your shell profile:
export MOXZI_BIN=~/.local/bin/moxzi
export MOXZI_COMPILER=~/.local/lib/moxzi/compiler.wasm
export MOXZI_LINKER=~/.local/lib/moxzi/linker.wasm
2. Copy the example#
The example is installed read-only. Copy it somewhere you can edit:
cp -R ~/.local/lib/moxzi-game/examples/pong pong
cd pong
| File | Contents |
|---|---|
game.yaml | The project: entry file, asset folder, simulation rate (30 ticks per second) |
src/Main.mo | The match actor: game state, input handling, and what to draw |
src/Game.mo | The rules: ball movement, collisions, scoring |
src/Opponent.mo | The computer opponent, a separate actor |
src/Scene.mo | Builds the scene (court, paddles, ball, camera, light) from the game state |
assets/ | Shapes, colours, sounds and controls |
3. Build and play#
moxzi-game build . out/pong
./pong/out/pong
build compiles the Motoko, checks the assets, and writes a package to out/pong. Play it:
moxzi-player out/pong native
Use W and S (or drag) to move your paddle. Space pauses, R restarts, Tab switches to two players.
4. Change something#
Open assets/court.material.yaml and change the court to dark red:
version: 1
base_color_linear: [0.25, 0.01, 0.01, 1]
metallic: 0.2
roughness: 0.42
emissive_linear: [0.0, 0.0, 0.0]
Colours are linear RGBA, from 0 to 1. Build into a new directory (build won't overwrite an existing one) and play it:
moxzi-game build . out/pong-red
./pong/out/pong-red
moxzi-player out/pong-red native
If you build into a directory that already exists, build stops:
Error: build destination already exists; choose a new output directory
5. Run without a window#
run-headless runs the simulation for a number of ticks without drawing anything. Use it in tests and CI:
moxzi-game run-headless out/pong 300 native
{
"execution_policy": {
"message_fuel": 20000000,
"version": 1
},
"live_actors": 2,
"loading_admissions": 0,
"scope": "unpaced explicit-clock execution; not rendering, replay or capacity evidence",
"simulation_time_ns": 10000000000,
"ticks": 300,
"wasm_timeout_ms": null
}
300 ticks at 30 per second is 10 seconds of game time. It runs as fast as the CPU allows. live_actors is 2: the match and the opponent.
Next steps#
- Writing a game: build a game from scratch and learn what each part of the actor does.
- Assets: shapes, materials and sounds.