Skip to content

lukewilliamboswell/roc-wasm4

Repository files navigation

roc-wasm4

Roc platform for the wasm4 game engine 🎮🕹️👾

The intent for this platform is to have some fun, learn more about Roc and platform development, and contribute something for others to enjoy.

Setup

  1. Clone this repository.

  2. Make sure you have the following in your PATH environment variable

Run

For the web runtime use zig build run

For the native runtime use zig build run-native (Note: native can often be much slower than web especially for non-optimized builds)

The build.zig script reports any warnings or errors for the app using roc check, it then builds an object file using roc build --target=wasm32 --no-link and links this with the host to produce the final .wasm game cartridge.

Snake Demo

  • Unix/Macos zig build -Dapp=examples/snake.roc run
  • Windows zig build -Dapp=".\examples\snake.roc" run

snake demo

Rocci-Bird Demo

Thank you Brendan Hansknecht and Luke DeVault (art) for this demo.

Link to play online

  • Unix/Macos zig build -Dapp=examples/rocci-bird.roc run
  • Windows zig build -Dapp=".\examples\rocci-bird.roc" run

rocci-bird demo

Sound Demo

  • Unix/Macos zig build -Dapp=examples/sound.roc run
  • Windows zig build -Dapp=".\examples\sound.roc" run

sound demo

Drum Roll

Thank you Isaac Van Doren for this demo.

Link to source code, and play online

drum roll

Documentation

📖 Platform docs hosted at lukewilliamboswell.github.io/roc-wasm4/

To generate locally use roc docs platform/main.roc, and then use a file server simple-http-server generated-docs/.

Hot Reloading

Well it isn't perfect, hot reloading can be quite nice when developing a game. For this, I suggest using the entr command line tool.

In one terminal run the build command: find . -name "*.roc" -o -name "*.zig" | entr -ccr zig build -Dapp=<app>.

In another terminal run wasm4: w4 run zig-out/lib/cart.wasm --hot.

If the hot reloading breaks (which it often does when changing the data layout or state), simply press R to reload the cart.

Distribution

To release a game, first build it with optimizations by adding -Doptimize=ReleaseSmall. Then bundle it like any other wasm4 game using the generated cartidge located in zig-out/lib/cart.wasm. If your cartidge is too large, you can try lowering the dynamic memory space with -Dmem-size=<size>. The default is 40960 bytes.

For example, a web release can be built with:

w4 bundle zig-out/lib/cart.wasm --title "My Game" --html my-game.html

For windows/mac/linux, a bundling command could look like:

w4 bundle zig-out/lib/cart.wasm --title "My Game" \
    --windows my-game-windows.exe \
    --mac my-game-mac \
    --linux my-game-linux