diff --git a/Cargo.lock b/Cargo.lock index 6d7dd1e..3c9c21a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -591,6 +591,7 @@ dependencies = [ "bevy_rapier2d", "leafwing-input-manager", "petgraph", + "seldom_state", ] [[package]] @@ -4816,6 +4817,23 @@ dependencies = [ "tiny-skia", ] +[[package]] +name = "seldom_state" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5db0767975eeb39d99493b23adc55b14d7106c333c06dd85774fa2cb909b79d5" +dependencies = [ + "bevy_app", + "bevy_derive", + "bevy_ecs", + "bevy_log", + "bevy_math", + "bevy_utils", + "either", + "leafwing-input-manager", + "variadics_please", +] + [[package]] name = "self_cell" version = "1.2.2" diff --git a/Cargo.toml b/Cargo.toml index 5ac7fc0..148865f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ bevy = { version = "0.18.0", features = ["bevy_remote"] } bevy_rapier2d = "0.33.0" leafwing-input-manager = "0.20.0" petgraph = { version = "0.8.3" } +seldom_state = { version = "0.16.0", features = ["leafwing_input"] } [profile.dev] opt-level = 1 diff --git a/src/combat/attack.rs b/src/combat/attack.rs index eceaf54..0c89016 100644 --- a/src/combat/attack.rs +++ b/src/combat/attack.rs @@ -5,6 +5,8 @@ use std::time::Duration; use bevy::prelude::*; use bevy_rapier2d::prelude::*; +use crate::{GROUP_ATTACK, GROUP_INTERACTIVE, GROUP_STATIC}; + /// Contains logic for attack-related calculations #[derive(Component, Clone, Debug, Reflect)] #[reflect(Component, Clone, Debug)] @@ -33,6 +35,7 @@ impl AttackArea { max_distance, } } + /// Returns attack area bundle with everything needed pub fn bundle( damage: f32, @@ -41,6 +44,7 @@ impl AttackArea { position: Vec2, half_area: Vec2, facing_left: bool, + affinity: Group, ) -> impl Bundle { let origin_x = if facing_left { position.x - half_area.x } else { position.x + half_area.x }; ( @@ -49,6 +53,10 @@ impl AttackArea { // Collision Transform::from_xyz(position.x, position.y, 0.), + CollisionGroups::new( + GROUP_ATTACK, + GROUP_STATIC | GROUP_INTERACTIVE | affinity, + ), Collider::cuboid(half_area.x, half_area.y), // AttackAreaOrigin @@ -73,3 +81,12 @@ impl AttackArea { self.damage * EaseFunction::QuinticOut.sample_unchecked(total_multiplier) } } + +/// System that updates AttackArea timers and despawns those who timed out +pub fn update_attack_areas(mut commands: Commands, time: Res