spacorium/src/score.rs
2025-11-17 23:52:42 +05:00

38 lines
783 B
Rust

use bevy::prelude::*;
use crate::{damagable::DamageableKilled, ships::Factions};
const ENEMY_REWARD: u64 = 10;
#[derive(Resource)]
pub struct Score {
pub score: u64,
pub max_score: u64,
}
pub struct ScorePlugin;
impl Plugin for ScorePlugin {
fn build(&self, app: &mut App) {
app.insert_resource(Score {
score: 0,
max_score: 0,
})
.add_observer(on_something_died);
}
}
pub fn on_something_died(killed: On<DamageableKilled>, mut score: ResMut<Score>) {
let Some(faction) = killed.killed_faction else {
return;
};
if faction != Factions::EnemyFaction {
return;
}
score.score += ENEMY_REWARD;
if score.max_score < score.score {
score.max_score = score.score;
}
}