Skip to content

tsoding/rust-browser-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bloat-Free Browser Game in Rust (rustc-only challenge)

Don't blame me if this code breaks in 1 year

thumbnail

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.

diagram

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.

  1. Start an HTTP Server (for example Python's Simple HTTP Server):
$ python3 -m http.server 6969
  1. Play the game
$ iexplore http://localhost:6969/

Building game.wasm

It is assumed that you are using rustup for managing your local Rust installation.

  1. Make sure you have wasm32-unknown-unknown target installed (you only need to do it once):
$ rustup target install wasm32-unknown-unknown
  1. Build the game
$ make -B

Game Controls

  • Mouse mouse cursor to position the player
  • Click to shoot
  • SPACE to toggle pause

About

Bloat-Free Browser Game in Rust (rustc-only challenge)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages