Use correct time

Former-commit-id: df33e802ee46f9ebe190be705ff8d81f856024e0
This commit is contained in:
timokoesters 2019-05-19 19:58:32 +02:00
parent 449b717777
commit fc39356cde
3 changed files with 9 additions and 7 deletions

View File

@ -1,16 +1,17 @@
use specs::{Component, FlaggedStorage, NullStorage, VecStorage};
use crate::state::Time;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Health {
pub current: u32,
pub maximum: u32,
pub last_change: Option<(i32, f64)>,
pub last_change: Option<(i32, Time)>,
}
impl Health {
pub fn change_by(&mut self, amount: i32, current_time: f64) {
pub fn change_by(&mut self, amount: i32, current_time: Time) {
self.current = (self.current as i32 + amount).max(0) as u32;
self.last_change = Some((amount, current_time));
self.last_change = dbg!(Some((amount, current_time)));
}
}

View File

@ -28,7 +28,7 @@ const DAY_CYCLE_FACTOR: f64 = 24.0 * 60.0;
pub struct TimeOfDay(f64);
/// A resource that stores the tick (i.e: physics) time.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
pub struct Time(f64);
/// A resource that stores the time since the previous tick.

View File

@ -5,7 +5,7 @@ use vek::*;
// Crate
use crate::{
comp::{phys::Pos, Action, Actions, Control, Stats},
state::DeltaTime,
state::{Time, DeltaTime},
};
// Basic ECS AI agent system
@ -14,13 +14,14 @@ pub struct Sys;
impl<'a> System<'a> for Sys {
type SystemData = (
Entities<'a>,
Read<'a, Time>,
Read<'a, DeltaTime>,
WriteStorage<'a, Actions>,
ReadStorage<'a, Pos>,
WriteStorage<'a, Stats>,
);
fn run(&mut self, (entities, dt, mut actions, positions, mut stats): Self::SystemData) {
fn run(&mut self, (entities, time, dt, mut actions, positions, mut stats): Self::SystemData) {
for (a, mut actions_a, pos_a) in (&entities, &mut actions, &positions).join() {
for event in actions_a.0.drain(..) {
match event {
@ -30,7 +31,7 @@ impl<'a> System<'a> for Sys {
continue;
}
if pos_a.0.distance_squared(pos_b.0) < 50.0 {
&mut stat_b.hp.change_by(-60, 0.0); // TODO: variable damage and current time
&mut stat_b.hp.change_by(-60, *time); // TODO: variable damage
&stat_b.hp;
}
}