diff --git a/Cargo.lock b/Cargo.lock index 14ea77ae..0e1f5b1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -232,6 +232,42 @@ dependencies = [ "bevy_internal", ] +[[package]] +name = "bevy-inspector-egui" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c53ed1cad011e33ea145d2c1f649a966e7457453f3768ddff39bc5064bd525" +dependencies = [ + "bevy", + "bevy-inspector-egui-derive", + "bevy_egui", + "image 0.23.14", + "nalgebra", + "pretty-type-name", +] + +[[package]] +name = "bevy-inspector-egui-derive" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48ef6260a46924d40781bcb9da157c110d5166bbd573795e4a16f2505913d0d0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "bevy-inspector-egui-rapier" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef372e6960033ec7a04b259c9a08b6a9fb5e3f6b4698091dc58aad4a4d6bc5d" +dependencies = [ + "bevy", + "bevy-inspector-egui", + "bevy_rapier2d", +] + [[package]] name = "bevy-parallax" version = "0.1.2" @@ -416,6 +452,19 @@ dependencies = [ "uuid", ] +[[package]] +name = "bevy_gilrs" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "963940426127533164af2a556971a03c493143c0afb95afadb4a070b6ab8c3df" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_input", + "bevy_utils", + "gilrs", +] + [[package]] name = "bevy_hierarchy" version = "0.8.0" @@ -455,6 +504,7 @@ dependencies = [ "bevy_derive", "bevy_diagnostic", "bevy_ecs", + "bevy_gilrs", "bevy_hierarchy", "bevy_input", "bevy_log", @@ -466,8 +516,10 @@ dependencies = [ "bevy_scene", "bevy_sprite", "bevy_tasks", + "bevy_text", "bevy_time", "bevy_transform", + "bevy_ui", "bevy_utils", "bevy_window", "bevy_winit", @@ -530,6 +582,18 @@ dependencies = [ "glam", ] +[[package]] +name = "bevy_mod_debugdump" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f22cfad8fab6ca053d81c1c8795e325fe2174fa47f7455f7be7a959ef9bbaf3" +dependencies = [ + "bevy_app", + "bevy_ecs", + "bevy_render", + "pretty-type-name", +] + [[package]] name = "bevy_pbr" version = "0.8.0" @@ -720,6 +784,29 @@ dependencies = [ "wasm-bindgen-futures", ] +[[package]] +name = "bevy_text" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef05a788c2c04aaa5db95b22a8f0fff0d3a0b08a7bcd1a71f050a628b38eec6e" +dependencies = [ + "ab_glyph", + "anyhow", + "bevy_app", + "bevy_asset", + "bevy_ecs", + "bevy_math", + "bevy_reflect", + "bevy_render", + "bevy_sprite", + "bevy_transform", + "bevy_utils", + "bevy_window", + "glyph_brush_layout", + "serde", + "thiserror", +] + [[package]] name = "bevy_time" version = "0.8.0" @@ -746,6 +833,34 @@ dependencies = [ "bevy_reflect", ] +[[package]] +name = "bevy_ui" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac181a7b637da61fad72981ff9d2e5b899283ca7d54b2b7ea49c431121331c53" +dependencies = [ + "bevy_app", + "bevy_asset", + "bevy_core_pipeline", + "bevy_derive", + "bevy_ecs", + "bevy_hierarchy", + "bevy_input", + "bevy_log", + "bevy_math", + "bevy_reflect", + "bevy_render", + "bevy_sprite", + "bevy_text", + "bevy_transform", + "bevy_utils", + "bevy_window", + "bytemuck", + "serde", + "smallvec", + "taffy", +] + [[package]] name = "bevy_utils" version = "0.8.0" @@ -1695,6 +1810,40 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "gilrs" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6ba7c37bf8ea7ba0c3e3795dfa1a7771b1e47c4bb417c4d27c7b338d79685f" +dependencies = [ + "fnv", + "gilrs-core", + "log", + "uuid", + "vec_map", +] + +[[package]] +name = "gilrs-core" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96a8d94a7fc5afd27e894e08a4cfe5a49237f85bcc7140e90721bad3399c7d02" +dependencies = [ + "core-foundation 0.9.3", + "io-kit-sys", + "js-sys", + "libc", + "libudev-sys", + "log", + "nix 0.24.2", + "rusty-xinput", + "uuid", + "vec_map", + "wasm-bindgen", + "web-sys", + "winapi", +] + [[package]] name = "glam" version = "0.21.2" @@ -1736,6 +1885,17 @@ dependencies = [ "web-sys", ] +[[package]] +name = "glyph_brush_layout" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc32c2334f00ca5ac3695c5009ae35da21da8c62d255b5b96d56e2597a637a38" +dependencies = [ + "ab_glyph", + "approx", + "xi-unicode", +] + [[package]] name = "gpu-alloc" version = "0.5.3" @@ -1785,6 +1945,26 @@ dependencies = [ "svg_fmt", ] +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] + +[[package]] +name = "hash32-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59d2aba832b60be25c1b169146b27c64115470981b128ed84c8db18c1b03c6ff" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "hashbrown" version = "0.11.2" @@ -1960,6 +2140,16 @@ dependencies = [ "unic-langid", ] +[[package]] +name = "io-kit-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7789f7f3c9686f96164f5109d69152de759e76e284f736bd57661c6df5091919" +dependencies = [ + "core-foundation-sys 0.8.3", + "mach", +] + [[package]] name = "itertools" version = "0.10.3" @@ -2087,9 +2277,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] -name = "leafwing_input_manager" -version = "0.5.0" -source = "git+https://github.com/Leafwing-Studios/leafwing-input-manager.git?branch=dev#cfa8759212049244a88d0fb173271c1cda740e1c" +name = "leafwing-input-manager" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524be04b15812de73b2e07add91538a3a67026259421285ae2b2ff0dec308261" dependencies = [ "bevy", "derive_more", @@ -2102,7 +2293,8 @@ dependencies = [ [[package]] name = "leafwing_input_manager_macros" version = "0.5.0" -source = "git+https://github.com/Leafwing-Studios/leafwing-input-manager.git?branch=dev#cfa8759212049244a88d0fb173271c1cda740e1c" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d38676bbe26f336c5554150be0050a7033c72e882f8df4be5a2b3b1e6b2929cd" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2132,6 +2324,16 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da83a57f3f5ba3680950aa3cbc806fc297bc0b289d42e8942ed528ace71b8145" +[[package]] +name = "libudev-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c8469b4a23b962c1396b9b451dda50ef5b283e8dd309d69033475fa9b334324" +dependencies = [ + "libc", + "pkg-config", +] + [[package]] name = "lock_api" version = "0.4.7" @@ -2435,6 +2637,17 @@ dependencies = [ "memoffset", ] +[[package]] +name = "nix" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "libc", +] + [[package]] name = "nohash-hasher" version = "0.2.0" @@ -2819,6 +3032,12 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +[[package]] +name = "pretty-type-name" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8815d101cfb4cb491154896bdab292a395a7ac9ab185a9941a2f5be0135900d" + [[package]] name = "proc-macro-crate" version = "1.1.3" @@ -2875,17 +3094,20 @@ dependencies = [ "anyhow", "async-channel", "bevy", + "bevy-inspector-egui", + "bevy-inspector-egui-rapier", "bevy-parallax", "bevy_egui", "bevy_fluent", "bevy_kira_audio", + "bevy_mod_debugdump", "bevy_rapier2d", "directories", "egui_extras", "fluent", "getrandom", "iyes_loopless", - "leafwing_input_manager", + "leafwing-input-manager", "once_cell", "punchy_macros", "rand", @@ -3083,6 +3305,17 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rusty-xinput" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2aa654bc32eb9ca14cce1a084abc9dfe43949a4547c35269a094c39272db3bb" +dependencies = [ + "lazy_static", + "log", + "winapi", +] + [[package]] name = "ryu" version = "1.0.10" @@ -3400,6 +3633,19 @@ dependencies = [ "winapi", ] +[[package]] +name = "taffy" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec27dea659b100d489dffa57cf0efc6d7bfefb119af817b92cc14006c0b214e3" +dependencies = [ + "arrayvec", + "hash32", + "hash32-derive", + "num-traits", + "typenum", +] + [[package]] name = "termcolor" version = "1.1.3" @@ -4051,3 +4297,9 @@ dependencies = [ "winapi", "winapi-wsapoll", ] + +[[package]] +name = "xi-unicode" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a67300977d3dc3f8034dae89778f502b6ba20b269527b3223ba59c0cf393bb8a" diff --git a/Cargo.toml b/Cargo.toml index d2fb6b92..67f954df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,8 @@ default-features = false features = [ "x11", "png", - "filesystem_watcher" + "filesystem_watcher", + "bevy_gilrs" ] [dependencies] @@ -38,7 +39,7 @@ structopt = "0.3.26" rand = "0.8.5" getrandom = { version = "0.2", features = ["js"] } -leafwing_input_manager = { git = "https://github.com/Leafwing-Studios/leafwing-input-manager.git", default-features = false, branch = "dev" } +leafwing-input-manager = { version = "0.5", default-features = false } unic-langid = "0.9.0" bevy_fluent = { git = "https://github.com/kgv/bevy_fluent.git" } sys-locale = "0.2.1" @@ -48,17 +49,17 @@ async-channel = "1.6.1" once_cell = "1.13.0" # Waiting for updates to Bevy 0.8 -# bevy_mod_debugdump = { version = "0.4", optional = true } -# bevy-inspector-egui = { version = "0.11", optional = true } -# bevy-inspector-egui-rapier = { version = "0.4", optional = true, features = ["rapier2d"] } +bevy_mod_debugdump = { version = "0.5.0", optional = true } +bevy-inspector-egui = { version = "0.12.1", optional = true } +bevy-inspector-egui-rapier = { version = "0.5.0", optional = true, features = ["rapier2d"] } [target.'cfg(target_arch = "wasm32")'.dependencies] web-sys = { version = "0.3", features = ["Window","Location","Storage"] } [features] default = [] -# Waiting for update to Bevy 0.8 -# schedule_graph = ["bevy_mod_debugdump"] +debug = ["bevy_mod_debugdump", "bevy-inspector-egui", "bevy-inspector-egui-rapier"] +schedule_graph = ["bevy_mod_debugdump"] # Enable optimizations for dependencies but not for our code [profile.dev.package."*"] diff --git a/assets/fighters/bandit/bandit.fighter.yaml b/assets/fighters/bandit/bandit.fighter.yaml index 25ea77fc..e0031743 100644 --- a/assets/fighters/bandit/bandit.fighter.yaml +++ b/assets/fighters/bandit/bandit.fighter.yaml @@ -1,8 +1,8 @@ name: Bandit stats: - health: 150 - damage: 20 + max_health: 150 + damage: 4 movement_speed: 150 hud: diff --git a/assets/fighters/brute/brute.fighter.yaml b/assets/fighters/brute/brute.fighter.yaml index 3a60fe39..e9905051 100644 --- a/assets/fighters/brute/brute.fighter.yaml +++ b/assets/fighters/brute/brute.fighter.yaml @@ -1,8 +1,8 @@ name: Brute stats: - health: 200 - damage: 50 + max_health: 200 + damage: 10 movement_speed: 50 hud: diff --git a/assets/fighters/fishy/fishy.fighter.yaml b/assets/fighters/fishy/fishy.fighter.yaml index 5aa40dfc..b351ebde 100644 --- a/assets/fighters/fishy/fishy.fighter.yaml +++ b/assets/fighters/fishy/fishy.fighter.yaml @@ -1,7 +1,7 @@ name: Fishy The Fearsome stats: - health: 100 + max_health: 600 damage: 35 movement_speed: 150 diff --git a/assets/fighters/sharky/sharky.fighter.yaml b/assets/fighters/sharky/sharky.fighter.yaml index 2b8b9338..e3ccb046 100644 --- a/assets/fighters/sharky/sharky.fighter.yaml +++ b/assets/fighters/sharky/sharky.fighter.yaml @@ -1,7 +1,7 @@ name: Scrumptious Sharky stats: - health: 100 + max_health: 600 damage: 35 movement_speed: 150 diff --git a/assets/fighters/slinger/slinger.fighter.yaml b/assets/fighters/slinger/slinger.fighter.yaml index 4b75d464..ee233631 100644 --- a/assets/fighters/slinger/slinger.fighter.yaml +++ b/assets/fighters/slinger/slinger.fighter.yaml @@ -1,8 +1,8 @@ name: Slinger stats: - health: 100 - damage: 35 + max_health: 100 + damage: 7 movement_speed: 150 hud: diff --git a/assets/items/bottle/bottle.item.yaml b/assets/items/bottle/bottle.item.yaml index 9f947c8d..25b35c5d 100644 --- a/assets/items/bottle/bottle.item.yaml +++ b/assets/items/bottle/bottle.item.yaml @@ -3,3 +3,6 @@ name: Bottle image: image: bottle.png image_size: [11, 31] + +kind: !Throwable + damage: 10 diff --git a/assets/items/health/health.item.yaml b/assets/items/health/health.item.yaml index aeee288b..e528ebcf 100644 --- a/assets/items/health/health.item.yaml +++ b/assets/items/health/health.item.yaml @@ -1,5 +1,8 @@ name: Health image: - image: health.png - image_size: [22, 20] + image: health.png + image_size: [22, 20] + +kind: !Health + health: 1000000 # Refill all of it diff --git a/src/animation.rs b/src/animation.rs index 7ca95e1e..0dfe33ae 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -1,8 +1,8 @@ use std::ops::Range; -use crate::{state::State, GameStage, GameState}; +use crate::GameState; use bevy::{ - prelude::{App, Changed, Component, Plugin, Query, Res}, + prelude::*, sprite::TextureAtlasSprite, time::{Time, Timer}, utils::HashMap, @@ -15,10 +15,9 @@ pub struct AnimationPlugin; impl Plugin for AnimationPlugin { fn build(&self, app: &mut App) { app.add_system_set_to_stage( - GameStage::Animation, + CoreStage::Last, ConditionSet::new() .run_in_state(GameState::InGame) - .with_system(animate_on_state_changed) .with_system(animation_flipping) .with_system(animation_cycling) .into(), @@ -26,6 +25,14 @@ impl Plugin for AnimationPlugin { } } +/// Bundle for animated sprite sheets +#[derive(Bundle)] +pub struct AnimatedSpriteSheetBundle { + #[bundle] + pub sprite_sheet: SpriteSheetBundle, + pub animation: Animation, +} + #[cfg_attr(feature = "debug", derive(bevy_inspector_egui::Inspectable))] #[derive(Component, PartialEq, Eq, Clone)] pub enum Facing { @@ -37,10 +44,6 @@ impl Facing { pub fn is_left(&self) -> bool { self == &Facing::Left } - - pub fn set(&mut self, facing: Facing) { - *self = facing; - } } #[derive(serde::Deserialize, Clone, Debug)] @@ -95,31 +98,41 @@ impl<'de> serde::de::Visitor<'de> for RangeVisitor { #[derive(Component)] pub struct Animation { - pub animations: HashMap, + pub animations: HashMap, pub current_frame: usize, - current_state: Option, + pub current_animation: Option, pub timer: Timer, pub played_once: bool, } impl Animation { - pub fn new(fps: f32, animations: HashMap) -> Self { + pub fn new(fps: f32, animations: HashMap) -> Self { Self { animations, current_frame: 0, - current_state: None, + current_animation: None, timer: Timer::from_seconds(fps, false), played_once: false, } } + /// Start playing a new animation + pub fn play(&mut self, name: &str, repeating: bool) { + self.current_animation = Some(name.to_owned()); + self.current_frame = 0; + self.timer.reset(); + self.timer.unpause(); + self.timer.set_repeating(repeating); + self.played_once = false; + } + pub fn is_finished(&self) -> bool { self.played_once } pub fn is_repeating(&self) -> bool { - if let Some(state) = self.current_state { - if let Some(clip) = self.animations.get(&state) { + if let Some(animation) = &self.current_animation { + if let Some(clip) = self.animations.get(animation) { return clip.repeat; } } @@ -138,8 +151,8 @@ impl Animation { } pub fn get_current_indices(&self) -> Option<&Range> { - if let Some(state) = self.current_state { - match self.animations.get(&state) { + if let Some(animation) = &self.current_animation { + match self.animations.get(animation) { Some(clip) => return Some(&clip.frames), None => return None, } @@ -157,22 +170,11 @@ impl Animation { } } -fn animate_on_state_changed(mut query: Query<(&mut Animation, &State), Changed>) { - for (mut animation, state) in query.iter_mut() { - if animation.current_state != Some(*state) { - animation.played_once = false; - animation.current_frame = 0; - animation.current_state = Some(*state); - animation.timer.reset(); - } - } -} - fn animation_cycling(mut query: Query<(&mut TextureAtlasSprite, &mut Animation)>, time: Res