Giter Site home page Giter Site logo

lukewilliamboswell / roc-wasm4 Goto Github PK

View Code? Open in Web Editor NEW
40.0 5.0 3.0 812 KB

Build wasm4 games using Roc

Home Page: https://lukewilliamboswell.github.io/roc-wasm4/

License: Universal Permissive License v1.0

Zig 80.75% Shell 0.46% Roc 18.78%
roc-lang wasm4

roc-wasm4's Introduction

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

Clone this repository.

Make sure you have roc newer than 2023-1-8, zig version 0.11.0, and w4 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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.