diff --git a/Cargo.lock b/Cargo.lock index a2c7e8c..99b841b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -563,8 +563,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if 1.0.0", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -1267,6 +1269,7 @@ name = "rust-game-1" version = "0.1.0" dependencies = [ "bracket-lib", + "getrandom", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3508ba3..fa0fda0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" [dependencies] bracket-lib = "0.8.1" # Meta-crate holding the entirety of bracket-lib (and exposing it). Use this for the full r... +getrandom = { version = "0.2", features = ["js"] } diff --git a/makefile b/makefile new file mode 100644 index 0000000..3217d22 --- /dev/null +++ b/makefile @@ -0,0 +1,11 @@ +build: + cargo build + +build-release: + cargo build --release + +build-wasm: + cargo build --release --target wasm32-unknown-unknown + wasm-bindgen target/wasm32-unknown-unknown/release/rust-game-1.wasm --out-dir target/rust-flappy-dragon --no-modules --no-typescript + cp src/index.html target/rust-flappy-dragon + upload target/rust-flappy-dragon diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..c508401 --- /dev/null +++ b/src/index.html @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/src/main.rs b/src/main.rs index aa9e43c..6bd870a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use std::collections::VecDeque; const SCREEN_WIDTH: u16 = 80; const SCREEN_HEIGHT: u16 = 50; -const FRAME_DURATION: f32 = 20.0; +const FRAME_DURATION: f32 = 35.0; const X_OFFSET: i32 = 10; const Y_START: i32 = 25; @@ -139,10 +139,10 @@ impl State { self.time += ctx.frame_time_ms; self.obstacleSpawnTime -= ctx.frame_time_ms; - ctx.print(1, 1, "Press Space to flag!"); + ctx.print(1, 1, "Press Space to flap!"); ctx.print(1, 2, &format!("Score: {}", self.score)); - ctx.print(1, 3, &format!("Pos: {}, {}", self.player.x, self.player.y)); - ctx.print(1, 4, &format!("Obstables: (Spawn: {}) #{} {:#?}", self.obstacleSpawnTime, self.obstacles.len(), self.obstacles)); + // ctx.print(1, 3, &format!("Pos: {}, {}", self.player.x, self.player.y)); + // ctx.print(1, 4, &format!("Obstables: (Spawn: {}) #{} {:#?}", self.obstacleSpawnTime, self.obstacles.len(), self.obstacles)); // update if self.time > FRAME_DURATION { @@ -152,7 +152,7 @@ impl State { if self.obstacleSpawnTime < 0.0 { let mut random = RandomNumberGenerator::new(); - self.obstacleSpawnTime += random.range(400.0, 1200.0); + self.obstacleSpawnTime += random.range(400.0, 1200.0) - self.score as f32; let o = Obstacle::new(self.player.x + SCREEN_WIDTH as i32, self.score); self.obstacles.push_back(o); }