Crates.io | wasm-rgame |
lib.rs | wasm-rgame |
version | 0.0.1 |
source | src |
created_at | 2018-05-25 13:48:11.775108 |
updated_at | 2018-05-25 13:48:11.775108 |
description | A Rust/wasm game-engine |
homepage | https://github.com/DarrenTsung/wasm-rgame |
repository | https://github.com/DarrenTsung/wasm-rgame |
max_upload_size | |
id | 67005 |
size | 39,654 |
A Rust framework for building browser games with WASM.
This framework was inspired by the Game of Life Rust + WASM Tutorial. You can dive right in and start writing a wasm-rgame application with the [tutorial](TODO link tutorial)!
This framework abstracts away writing custom HTML/Javascript and provides Rust types that interface with the Javascript bundled in the wasm-rgame-js repository.
The Rust API provides types for:
Also, a build tool (wasm-rgame-tools) is provided that builds the project (targeting wasm32-unknown-unknown), runs wasm-bindgen, and bundles together the generated WASM binaries and Javascript/HTML.
This project is mainly experimental, but has been used to make non-trivial applications (see wrg-snake).
These examples are taken from wrg-snake. Also note that these examples can't be run stand-alone as they require the Javascript/HTML framework.
Rendering a transparent overlay:
use wasm_rgame::{Delegate, Graphics};
impl Delegate for MyObject {
fn tick(..) {}
fn render(&self, graphics: &mut Graphics) {
// draw a transparent overlay over the game
graphics.draw_rect(
0.0,
0.0,
CANVAS.width() as f32,
CANVAS.height() as f32,
[255, 255, 255, 150]
);
}
}
Checking keyboard input:
use wasm_rgame::{KeyManager, key_codes};
pub fn store_direction_change(&mut self, key_manager: &KeyManager) {
// Don't let direction change if already going opposite direction
let wanted_direction = if key_manager.key_down(key_codes::W) {
Direction::Up
} else if key_manager.key_down(key_codes::D) {
Direction::Right
} else if key_manager.key_down(key_codes::S) {
Direction::Down
} else if key_manager.key_down(key_codes::A) {
Direction::Left
} else {
return;
};
...
}
Read the [tutorial](TODO tutorial) and get started writing your own wasm-rgame application!