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

Overview

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
You might also like...
A barebones example of how to integrate OpenXR with wgpu (Vulkan-only)

wgpu-openxr-example a barebones example of how to integrate OpenXR with wgpu (Vulkan-only) It has four modes: cargo run --no-default-features: desktop

Victorem - easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust.

Victorem Easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust. Example Cargo.toml [dependencies] vict

2-player game made with Rust and
2-player game made with Rust and "ggez" engine, based on "Conway's Game of Life"

fight-for-your-life A 2-player game based on the "Conway's Game of Life", made with Rust and the game engine "ggez". Create shapes on the grid that wi

A tetris game I wrote in rust using ncurses. I'm sure that there's a better way to write a tetris game, and the code may be sus, but it techinically works
A tetris game I wrote in rust using ncurses. I'm sure that there's a better way to write a tetris game, and the code may be sus, but it techinically works

rustetris A tetris game I wrote in rust using ncurses. I'm sure that there's a better way to write a tetris game, and the code may be sus, but it tech

A game of snake written in Rust using the Bevy game engine, targeting WebGL2

Snake using the Bevy Game Engine Prerequisites cargo install cargo-make Build and serve WASM version Set your local ip address in Makefile.toml (loca

Wasm game of life - A Rust and WebAssembly tutorial implementing the Game of Life

wasm_game_of_life Conway's Game of Life in Rust and WebAssembly Contributing | Chat Built with 🦀 🕸 by The Rust and WebAssembly Working Group About T

Conway's Game of Life implemented for Game Boy Advance in Rust

game-of-life An implementation of a Conway's Game of Life environment on GBA. The ultimate game should have two modes: Edit and Run mode which can be

2d Endless Runner Game made with Bevy Game Engine
2d Endless Runner Game made with Bevy Game Engine

Cute-runner A 2d Endless Runner Game made with Bevy Game Engine. Table of contents Project Infos Usage Screenshots Disclaimer Project Infos Date: Sept

A game for the game jam
A game for the game jam "1-Button Jam 2021"

One click ninja A game for the game jam "1-Button Jam 2021" written in Rust with the Bevy engine. A rhythm game, where you play a soldier that can def

Comments
Owner
Tsoding
Recreational Programming
Tsoding
The Bloat-Free Browser Game in Rust but in C and in UEFI

rust-browser-game but in UEFI instead of browser quick start deps rust gnu-efi gcc make build process $ make running after building everything you wil

bit6tream 12 Nov 7, 2022
rust-browser-game but native and rendered with ncurses in C without the Browser

Spin-off of rust-browser-game-but-sdl but with ncurses Nothing much to say. Just see rust-browser-game-but-sdl and rust-browser-game. Quick Start $ ma

Tsoding 8 Apr 21, 2022
Template game client for the Software Challenge 2023 ("Hey, Danke für den Fisch!")

Software Challenge 2023 Rust Client A template client for the Software Challenge 2023 (Hey, Danke für den Fisch!) written in Rust. The client implemen

FW 3 Nov 4, 2022
Tools for working with Retro game formats. Currently only supports Metroid Prime Remastered.

retrotool Warning Under active development, not guaranteed to be useful or even function. Tools for working with Retro game formats. Currently only su

null 4 Feb 19, 2023
Solana Game Server is a decentralized game server running on Solana, designed for game developers

Solana Game Server* is the first decentralized Game Server (aka web3 game server) designed for game devs. (Think web3 SDK for game developers as a ser

Tardigrade Life Sciences, Inc 16 Dec 1, 2022
A vdom-free reactive UI lib for the bevy game engine

ui4 ui4 is my fourth major attempt at making a UI dataflow library for the Bevy game engine. More specifically, it's a vdom-less UI library which uses

null 48 Nov 28, 2022
🍂 A Rust-based simulated DOM (browser-independent replacement for web_sys)

DOM in Rust without a browser Hello and welcome. This library provides server-side or browserless simulation of a DOM. Example Usage use std::sync::Ar

null 45 Dec 13, 2022
Wein2D.js bindings for creating browser games in Rust using WebAssembly.

Wein2D.js-WASM Wein2D.js bindings for creating browser games in Rust using WebAssembly. Wein2D.js-WASM requires Wein2d.js to be loaded in the same doc

DevTaube 1 Apr 14, 2022
Visual Pathfinding running in the browser!

wasm_party Here is the code I made while learning to use WebAssembly. It runs and visualizes a pathfinding algorithm in the browser. Run online Click

Ask Sødal 3 Dec 15, 2022
An application that tries to solve a Wordle puzzle only by using clues

wordlebot An application that tries to solve a Wordle puzzle only by using clues. You decide the word to discover (if you want to compete with wordleb

Rich Neswold 2 May 25, 2022