Skip to content

A 2-D fighting game using Rust, Bevy and WebAssembly

License

Notifications You must be signed in to change notification settings

hackmad/fighter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fighter

A 2-player fighting game written in Rust with the Bevy game engine. Based on JavaScript Fighting Game Tutorial with HTML Canvas

Assets:

Building

This project uses Cargo workspaces and split into 2 library and one binary:

Notes:

  • A clean build will take a long time due to compilation of the entire bevy engine.
  • The assets folder in the root of the project is symlinked into the desktop project.
  • The assets folder needs to be copied to destop and browser/www folders. It is ignored in .gitignore for this reason.

game

This is the shared library that houses the core game logic. It will be built as part of the other projects which target different platforms such as desktop and WebAssembly.

desktop

This compiles a desktop binary for the game.

cargo build -p desktop

To build release version:

cargo build -p desktop --release

browser

This is for the WebAssembly game and uses wasm-pack. It can't be build form the workspace root so you have to change to the project folder first.

NOTE: This relies on Node 16.13.0 LTS.

The following will build with --release by default:

cd browser
wasm-pack build --out-dir pkg

The following steps are for the first time setup only,

Initialize the Node application:

npm init wasm-app www

Install dependencies for Node application:

cd www
npm install

Update browser/www/package.json:

{
  // ..
  "scripts": {
    // ...
    "start": "cp -r ../../assets ./ && webpack-dev-server" // Update this line!
    // ...
  },
  // ...
  "devDependencies": {
    "browser": "file:../pkg", // Add this line!
    // ...
  }
  // ...
}

Update browser/www/index.js:

import * as wasm from "browser";
wasm.run()

Install dependencies again:

cd www
npm install

Running

desktop

cp -r assets desktop/assets
cargo run -p desktop

browser

cd browser/www
npm run start

If you are using a newer verison of Node, then you might need to add NODE_OPTIONS like this:

cd browser/www
NODE_OPTIONS=--openssl-legacy-provider npm run start

Open the browser to the http://localhost:8080.

NOTES:

By default browsers block autoplay and so there might be no sound.

Firefox:

  • Under Tools menu click Page Info.
  • Click Permissions tab.
  • Under Autoplay uncheck Use Default
  • Check Allow Audio and Video.

Safari:

  • Go to Preferences.
  • Click Websites tab.
  • On the left side click Auto-Play
  • Enable Allow All Auto-Play for localhost.

Chrome:

  • Go to Settings.
  • On the left select Privacy and security.
  • Scroll down to Additional content settings.
  • Click Sounds
  • Under Allowed to play sound add localhost.

About

A 2-D fighting game using Rust, Bevy and WebAssembly

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published