Impl a basic scoring system
Games have scores, so I need a score counter... I guess.
This commit is contained in:
@@ -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)),
|
||||
)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user