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

View File

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