All Projects → tsoding → rust-browser-game

tsoding / rust-browser-game

Licence: MIT License
Bloat-Free Browser Game in Rust (rustc-only challenge)

Programming Languages

rust
11053 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to rust-browser-game

awesome-swiftwasm
A community-driven curated list of SwiftWasm projects and content
Stars: ✭ 117 (+485%)
Mutual labels:  webassembly
SadlyDistributed
Distributing your code(soul), in almost any language(state), among a cluster of idle browsers(voids)
Stars: ✭ 20 (+0%)
Mutual labels:  webassembly
golang-wasm
Golang-WASM provides a simple idiomatic, and comprehensive API and bindings for working with WebAssembly for Go and JavaScript developers
Stars: ✭ 57 (+185%)
Mutual labels:  webassembly
krustlet-wasmcloud-provider
Kubernetes Rust Kubelet provider for wasmCloud
Stars: ✭ 15 (-25%)
Mutual labels:  webassembly
Babylon.Font
Generate text mesh for BabylonJS using WASM, written in AssemblyScript.
Stars: ✭ 22 (+10%)
Mutual labels:  webassembly
wasm-fizzbuzz
WebAssembly from Scratch: From FizzBuzz to DooM.
Stars: ✭ 1,364 (+6720%)
Mutual labels:  webassembly
ricardo-forth
Forth dialect implemented in C, Javascript, WebAssembly and compiled from C to asm.js and WebAssembly.
Stars: ✭ 26 (+30%)
Mutual labels:  webassembly
Front-end-tutorial
🐼 最全的资源教程-前端涉及的所有知识体系,并在 Nice Front-end Tutorial 持续更新;
Stars: ✭ 1,655 (+8175%)
Mutual labels:  webassembly
learn-wasm
🎲 Learning WebAssembly
Stars: ✭ 57 (+185%)
Mutual labels:  webassembly
lxgui
Portable, real time, modular and data-driven GUI C++ library.
Stars: ✭ 50 (+150%)
Mutual labels:  webassembly
magnum-integration
Integration libraries for the Magnum C++11/C++14 graphics engine
Stars: ✭ 75 (+275%)
Mutual labels:  webassembly
idris-codegen-wasm
WebAssembly Code Generation Backend for Idris Compiler
Stars: ✭ 79 (+295%)
Mutual labels:  webassembly
wasm-opencc
OpenCC compiled by Emscripten so that you can run it on browsers or nodejs without compiling.
Stars: ✭ 41 (+105%)
Mutual labels:  webassembly
rustexp
A Rust regular expression editor and tester that runs entirely within the browser!
Stars: ✭ 59 (+195%)
Mutual labels:  webassembly
pywasm3
Python bindings for Wasm3, the fastest WebAssembly interpreter
Stars: ✭ 34 (+70%)
Mutual labels:  webassembly
wapc-rust
Rust-based WebAssembly Host Runtime for waPC-compliant modules
Stars: ✭ 75 (+275%)
Mutual labels:  webassembly
scout
Scout is a Ethereum 2.0 Phase 2 execution prototyping engine.
Stars: ✭ 81 (+305%)
Mutual labels:  webassembly
wgpu-rust-renderer
A tiny WebGPU renderer written in Rust
Stars: ✭ 81 (+305%)
Mutual labels:  webassembly
Binaryen
Binaryen for Swift
Stars: ✭ 15 (-25%)
Mutual labels:  webassembly
swam
WebAssembly engine in Scala
Stars: ✭ 38 (+90%)
Mutual labels:  webassembly

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].