save
This commit is contained in:
parent
895b56c326
commit
ee8799c324
8 changed files with 177 additions and 38 deletions
51
src/counter.rs
Normal file
51
src/counter.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue