projectile system

This commit is contained in:
Jim 2025-08-31 19:00:19 -04:00
parent 918b4884b2
commit ad4a2cf393
Signed by: jim
GPG key ID: 3D7D94BA53088BF4
17 changed files with 400 additions and 23 deletions

View file

@ -18,10 +18,29 @@ impl Plugin for CombatDamagersPlugin {
}
}
#[derive(Component)]
#[derive(Component, Default)]
#[require(CollisionEventsEnabled)]
pub struct ContactDamage {
pub amount: f32,
pub skip_invulnerability: bool,
pub self_damage: f32,
}
impl ContactDamage {
pub fn new(amount: f32) -> Self {
Self {
amount,
..default()
}
}
pub fn projectile(amount: f32, self_damage: f32) -> Self {
Self {
amount,
skip_invulnerability: true,
self_damage,
}
}
}
fn deal_contact_damage(
@ -35,20 +54,40 @@ fn deal_contact_damage(
Attacked {
attacker: Some(event.0),
amount: contact.amount,
..default()
skip_invulnerability: contact.skip_invulnerability,
},
event.1,
);
if contact.self_damage > 0. {
commands.trigger_targets(
Attacked {
attacker: None,
amount: contact.self_damage,
skip_invulnerability: true,
},
event.0,
);
}
}
if let Ok(contact) = query.get(event.1) {
commands.trigger_targets(
Attacked {
attacker: Some(event.1),
amount: contact.amount,
..default()
skip_invulnerability: contact.skip_invulnerability,
},
event.0,
);
if contact.self_damage > 0. {
commands.trigger_targets(
Attacked {
attacker: None,
amount: contact.self_damage,
skip_invulnerability: true,
},
event.1,
);
}
}
}
}