This repository contains a basic multiplayer game inspired by Achtung, die Kurve!, written in Rust using Bevy Engine (v0.18) and Avian Physics. The goal of the project was to explore network programming when real-time movement is involved.
- Implementation of Achtung, die Kurve! (also known as Curve Fever)
- Local multiplayer (up to 5 players)
- Online multiplayer (up to 5 players) over UDP using
bevy_renet - Touch controls for mobile devices
- Cross-platform (Linux, Windows, WebAssembly)
Note
Check out the branch with-bevy-renet for a
P2P multiplayer implementation with renet which uses UDP. However, this version does not support WebAssembly
multiplayer due to browser limitations around UDP.
Online multiplayer:
Menu:
Lobby with touch controls enabled:
In-game:
You can run this project in any way you like, but I have set things up to make it easy to develop using JetBrains RustRover. For this, you'll need:
direnv- Any Direnv integration plugin e.g. https://plugins.jetbrains.com/plugin/15285-direnv-integration
nix
This way, you'll just need to direnv allow in the project directory after which all prerequisites (incl. Rust, Cargo,
all Bevy dependencies, etc.) will be available to you. The JetBrains plugin will ensure that the environment is
available to your IDE and you can run the project from there (vs cargo build and cargo run in the terminal).
RustRover will always fail to sync the project when you open it because it doesn't wait for direnv. Just re-sync
immediately after the failure and it will work.
Did RustRover forget where the Rust standard library is again? Run the below and update the path in the settings:
find /nix/store -type d -name rust_lib_src
Upgrade the flake by running nix flake update --flake . in the repository's base directory.
Warning
The web version does not support online multiplayer due to browser limitations around UDP.
- Run (already included in the Flake if using Nix):
rustup target add wasm32-unknown-unknown
- Set
RUSTFLAGSenvironment variable:- Linux:
export RUSTFLAGS="--cfg=web_sys_unstable_apis --cfg=getrandom_backend=\"wasm_js\""
- Windows:
$env:RUSTFLAGS="--cfg=web_sys_unstable_apis --cfg=getrandom_backend=`"wasm_js`""
- Linux:
- Make sure you have Node.js with
serveinstalled
Then you can build the WASM file:
- Build the WASM file:
RUSTFLAGS='--cfg=web_sys_unstable_apis --cfg=getrandom_backend="wasm_js"' cargo build --target wasm32-unknown-unknown --release --no-default-features - Clean the
/www/publicdirectory and copy the game's assets over:- Linux:
./scripts/clean-mooplas-files.sh ./scripts/copy-assets.sh
- Windows:
./scripts/clean-wasm-files.ps1 ./scripts/copy-assets.ps1
- Linux:
- Run
wasm-bindgento generate the JS bindings and move all relevant files to the/www/publicdirectory:- Linux:
wasm-bindgen --out-dir ./www/public --target web ./target/wasm32-unknown-unknown/release/mooplas.wasm
- Windows:
wasm-bindgen.exe --out-dir ./www/public --target web ./target/wasm32-unknown-unknown/release/mooplas.wasm
- Linux:
You can optimise the WASM file (from the Unofficial Bevy Cheat Book):
# Optimize for size (z profile).
wasm-opt -Oz -o output.wasm input.wasm
# Optimize for size (s profile).
wasm-opt -Os -o output.wasm input.wasm
# Optimize for speed.
wasm-opt -O3 -o output.wasm input.wasm
# Optimize for both size and speed.
wasm-opt -O -ol 100 -s 100 -o output.wasm input.wasmFinally, to run the game in your browser locally, run the below and paste the URL copied to your clipboard into your browser:
npx serve ./www/public



