๐Ÿ“ฆ djberube / xaxocolony

๐Ÿ“„ spoilage_system.rs ยท 30 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30use super::prelude::*;

// Make Plugin
pub struct SpoilagePlugin;

impl Plugin for SpoilagePlugin {
    fn build(&self, app: &mut App) {
        app
        .add_systems(
            Update,
            spoilage_system
            .run_if(bevy::time::common_conditions::on_timer(bevy::utils::Duration::from_secs_f32(2.0)))
            .run_if(in_state(GameState::InGame))
        )
        ;
    }
}

pub fn spoilage_system(
    mut commands: Commands,
    mut food: Query<(Entity, &mut Food)>,
) {
    for (entity, mut food) in food.iter_mut() {
        food.spoilage -= food.spoilage_rate;
        if food.spoilage < 0.0 {
            // TO DO: ALERT PLAYER.
            commands.entity(entity).despawn();
        }
    }
}