mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Swim pulsing
This commit is contained in:
@ -69,6 +69,11 @@ impl Input {
|
|||||||
(self.is_pressed() && self.duration >= DEFAULT_HOLD_DURATION)
|
(self.is_pressed() && self.duration >= DEFAULT_HOLD_DURATION)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Whether input has been pressed for longer than `threshold`
|
||||||
|
pub fn is_long_press(&self, threshold: Duration) -> bool {
|
||||||
|
(self.is_pressed() && self.duration >= threshold)
|
||||||
|
}
|
||||||
|
|
||||||
/// Handles logic of updating state of Input
|
/// Handles logic of updating state of Input
|
||||||
pub fn set_state(&mut self, new_state: bool) {
|
pub fn set_state(&mut self, new_state: bool) {
|
||||||
// Only update if state switches
|
// Only update if state switches
|
||||||
|
@ -47,11 +47,8 @@ use super::{
|
|||||||
///
|
///
|
||||||
/// ## Example Implementation:
|
/// ## Example Implementation:
|
||||||
/// ```
|
/// ```
|
||||||
/// use crate::comp::{
|
/// use crate::util::state_utils::*;
|
||||||
/// ClimbState, EcsStateData, GlideState, JumpState, MoveState::*, SitState, StateHandler,
|
///
|
||||||
/// StateUpdate,
|
|
||||||
/// };
|
|
||||||
/// use crate::util::state_utils::*
|
|
||||||
/// #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
/// #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
||||||
/// pub struct RunState {
|
/// pub struct RunState {
|
||||||
/// active_duration: Duration,
|
/// active_duration: Duration,
|
||||||
@ -72,7 +69,7 @@ use super::{
|
|||||||
/// ori: *ecs_data.ori,
|
/// ori: *ecs_data.ori,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// // Move player according to move_dir
|
/// // Update player's Vel
|
||||||
/// update.vel.0 += Vec2::broadcast(ecs_data.dt.0)
|
/// update.vel.0 += Vec2::broadcast(ecs_data.dt.0)
|
||||||
/// * ecs_data.inputs.move_dir
|
/// * ecs_data.inputs.move_dir
|
||||||
/// * if update.vel.0.magnitude_squared() < HUMANOID_SPEED.powf(2.0) {
|
/// * if update.vel.0.magnitude_squared() < HUMANOID_SPEED.powf(2.0) {
|
||||||
@ -81,50 +78,18 @@ use super::{
|
|||||||
/// 0.0
|
/// 0.0
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// // Set direction based on move direction when on the ground
|
/// // -- snip --
|
||||||
/// let ori_dir = if update.character.action_state.is_attacking()
|
/// // Other updates; checks for gliding, climbing, etc.
|
||||||
/// || update.character.action_state.is_blocking()
|
|
||||||
/// {
|
|
||||||
/// Vec2::from(ecs_data.inputs.look_dir).normalized()
|
|
||||||
/// } else {
|
|
||||||
/// Vec2::from(update.vel.0)
|
|
||||||
/// };
|
|
||||||
///
|
|
||||||
/// if ori_dir.magnitude_squared() > 0.0001
|
|
||||||
/// && (update.ori.0.normalized() - Vec3::from(ori_dir).normalized()).magnitude_squared()
|
|
||||||
/// > 0.001
|
|
||||||
/// {
|
|
||||||
/// update.ori.0 =
|
|
||||||
/// vek::ops::Slerp::slerp(update.ori.0, ori_dir.into(), 9.0 * ecs_data.dt.0);
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// // Try to sit
|
|
||||||
/// if can_sit(ecs_data.physics, ecs_data.inputs, ecs_data.body) {
|
|
||||||
/// update.character.move_state = Sit(Some(SitState));
|
|
||||||
/// return update;
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// // Try to climb
|
|
||||||
/// if can_climb(ecs_data.physics, ecs_data.inputs, ecs_data.body) {
|
|
||||||
/// update.character.move_state = Climb(Some(ClimbState));
|
|
||||||
/// return update;
|
|
||||||
/// }
|
|
||||||
///
|
///
|
||||||
/// // Try to jump
|
/// // Try to jump
|
||||||
/// if can_jump(ecs_data.physics, ecs_data.inputs) {
|
/// if state_utils::can_jump(ecs_data.physics, ecs_data.inputs) {
|
||||||
/// update.character.move_state = Jump(Some(JumpState));
|
/// update.character.move_state = Jump(None);
|
||||||
/// return update;
|
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// // Try to glide
|
|
||||||
/// if can_glide(ecs_data.physics, ecs_data.inputs, ecs_data.body) {
|
|
||||||
/// update.character.move_state = Glide(Some(GlideState));
|
|
||||||
/// return update;
|
/// return update;
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// // Update based on groundedness
|
/// // Update based on groundedness
|
||||||
/// update.character.move_state =
|
/// update.character.move_state =
|
||||||
/// determine_move_from_grounded_state(ecs_data.physics, ecs_data.inputs);
|
/// state_utils::determine_move_from_grounded_state(ecs_data.physics, ecs_data.inputs);
|
||||||
///
|
///
|
||||||
/// return update;
|
/// return update;
|
||||||
/// }
|
/// }
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::comp::{EcsStateData, MoveState::*, StateHandler, StateUpdate};
|
use crate::comp::{EcsStateData, MoveState::*, StateHandler, StateUpdate};
|
||||||
use crate::sys::phys::GRAVITY;
|
use crate::sys::phys::GRAVITY;
|
||||||
|
use std::time::Duration;
|
||||||
use vek::{Vec2, Vec3};
|
use vek::{Vec2, Vec3};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
#[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
||||||
@ -50,7 +51,13 @@ impl StateHandler for SwimState {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ecs_data.inputs.jump.is_pressed() && !ecs_data.inputs.jump.is_held_down() {
|
// Force players to press jump in a slow rhythmic fashion to swim up
|
||||||
|
if ecs_data.inputs.jump.is_pressed()
|
||||||
|
&& !ecs_data
|
||||||
|
.inputs
|
||||||
|
.jump
|
||||||
|
.is_long_press(Duration::from_millis(600))
|
||||||
|
{
|
||||||
update.vel.0.z =
|
update.vel.0.z =
|
||||||
(update.vel.0.z + ecs_data.dt.0 * GRAVITY * 1.25).min(HUMANOID_WATER_SPEED);
|
(update.vel.0.z + ecs_data.dt.0 * GRAVITY * 1.25).min(HUMANOID_WATER_SPEED);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user