msakuta / shooter-rust-wasm

WebAssembly port of shooter-rust project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shooter-rust-wasm

This is a port of shooter-rust to WebAssembly.

Try it now in your browser! https://msakuta.github.io/shooter-rust-wasm/

Screenshots

image

Controls

  • Arrow keys, W, A, S, D - move
  • Z, X - select weapon
  • Space - shoot weapon
  • P - toggle pause game
  • N - Restart new game

Building web application

Prerequisites

This game uses JavaScript and WebAssembly (Wasm), so you need a browser with WebAssembly support. Most modern browser support it nowadays.

How to build and run

Install

  • Cargo >1.40
  • npm >7.0.2

Install npm packages

npm i

Launch development server

npm start

It will start webpack-dev-server, launch a browser and show http://localhost:8080 automatically.

Launch production distribution

npm run build

Building native application

There is also native application version implemented with Piston game engine that can be compiled in a sub-crate shooter-rust-native.

Below is a screenshot on Windows.

image

Honestly I wouldn't much like to keep the native version, because Wasm is more portable, fast to compile and even looks faster to run. But I will keep it anyway as an exercise making portable application among native and the web.

It should support all platforms that Piston supports, which is basically desktops, like Windows, Linux or Mac.

How to build and run

Install

  • Cargo >1.40

Run

cd shooter-rust-native
cargo run --release

Note that cargo run --release --package shooter-rust-native won't work, because the root crate assumes different feature set than native version. The root crate uses "webgl" feature, which will enable wasm-bindgen and generating Wasm interface, which is not compatible with native version.

History

I originally wrote this game in C back in 2007 with Windows API.

About a decade later, I re-implmented it in Rust and Piston.

Now finally I could bring it to the web without converting the codebase into JavaScript or TypeScript.

Libraries

  • wasm-bindgen

I use WebGL API directly, without any graphics libraries.

About

WebAssembly port of shooter-rust project

License:MIT License


Languages

Language:Rust 92.8%Language:JavaScript 4.5%Language:HTML 2.7%