Impl a basic scoring system

Games have scores, so I need a score counter... I guess.
This commit is contained in:
2025-11-09 11:14:27 -06:00
parent de79ca0258
commit 97e0313c23
2 changed files with 14 additions and 1 deletions

View File

@@ -65,6 +65,7 @@ impl Plugin for AsteroidPlugin {
objects::ship_impact_listener,
physics::collision_listener,
machinery::tick_lifetimes,
machinery::update_scoreboard,
)
.run_if(in_state(GameState::Playing)),
)

View File

@@ -8,7 +8,7 @@ use std::time::Duration;
use bevy::prelude::*;
use crate::{WorldSize, events::SpawnAsteroid, objects::AsteroidSize};
use crate::{WorldSize, events::{AsteroidDestroy, SpawnAsteroid}, objects::AsteroidSize, resources::Score};
/// Asteroid spawning parameters and state.
///
@@ -135,3 +135,15 @@ pub fn operate_sparklers(sparklers: Query<(&mut Visibility, &mut Sparkler)>, tim
}
}
}
/// Event listener for adding score after an asteroid was destroyed
///
/// Refreshing the HUD element is done by [crate::widgets::operate_ui] (a private function)
pub fn update_scoreboard(
mut destroy_events: EventReader<AsteroidDestroy>,
mut scoreboard: ResMut<Score>,
) {
for _event in destroy_events.read() {
scoreboard.0 += 100;
}
}