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.
-
Clone this repository.
-
Make sure you have the following in your
PATH
environment variable
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.
- Unix/Macos
zig build -Dapp=examples/snake.roc run
- Windows
zig build -Dapp=".\examples\snake.roc" run
Thank you Brendan Hansknecht and Luke DeVault (art) for this demo.
- Unix/Macos
zig build -Dapp=examples/rocci-bird.roc run
- Windows
zig build -Dapp=".\examples\rocci-bird.roc" run
- Unix/Macos
zig build -Dapp=examples/sound.roc run
- Windows
zig build -Dapp=".\examples\sound.roc" run
Thank you Isaac Van Doren for this demo.
Link to source code, and play online
๐ 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/
.
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.
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