Small faction check improvement
This commit is contained in:
parent
526caf91c7
commit
385f1ba20f
2 changed files with 25 additions and 2 deletions
|
|
@ -45,7 +45,7 @@ pub fn observe_collision(
|
||||||
let Ok((mut collided, faction)) = collision_query.get_mut(collision.with) else {
|
let Ok((mut collided, faction)) = collision_query.get_mut(collision.with) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if faction == &projectile.faction {
|
if projectile.faction.can_damage(faction) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,33 @@ use crate::projectile::spawn_projectile;
|
||||||
pub mod enemy;
|
pub mod enemy;
|
||||||
pub mod player;
|
pub mod player;
|
||||||
|
|
||||||
#[derive(Component, PartialEq)]
|
#[derive(Component)]
|
||||||
pub enum Factions {
|
pub enum Factions {
|
||||||
PlayerFaction,
|
PlayerFaction,
|
||||||
EnemyFaction,
|
EnemyFaction,
|
||||||
|
NeutralFaction,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Factions {
|
||||||
|
pub fn can_damage(&self, other: &Factions) -> bool {
|
||||||
|
match self {
|
||||||
|
Factions::PlayerFaction => match other {
|
||||||
|
Factions::PlayerFaction => false,
|
||||||
|
Factions::EnemyFaction => true,
|
||||||
|
Factions::NeutralFaction => false,
|
||||||
|
},
|
||||||
|
Factions::EnemyFaction => match other {
|
||||||
|
Factions::PlayerFaction => true,
|
||||||
|
Factions::EnemyFaction => false,
|
||||||
|
Factions::NeutralFaction => false,
|
||||||
|
},
|
||||||
|
Factions::NeutralFaction => match other {
|
||||||
|
Factions::EnemyFaction => false,
|
||||||
|
Factions::NeutralFaction => false,
|
||||||
|
Factions::PlayerFaction => false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ShipsPlugin;
|
pub struct ShipsPlugin;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue