finish movment states handle() fn logic

This commit is contained in:
AdamWhitehurst 2019-12-22 08:08:48 -08:00
parent 1ab09220b0
commit c2ceabea0e
8 changed files with 930 additions and 417 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -10,17 +10,29 @@ use std::time::Duration;
pub struct RunData;
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct StandData;
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct SitData;
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct JumpData;
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct FallData;
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct GlideData;
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct SwimData;
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub struct ClimbData;
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
pub enum MovementState {
Stand(StandData),
Sit,
Run(RunData),
Jump,
Fall,
Glide,
Swim,
Climb,
Sit(SitData),
Jump(JumpData),
Fall(FallData),
Glide(GlideData),
Swim(SwimData),
Climb(ClimbData),
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
@ -122,7 +134,7 @@ impl CharacterState {
impl Default for CharacterState {
fn default() -> Self {
Self {
movement: MovementState::Jump,
movement: MovementState::Fall(FallData),
action: ActionState::Idle,
}
}

View File

@ -20,7 +20,10 @@ pub use body::{
biped_large, bird_medium, bird_small, dragon, fish_medium, fish_small, humanoid, object,
quadruped_medium, quadruped_small, Body,
};
pub use character_state::{ActionState, CharacterState, MovementState, RunData, StandData};
pub use character_state::{
ActionState, CharacterState, ClimbData, FallData, GlideData, JumpData, MovementState, RunData,
SitData, StandData, SwimData,
};
pub use controller::{
ControlEvent, Controller, ControllerInputs, Input, InputState, InventoryManip, MountState,
Mounting,

View File

@ -1,6 +1,6 @@
use crate::comp::{
Agent, CharacterState, Controller, ControllerInputs, MountState, MovementState::Glide, Pos,
Stats,
Agent, CharacterState, Controller, ControllerInputs, GlideData, MountState,
MovementState::Glide, Pos, Stats,
};
use crate::pathfinding::WorldPath;
use crate::terrain::TerrainGrid;
@ -163,7 +163,8 @@ impl<'a> System<'a> for Sys {
inputs.roll.set_state(true);
}
if target_character.movement == Glide && target_pos.0.z > pos.0.z + 5.0
if target_character.movement == Glide(GlideData)
&& target_pos.0.z > pos.0.z + 5.0
{
inputs.glide.set_state(true);
inputs.jump.set_state(true);

File diff suppressed because it is too large Load Diff

View File

@ -106,131 +106,131 @@ impl<'a> System<'a> for Sys {
)
.join()
{
if character.movement == Run(RunData) || character.movement == Stand(StandData) {
continue;
}
// if character.movement == Run(RunData) || character.movement == Stand(StandData) {
// continue;
// }
if stats.is_dead {
continue;
}
// if stats.is_dead {
// continue;
// }
if mount.is_some() {
continue;
}
// if mount.is_some() {
// continue;
// }
let inputs = &controller.inputs;
// let inputs = &controller.inputs;
if character.action.is_roll() {
vel.0 = Vec3::new(0.0, 0.0, vel.0.z)
+ (vel.0 * Vec3::new(1.0, 1.0, 0.0)
+ 1.5 * inputs.move_dir.try_normalized().unwrap_or_default())
.try_normalized()
.unwrap_or_default()
* ROLL_SPEED;
} else if character.action.is_charge() {
vel.0 = Vec3::new(0.0, 0.0, vel.0.z)
+ (vel.0 * Vec3::new(1.0, 1.0, 0.0)
+ 1.5 * inputs.move_dir.try_normalized().unwrap_or_default())
.try_normalized()
.unwrap_or_default()
* CHARGE_SPEED;
} else if character.action.is_block() {
vel.0 += Vec2::broadcast(dt.0)
* inputs.move_dir
* match physics.on_ground {
true if vel.0.magnitude_squared() < BLOCK_SPEED.powf(2.0) => BLOCK_ACCEL,
_ => 0.0,
}
} else {
// Move player according to move_dir
vel.0 += Vec2::broadcast(dt.0)
* inputs.move_dir
* match (physics.on_ground, &character.movement) {
(true, Run(_)) if vel.0.magnitude_squared() < HUMANOID_SPEED.powf(2.0) => {
HUMANOID_ACCEL
}
(false, Climb) if vel.0.magnitude_squared() < HUMANOID_SPEED.powf(2.0) => {
HUMANOID_CLIMB_ACCEL
}
(false, Glide) if vel.0.magnitude_squared() < GLIDE_SPEED.powf(2.0) => {
GLIDE_ACCEL
}
(false, Fall) | (false, Jump)
if vel.0.magnitude_squared() < HUMANOID_AIR_SPEED.powf(2.0) =>
{
HUMANOID_AIR_ACCEL
}
(false, Swim)
if vel.0.magnitude_squared() < HUMANOID_WATER_SPEED.powf(2.0) =>
{
HUMANOID_WATER_ACCEL
}
_ => 0.0,
};
}
// if character.action.is_roll() {
// vel.0 = Vec3::new(0.0, 0.0, vel.0.z)
// + (vel.0 * Vec3::new(1.0, 1.0, 0.0)
// + 1.5 * inputs.move_dir.try_normalized().unwrap_or_default())
// .try_normalized()
// .unwrap_or_default()
// * ROLL_SPEED;
// } else if character.action.is_charge() {
// vel.0 = Vec3::new(0.0, 0.0, vel.0.z)
// + (vel.0 * Vec3::new(1.0, 1.0, 0.0)
// + 1.5 * inputs.move_dir.try_normalized().unwrap_or_default())
// .try_normalized()
// .unwrap_or_default()
// * CHARGE_SPEED;
// } else if character.action.is_block() {
// vel.0 += Vec2::broadcast(dt.0)
// * inputs.move_dir
// * match physics.on_ground {
// true if vel.0.magnitude_squared() < BLOCK_SPEED.powf(2.0) => BLOCK_ACCEL,
// _ => 0.0,
// }
// } else {
// // Move player according to move_dir
// vel.0 += Vec2::broadcast(dt.0)
// * inputs.move_dir
// * match (physics.on_ground, &character.movement) {
// (true, Run(_)) if vel.0.magnitude_squared() < HUMANOID_SPEED.powf(2.0) => {
// HUMANOID_ACCEL
// }
// (false, Climb) if vel.0.magnitude_squared() < HUMANOID_SPEED.powf(2.0) => {
// HUMANOID_CLIMB_ACCEL
// }
// (false, Glide) if vel.0.magnitude_squared() < GLIDE_SPEED.powf(2.0) => {
// GLIDE_ACCEL
// }
// (false, Fall) | (false, Jump)
// if vel.0.magnitude_squared() < HUMANOID_AIR_SPEED.powf(2.0) =>
// {
// HUMANOID_AIR_ACCEL
// }
// (false, Swim)
// if vel.0.magnitude_squared() < HUMANOID_WATER_SPEED.powf(2.0) =>
// {
// HUMANOID_WATER_ACCEL
// }
// _ => 0.0,
// };
// }
// Set direction based on move direction when on the ground
let ori_dir = if
//character.action.is_wield() ||
character.action.is_attack() || character.action.is_block() {
Vec2::from(inputs.look_dir).normalized()
} else if let (Climb, Some(wall_dir)) = (character.movement, physics.on_wall) {
if Vec2::<f32>::from(wall_dir).magnitude_squared() > 0.001 {
Vec2::from(wall_dir).normalized()
} else {
Vec2::from(vel.0)
}
} else {
Vec2::from(vel.0)
};
// // Set direction based on move direction when on the ground
// let ori_dir = if
// //character.action.is_wield() ||
// character.action.is_attack() || character.action.is_block() {
// Vec2::from(inputs.look_dir).normalized()
// } else if let (Climb, Some(wall_dir)) = (character.movement, physics.on_wall) {
// if Vec2::<f32>::from(wall_dir).magnitude_squared() > 0.001 {
// Vec2::from(wall_dir).normalized()
// } else {
// Vec2::from(vel.0)
// }
// } else {
// Vec2::from(vel.0)
// };
if ori_dir.magnitude_squared() > 0.0001
&& (ori.0.normalized() - Vec3::from(ori_dir).normalized()).magnitude_squared()
> 0.001
{
ori.0 = vek::ops::Slerp::slerp(
ori.0,
ori_dir.into(),
if physics.on_ground { 9.0 } else { 2.0 } * dt.0,
);
}
// if ori_dir.magnitude_squared() > 0.0001
// && (ori.0.normalized() - Vec3::from(ori_dir).normalized()).magnitude_squared()
// > 0.001
// {
// ori.0 = vek::ops::Slerp::slerp(
// ori.0,
// ori_dir.into(),
// if physics.on_ground { 9.0 } else { 2.0 } * dt.0,
// );
// }
// Glide
if character.movement == Glide
&& Vec2::<f32>::from(vel.0).magnitude_squared() < GLIDE_SPEED.powf(2.0)
&& vel.0.z < 0.0
{
let lift = GLIDE_ANTIGRAV + vel.0.z.abs().powf(2.0) * 0.15;
vel.0.z += dt.0
* lift
* (Vec2::<f32>::from(vel.0).magnitude() * 0.075)
.min(1.0)
.max(0.2);
}
// // Glide
// if character.movement == Glide
// && Vec2::<f32>::from(vel.0).magnitude_squared() < GLIDE_SPEED.powf(2.0)
// && vel.0.z < 0.0
// {
// let lift = GLIDE_ANTIGRAV + vel.0.z.abs().powf(2.0) * 0.15;
// vel.0.z += dt.0
// * lift
// * (Vec2::<f32>::from(vel.0).magnitude() * 0.075)
// .min(1.0)
// .max(0.2);
// }
// Climb
if let (true, Some(_wall_dir)) = (
(inputs.climb.is_pressed() | inputs.climb_down.is_pressed())
&& vel.0.z <= CLIMB_SPEED,
physics.on_wall,
) {
if inputs.climb_down.is_pressed() && !inputs.climb.is_pressed() {
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() {
vel.0.z = (vel.0.z + dt.0 * GRAVITY * 1.25).min(CLIMB_SPEED);
} else {
vel.0.z = vel.0.z + dt.0 * GRAVITY * 1.5;
vel.0 = Lerp::lerp(
vel.0,
Vec3::zero(),
30.0 * dt.0 / (1.0 - vel.0.z.min(0.0) * 5.0),
);
}
}
// // Climb
// if let (true, Some(_wall_dir)) = (
// (inputs.climb.is_pressed() | inputs.climb_down.is_pressed())
// && vel.0.z <= CLIMB_SPEED,
// physics.on_wall,
// ) {
// if inputs.climb_down.is_pressed() && !inputs.climb.is_pressed() {
// 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() {
// vel.0.z = (vel.0.z + dt.0 * GRAVITY * 1.25).min(CLIMB_SPEED);
// } else {
// vel.0.z = vel.0.z + dt.0 * GRAVITY * 1.5;
// vel.0 = Lerp::lerp(
// vel.0,
// Vec3::zero(),
// 30.0 * dt.0 / (1.0 - vel.0.z.min(0.0) * 5.0),
// );
// }
// }
if character.movement == Swim && inputs.jump.is_pressed() {
vel.0.z = (vel.0.z + dt.0 * GRAVITY * 1.25).min(HUMANOID_WATER_SPEED);
}
// if character.movement == Swim && inputs.jump.is_pressed() {
// vel.0.z = (vel.0.z + dt.0 * GRAVITY * 1.25).min(HUMANOID_WATER_SPEED);
// }
}
}
}

View File

@ -160,17 +160,17 @@ impl SfxEventMapper {
stats,
) {
(_, ActionState::Roll { .. }, ..) => SfxEvent::Roll,
(MovementState::Climb, ..) => SfxEvent::Climb,
(MovementState::Swim, ..) => SfxEvent::Swim,
(MovementState::Climb(_), ..) => SfxEvent::Climb,
(MovementState::Swim(_), ..) => SfxEvent::Swim,
(MovementState::Run(_), ..) => SfxEvent::Run,
(MovementState::Fall, _, previous_event, _) => {
(MovementState::Fall(_), _, previous_event, _) => {
if previous_event != SfxEvent::Glide {
SfxEvent::Fall
} else {
SfxEvent::GliderClose
}
}
(MovementState::Glide, _, previous_event, ..) => {
(MovementState::Glide(_), _, previous_event, ..) => {
if previous_event != SfxEvent::GliderOpen && previous_event != SfxEvent::Glide {
SfxEvent::GliderOpen
} else {

View File

@ -211,35 +211,35 @@ impl FigureMgr {
&mut movement_animation_rate,
skeleton_attr,
),
Jump | Fall => anim::character::JumpAnimation::update_skeleton(
Jump(_) | Fall(_) => anim::character::JumpAnimation::update_skeleton(
&CharacterSkeleton::new(),
(active_tool_kind, time),
state.movement_time,
&mut movement_animation_rate,
skeleton_attr,
),
Glide => anim::character::GlidingAnimation::update_skeleton(
Glide(_) => anim::character::GlidingAnimation::update_skeleton(
&CharacterSkeleton::new(),
(active_tool_kind, vel.0, ori.0, state.last_ori, time),
state.movement_time,
&mut movement_animation_rate,
skeleton_attr,
),
Swim => anim::character::SwimAnimation::update_skeleton(
Swim(_) => anim::character::SwimAnimation::update_skeleton(
&CharacterSkeleton::new(),
(active_tool_kind, vel.0.magnitude(), ori.0.magnitude(), time),
state.movement_time,
&mut movement_animation_rate,
skeleton_attr,
),
Climb => anim::character::ClimbAnimation::update_skeleton(
Climb(_) => anim::character::ClimbAnimation::update_skeleton(
&CharacterSkeleton::new(),
(active_tool_kind, vel.0, ori.0, time),
state.movement_time,
&mut movement_animation_rate,
skeleton_attr,
),
Sit => anim::character::SitAnimation::update_skeleton(
Sit(_) => anim::character::SitAnimation::update_skeleton(
&CharacterSkeleton::new(),
(active_tool_kind, time),
state.movement_time,
@ -349,7 +349,7 @@ impl FigureMgr {
&mut movement_animation_rate,
skeleton_attr,
),
Jump => anim::quadruped_small::JumpAnimation::update_skeleton(
Jump(_) => anim::quadruped_small::JumpAnimation::update_skeleton(
&QuadrupedSmallSkeleton::new(),
(vel.0.magnitude(), time),
state.movement_time,
@ -406,7 +406,7 @@ impl FigureMgr {
&mut movement_animation_rate,
skeleton_attr,
),
Jump => anim::quadruped_medium::JumpAnimation::update_skeleton(
Jump(_) => anim::quadruped_medium::JumpAnimation::update_skeleton(
&QuadrupedMediumSkeleton::new(),
(vel.0.magnitude(), time),
state.movement_time,
@ -461,7 +461,7 @@ impl FigureMgr {
&mut movement_animation_rate,
skeleton_attr,
),
Jump => anim::bird_medium::JumpAnimation::update_skeleton(
Jump(_) => anim::bird_medium::JumpAnimation::update_skeleton(
&BirdMediumSkeleton::new(),
(vel.0.magnitude(), time),
state.movement_time,
@ -516,7 +516,7 @@ impl FigureMgr {
&mut movement_animation_rate,
skeleton_attr,
),
Jump => anim::fish_medium::JumpAnimation::update_skeleton(
Jump(_) => anim::fish_medium::JumpAnimation::update_skeleton(
&FishMediumSkeleton::new(),
(vel.0.magnitude(), time),
state.movement_time,
@ -571,7 +571,7 @@ impl FigureMgr {
&mut movement_animation_rate,
skeleton_attr,
),
Jump => anim::dragon::JumpAnimation::update_skeleton(
Jump(_) => anim::dragon::JumpAnimation::update_skeleton(
&DragonSkeleton::new(),
(vel.0.magnitude(), time),
state.movement_time,
@ -626,7 +626,7 @@ impl FigureMgr {
&mut movement_animation_rate,
skeleton_attr,
),
Jump => anim::bird_small::JumpAnimation::update_skeleton(
Jump(_) => anim::bird_small::JumpAnimation::update_skeleton(
&BirdSmallSkeleton::new(),
(vel.0.magnitude(), time),
state.movement_time,
@ -681,7 +681,7 @@ impl FigureMgr {
&mut movement_animation_rate,
skeleton_attr,
),
Jump => anim::fish_small::JumpAnimation::update_skeleton(
Jump(_) => anim::fish_small::JumpAnimation::update_skeleton(
&FishSmallSkeleton::new(),
(vel.0.magnitude(), time),
state.movement_time,
@ -736,7 +736,7 @@ impl FigureMgr {
&mut movement_animation_rate,
skeleton_attr,
),
Jump => anim::biped_large::JumpAnimation::update_skeleton(
Jump(_) => anim::biped_large::JumpAnimation::update_skeleton(
&BipedLargeSkeleton::new(),
(vel.0.magnitude(), time),
state.movement_time,