projectile system
This commit is contained in:
parent
918b4884b2
commit
ad4a2cf393
17 changed files with 400 additions and 23 deletions
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue