2020-01-09 16:23:20 +00:00
|
|
|
use super::utils::*;
|
2020-01-12 23:06:52 +00:00
|
|
|
use crate::comp::{EcsStateData, StateUpdate};
|
|
|
|
use crate::states::StateHandler;
|
2019-12-26 14:43:59 +00:00
|
|
|
use std::time::Duration;
|
2019-12-26 18:01:19 +00:00
|
|
|
use vek::Vec2;
|
2019-12-26 14:43:59 +00:00
|
|
|
|
2020-01-07 15:49:08 +00:00
|
|
|
const BLOCK_ACCEL: f32 = 30.0;
|
|
|
|
const BLOCK_SPEED: f32 = 75.0;
|
|
|
|
|
2020-01-05 18:19:09 +00:00
|
|
|
#[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
2020-01-08 16:56:36 +00:00
|
|
|
pub struct State {
|
2019-12-26 14:43:59 +00:00
|
|
|
/// How long the blocking state has been active
|
2019-12-30 13:56:42 +00:00
|
|
|
pub active_duration: Duration,
|
2019-12-26 14:43:59 +00:00
|
|
|
}
|
|
|
|
|
2020-01-08 16:56:36 +00:00
|
|
|
impl StateHandler for State {
|
2020-01-07 15:49:08 +00:00
|
|
|
fn new(_ecs_data: &EcsStateData) -> Self {
|
2020-01-05 23:17:22 +00:00
|
|
|
Self {
|
|
|
|
active_duration: Duration::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-28 16:10:39 +00:00
|
|
|
fn handle(&self, ecs_data: &EcsStateData) -> StateUpdate {
|
|
|
|
let mut update = StateUpdate {
|
2019-12-26 14:43:59 +00:00
|
|
|
pos: *ecs_data.pos,
|
|
|
|
vel: *ecs_data.vel,
|
|
|
|
ori: *ecs_data.ori,
|
|
|
|
character: *ecs_data.character,
|
|
|
|
};
|
2019-12-26 18:01:19 +00:00
|
|
|
|
|
|
|
// TODO: Apply simple move speed debuff instead
|
|
|
|
|
|
|
|
// Update movement
|
|
|
|
update.vel.0 += Vec2::broadcast(ecs_data.dt.0)
|
|
|
|
* ecs_data.inputs.move_dir
|
|
|
|
* match ecs_data.physics.on_ground {
|
|
|
|
true if update.vel.0.magnitude_squared() < BLOCK_SPEED.powf(2.0) => BLOCK_ACCEL,
|
|
|
|
_ => 0.0,
|
|
|
|
};
|
|
|
|
|
|
|
|
if !ecs_data.inputs.secondary.is_pressed() {
|
2019-12-28 16:10:39 +00:00
|
|
|
update.character.action_state = attempt_wield(ecs_data.stats);
|
2019-12-26 18:01:19 +00:00
|
|
|
return update;
|
|
|
|
}
|
|
|
|
|
|
|
|
return update;
|
2019-12-26 14:43:59 +00:00
|
|
|
}
|
|
|
|
}
|