add contact damage and iframes
This commit is contained in:
parent
6659fe8e5a
commit
9d397451c4
9 changed files with 171 additions and 11 deletions
53
crates/combat_damagers/src/lib.rs
Normal file
53
crates/combat_damagers/src/lib.rs
Normal 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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue