51 lines
1.3 KiB
Rust
51 lines
1.3 KiB
Rust
use bevy::prelude::*;
|
|
use derive_more::{Deref, DerefMut};
|
|
|
|
#[derive(Resource, Default)]
|
|
pub struct Counter {
|
|
pub count: u32,
|
|
}
|
|
|
|
impl Counter {
|
|
pub fn new() -> Self {
|
|
Counter { count: 0 }
|
|
}
|
|
|
|
pub fn increase(&mut self, delta: u32) {
|
|
self.count += delta;
|
|
}
|
|
|
|
pub fn reset(&mut self) {
|
|
self.count = 0;
|
|
}
|
|
}
|
|
|
|
#[derive(Resource, Default, Deref, DerefMut)]
|
|
pub struct BubbleExplodedCountThisFrame(pub Counter);
|
|
|
|
#[derive(Resource, Default, Deref, DerefMut)]
|
|
pub struct BubbleSuckedCountThisFrame(pub Counter);
|
|
|
|
#[derive(Resource, Default, Deref, DerefMut)]
|
|
pub struct KirbyHitCountThisFrame(pub Counter);
|
|
|
|
fn reset_frame_counters(
|
|
mut bubble_sucked: ResMut<BubbleSuckedCountThisFrame>,
|
|
mut bubble_exploded: ResMut<BubbleExplodedCountThisFrame>,
|
|
mut kirby_hit: ResMut<KirbyHitCountThisFrame>,
|
|
) {
|
|
bubble_sucked.reset();
|
|
bubble_exploded.reset();
|
|
kirby_hit.reset();
|
|
}
|
|
|
|
pub struct CounterPlugin;
|
|
|
|
impl Plugin for CounterPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.insert_resource(BubbleSuckedCountThisFrame::default())
|
|
.insert_resource(BubbleExplodedCountThisFrame::default())
|
|
.insert_resource(KirbyHitCountThisFrame::default())
|
|
.add_systems(FixedPostUpdate, reset_frame_counters);
|
|
}
|
|
}
|