> Documentation version: 0.8.0. [HTML page](https://lukewilliamboswell.github.io/roc-wasm4/index.html)

<a id="roc-wasm4"></a>

# roc-wasm4

roc-wasm4 is a Roc platform for [WASM-4](https://wasm4.org) games.
It provides drawing, input, audio, disk persistence, netplay state and sprites.

<a id="release-0-8-0"></a>

# Release 0.8.0

Use this release’s [platform bundle](https://github.com/lukewilliamboswell/roc-wasm4/releases/download/0.8.0/GM7NT8JuW6TB4X9FAZKiHC4yBJ6nzeNrRwuyjvyZdqMu.tar.zst) and [examples archive](https://github.com/lukewilliamboswell/roc-wasm4/releases/download/0.8.0/roc-wasm4-examples-0.8.0.zip). The [API archive](https://github.com/lukewilliamboswell/roc-wasm4/releases/download/0.8.0/roc-wasm4-docs-0.8.0.zip) restores this release’s reference. Download the [PDF manual](https://github.com/lukewilliamboswell/roc-wasm4/releases/download/0.8.0/roc-wasm4-manual-0.8.0.pdf). Each asset has checked SPDX and CycloneDX sidecars beside it.

<a id="build-a-game"></a>

## Build a game

Install a current Roc nightly and the WASM-4 CLI (` w4 `).
For a checkout, install [Blueprint 0.11.0](https://github.com/lukewilliamboswell/roc-blueprint/releases),
then build the host and a cart:

``` shell
blueprint run build-host
roc build examples/basic/main.roc --target=wasm32 --opt=size --output=basic.wasm
w4 run basic.wasm
```

Checkout examples use the working-tree platform. For a standalone game, copy
an entire example directory and replace its platform path with the immutable
bundle URL from the [selected release](https://github.com/lukewilliamboswell/roc-wasm4/releases).
Follow that release’s compiler requirements; older releases may require a specific nightly.

<a id="choose-an-example"></a>

## Choose an example

| Example | What it demonstrates |
| --- | --- |
| ` examples/basic/main.roc ` | Drawing, text, input, mouse, trace and tones |
| ` examples/snake/main.roc ` | A playable snake game |
| ` examples/rocci-bird/main.roc ` | Rocci Bird, by Brendan Hansknecht with art by Luke DeVault |
| ` examples/sound/main.roc ` | A tone parameter playground |

[Play Rocci Bird online](https://bren077s.itch.io/rocci-bird).
The repository README links animated demonstrations.

<a id="use-the-platform-api"></a>

## Use the platform API

Import ` w4.W4 ` for drawing, input, audio, persistence and utility functions.
Use ` w4.Sprite ` for sprite data and blitting; ` w4.Host ` contains the lower-level
hosted effects used by the platform.
See the [generated API reference](api/index.html) for function signatures and usage.

<a id="distribute-a-game"></a>

## Distribute a game

Build with size-oriented optimization and use the WASM-4 CLI to produce an HTML game:

``` shell
roc build app.roc --target=wasm32 --opt=size --output=app.wasm
w4 bundle app.wasm --title "My Game" --html my-game.html
```

For native distribution:

``` shell
w4 bundle app.wasm --title "My Game" --windows my-game-windows.exe --mac my-game-mac --linux my-game-linux
```

<a id="work-on-the-platform"></a>

## Work on the platform

Run ` blueprint run check ` from the repository root. Blueprint downloads and
verifies the fixed tooling compiler and Zig; ` roc ` on PATH is the compiler
under test. ` blueprint run bundle ` bundles an already-built host.

CI runs all four public carts for sixty deterministic frames in the official
WASM-4 web runtime under locked headless Chromium on Linux. It checks framebuffer
hashes, simulated input, trace output and host import calls. Play-test audible
sound and native runtime behavior before release.
The host reserves 32768 bytes for dynamic allocation by default; build with
` zig build -Dmem-size=<bytes> ` inside ` blueprint shell ` to change that limit.

Run ` blueprint run docs ` to render the HTML, PDF and Markdown manual and API reference.

