Add HungerClock component

This commit is contained in:
Timothy Warren 2021-11-17 16:23:01 -05:00
parent c4db6f5932
commit 15a0f1779c
4 changed files with 23 additions and 2 deletions

View File

@ -179,6 +179,20 @@ pub struct ParticleLifetime {
pub lifetime_ms: f32, pub lifetime_ms: f32,
} }
#[derive(Serialize, Deserialize, Copy, Clone, PartialEq)]
pub enum HungerState {
WellFed,
Normal,
Hungry,
Starving,
}
#[derive(Component, Serialize, Deserialize, Clone)]
pub struct HungerClock {
pub state: HungerState,
pub duration: i32,
}
// Serialization helper code. We need to implement ConvertSaveLoad for each type that contains an // Serialization helper code. We need to implement ConvertSaveLoad for each type that contains an
// Entity. // Entity.

View File

@ -490,6 +490,7 @@ fn main() -> rltk::BError {
DefenseBonus, DefenseBonus,
WantsToRemoveItem, WantsToRemoveItem,
ParticleLifetime, ParticleLifetime,
HungerClock,
); );
gs.ecs.insert(SimpleMarkerAllocator::<SerializeMe>::new()); gs.ecs.insert(SimpleMarkerAllocator::<SerializeMe>::new());

View File

@ -75,7 +75,8 @@ pub fn save_game(ecs: &mut World) {
MeleePowerBonus, MeleePowerBonus,
DefenseBonus, DefenseBonus,
WantsToRemoveItem, WantsToRemoveItem,
ParticleLifetime ParticleLifetime,
HungerClock
); );
} }
@ -157,7 +158,8 @@ pub fn load_game(ecs: &mut World) {
MeleePowerBonus, MeleePowerBonus,
DefenseBonus, DefenseBonus,
WantsToRemoveItem, WantsToRemoveItem,
ParticleLifetime ParticleLifetime,
HungerClock
); );
} }

View File

@ -27,6 +27,10 @@ pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
defense: 2, defense: 2,
power: 5, power: 5,
}) })
.with(HungerClock {
state: HungerState::WellFed,
duration: 20,
})
.marked::<SimpleMarker<SerializeMe>>() .marked::<SimpleMarker<SerializeMe>>()
.build() .build()
} }