Small faction check improvement

This commit is contained in:
Rendo 2025-11-15 17:12:42 +05:00
commit 385f1ba20f
2 changed files with 25 additions and 2 deletions

View file

@ -45,7 +45,7 @@ pub fn observe_collision(
let Ok((mut collided, faction)) = collision_query.get_mut(collision.with) else {
return;
};
if faction == &projectile.faction {
if projectile.faction.can_damage(faction) {
return;
}

View file

@ -5,10 +5,33 @@ use crate::projectile::spawn_projectile;
pub mod enemy;
pub mod player;
#[derive(Component, PartialEq)]
#[derive(Component)]
pub enum Factions {
PlayerFaction,
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;