Bloat-Free Browser Game in Rust (rustc-only challenge)
Don't blame me if this code breaks in 1 year
The idea is to make a simple game in Rust as bloat-free as possible using only rustc
(not using Emscripten, wasm-bindgen, etc.). This could be achieved by using wasm32-unknown-unknown
target directly and developing in embedded style.
We still use a little bit of JavaScript to
- Load the WebAssembly module with the logic of the Game,
- Organize the Event Loop,
- Display the Frames generated by the Game in the HTML5 Canvas.
WARNING! The Game is NOT FINISHED yet!
Main Technical Idea
The entire logic of the game is contained within the game.wasm
module that renders the frames of the game into its own memory. The JavaScript part of the applications (index.js
) constantly takes those frames directly from the memory, puts them into ImageData and displays them on the HTML5 Canvas.
Bitmap Font
The embedded bitmap font was compressed with domsson-fontgen.
Portability
The game is extremely portable. Here are some of the existing alternative "frontends" for it:
Running the Game locally
Building step is optional. The compiled version of the game (game.wasm
) is committed into the repo just in case you wanna quickly check the game without wrestling with the Rust compiler.
- Start an HTTP Server (for example Python's Simple HTTP Server):
$ python3 -m http.server 6969
- Play the game
$ iexplore http://localhost:6969/
game.wasm
Building It is assumed that you are using rustup for managing your local Rust installation.
- Make sure you have
wasm32-unknown-unknown
target installed (you only need to do it once):
$ rustup target install wasm32-unknown-unknown
- Build the game
$ make -B
Game Controls
- Mouse mouse cursor to position the player
- Click to shoot
- SPACE to toggle pause