Skip to content
/ tanks Public

Sample ๐ŸŽฎ Realtime Multiplayer Client-Server Web Game built entirely on Rust ๐Ÿฆ€+ WASM

Notifications You must be signed in to change notification settings

ndbaker1/tanks

Repository files navigation

Tanks

๐ŸŽฎ A Realtime Multiplayer Server/Client Game example built entirely with Rust ๐Ÿฆ€

โœจJust 2 lines of JavaScript needed for bootstrapping WASM in the index fileโœจ

Background

So I wanted to make a web game completely in Rust but could only find small bits of documentation in different articles/posts.

Therefore, I decided to make this as a general example for myself (and practice my Rust) regarding how to implement several critical Rust WASM features, such as implementing WebSockets and drawing to a browser Canvas exclusively from Rust APIs.

Libraries ๐Ÿ“š

The server is a Warp server setup to handle WebSockets.
I wrote this websocket server wrapper that accepts custom MessageEventHandler and ServerTickHandler, that way I can reuse it for multiple browser games.

Building ๐Ÿ”จ

pack-wasm lib is my hacky way of creating a custom build script for packing wasm and including an index page file which I find slightly annoying using wasm-pack because you cant specify the .wasm target like with wasm-bindgen-cli

cargo install wasm-bindgen-cli
cargo run --bin pack-wasm

Start the server binary from the root directory and it will server everything in the dist folder

cargo run --bin tanks_server

About

Sample ๐ŸŽฎ Realtime Multiplayer Client-Server Web Game built entirely on Rust ๐Ÿฆ€+ WASM

Topics

Resources

Stars

Watchers

Forks

Languages