add contact damage and iframes

This commit is contained in:
Jim 2025-08-26 08:16:40 -04:00
parent 6659fe8e5a
commit 9d397451c4
Signed by: jim
GPG key ID: 3236D2F059A7C0AC
9 changed files with 171 additions and 11 deletions

View file

@ -0,0 +1,53 @@
//bevy system signatures often violate these rules
#![allow(clippy::type_complexity)]
#![allow(clippy::too_many_arguments)]
use avian3d::prelude::*;
use bevy::prelude::*;
use combat::Attacked;
use state::GameSystemSet;
pub struct CombatDamagersPlugin;
impl Plugin for CombatDamagersPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
FixedUpdate,
deal_contact_damage.in_set(GameSystemSet::DealDamage),
);
}
}
#[derive(Component)]
pub struct ContactDamage {
pub amount: f32,
}
fn deal_contact_damage(
mut reader: EventReader<CollisionStarted>,
query: Query<&ContactDamage>,
mut commands: Commands,
) {
for event in reader.read() {
if let Ok(contact) = query.get(event.0) {
commands.trigger_targets(
Attacked {
attacker: Some(event.0),
amount: contact.amount,
..default()
},
event.1,
);
}
if let Ok(contact) = query.get(event.1) {
commands.trigger_targets(
Attacked {
attacker: Some(event.1),
amount: contact.amount,
..default()
},
event.0,
);
}
}
}