Update common/src/sys/controller.rs, common/src/sys/movement.rs, common/src/comp/energy.rs files

This commit is contained in:
Ben Simpson 2020-02-13 08:36:29 +00:00
parent bfd2f345b1
commit 3343f8e5c0
2 changed files with 25 additions and 25 deletions

View File

@ -19,7 +19,6 @@ use vek::*;
const CHARGE_COST: i32 = 200;
const ROLL_COST: i32 = 30;
/// # Controller System
/// #### Responsible for validating controller inputs and setting new Character
/// States ----
@ -570,15 +569,15 @@ impl<'a> System<'a> for Sys {
}
// Try to climb
if let (true, Some(_wall_dir)) = (
if let (true, Some(_wall_dir)) = (
(inputs.climb.is_pressed() | inputs.climb_down.is_pressed())
&& can_climb(body),
physics.on_wall,)
{
character.movement = Climb;
continue;
}
physics.on_wall,
) {
character.movement = Climb;
continue;
}
// Try to swim
if !physics.on_ground {
@ -607,7 +606,6 @@ impl<'a> System<'a> for Sys {
character.action = Charge {
time_left: Duration::from_millis(250),
};
}
continue;
}
@ -622,10 +620,10 @@ impl<'a> System<'a> for Sys {
.try_change_by(-ROLL_COST, EnergySource::Roll)
.is_ok()
{
character.action = Roll {
time_left: ROLL_DURATION,
was_wielding: character.action.is_wield(),
};
character.action = Roll {
time_left: ROLL_DURATION,
was_wielding: character.action.is_wield(),
};
}
continue;
}

View File

@ -1,8 +1,8 @@
use super::phys::GRAVITY;
use crate::{
comp::{
ActionState, CharacterState, Controller, Mounting, MovementState::*, Ori, PhysicsState,
Pos, Stats, Vel, Energy, EnergySource
ActionState, CharacterState, Controller, Energy, EnergySource, Mounting, MovementState::*,
Ori, PhysicsState, Pos, Stats, Vel,
},
event::{EventBus, ServerEvent},
state::DeltaTime,
@ -232,20 +232,22 @@ impl<'a> System<'a> for Sys {
character.movement == Climb && vel.0.z <= CLIMB_SPEED,
physics.on_wall,
) {
if inputs.climb_down.is_pressed() && !inputs.climb.is_pressed() && energy
.get_mut_unchecked()
.try_change_by(-CLIMB_COST, EnergySource::Climb)
.is_ok()
{
vel.0 -= dt.0 * vel.0.map(|e| e.abs().powf(1.5) * e.signum() * 6.0);
}
} else if inputs.climb.is_pressed() && !inputs.climb_down.is_pressed() && energy
if inputs.climb_down.is_pressed() && !inputs.climb.is_pressed() {
if energy
.get_mut_unchecked()
.try_change_by(-CLIMB_COST, EnergySource::Climb)
.is_ok()
{
{
vel.0 -= dt.0 * vel.0.map(|e| e.abs().powf(1.5) * e.signum() * 6.0);
}
} else if inputs.climb.is_pressed() && !inputs.climb_down.is_pressed() {
if energy
.get_mut_unchecked()
.try_change_by(-CLIMB_COST, EnergySource::Climb)
.is_ok()
{
vel.0.z = (vel.0.z + dt.0 * GRAVITY * 1.25).min(CLIMB_SPEED).max(0.0);
}
} else {
vel.0.z = (vel.0.z - dt.0 * GRAVITY * 0.01).min(CLIMB_SPEED);
}