Player ui
This commit is contained in:
parent
241078096f
commit
d5bd76a3b7
6 changed files with 128 additions and 5 deletions
38
src/score.rs
Normal file
38
src/score.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue