Giter Site home page Giter Site logo

ospencer / wasm4-gr Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 32 KB

Bindings to WASM-4, the fantasy game console for building games with WebAssembly

Home Page: https://ospencer.github.io/wasm4-gr/

Makefile 100.00%
game-development grain wasm wasm-4 wasm4 webassembly

wasm4-gr's Introduction

wasm4-gr

This project contains Grain bindings to WASM-4, a low-level fantasy game console for building small games with WebAssembly. You can find docs for the library here, but for a general overview of WASM-4, check our their docs.

Building your project

The only value that needs to be provided by your module is a function called update, taking no arguments and returning no values. This function is called on each frame of the game engine.

WASM-4 modules (called cartridges) must be <64k and meet some other specific requirements, so a number of compiler flags are required to produce compatible cartridges. To compile the hello-world.gr example in the examples directory, run

make hello

or to invoke the compiler directly, run

grain compile --release --elide-type-info --import-memory --use-start-section --memory-base 8192 --initial-memory-pages 1 --maximum-memory-pages 1 --wasi-polyfill src/wasm4-wasi-polyfill.gr -I src examples/hello-world.gr

To depend on wasm4-gr in a directory outside of your project, add the src directory to your include path with -I path/to/wasm4-gr/src. You'll also need to provide the path to the WASI polyfill provided by this library with the --wasi-polyfill flag.

The examples

The hello-world.gr file contains the basic game that is shown in the WASM-4 tutorial, and the music.gr file contains a game that utilities WASM-4's sound system to play a simple tune.

Tips to fit within 64k

This limitation is part of the fun. Grain's extensive Number type brings in quite a bit of support code, so avoiding it (and standard libraries that depend on it) is the best way to keep the cartridge size small. This includes the math operations provided by Pervasives, like + and ==, but conveniently, the WASM-4 API uses the Uint8 and Uint16 types. The hello-world.gr example is only 7k, and even with a number of sprites and a good chunk of music data, the music.gr example is 21k.

Good luck and have fun!

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.