Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac0216ff00 |
@@ -1,6 +1,3 @@
|
|||||||
use crate::fighter::state::ground::GroundedStateCommon;
|
|
||||||
use crate::fighter::state::land::{LandingState, LandingType};
|
|
||||||
use crate::fighter::state::{CollisionContext, FighterState};
|
|
||||||
use crate::fighter::*;
|
use crate::fighter::*;
|
||||||
|
|
||||||
pub fn integrate_gravity(velocity: &mut FighterVelocity, attributes: &FighterAttributes) {
|
pub fn integrate_gravity(velocity: &mut FighterVelocity, attributes: &FighterAttributes) {
|
||||||
@@ -56,27 +53,6 @@ pub fn apply_air_motion(
|
|||||||
translation.0 += velocity.0;
|
translation.0 += velocity.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_standard_motion(ctx: &mut crate::fighter::state::UpdateContext) {
|
|
||||||
integrate_gravity(ctx.velocity, ctx.fighter_attributes);
|
|
||||||
apply_air_drift(ctx.velocity, ctx.fighter_attributes, ctx.input);
|
|
||||||
apply_air_motion(ctx.velocity, ctx.translation, ctx.prev_translation);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn collision_interrupt(
|
|
||||||
ctx: &mut CollisionContext,
|
|
||||||
landing_type: LandingType,
|
|
||||||
) -> Option<FighterState> {
|
|
||||||
let res = ctx.air_collide_with_stage()?;
|
|
||||||
ctx.translation.0 = res.hit_position - ctx.ecb.get_bottom_point();
|
|
||||||
let grounded_common = GroundedStateCommon {
|
|
||||||
current_line_id: res.line_id,
|
|
||||||
};
|
|
||||||
Some(FighterState::Land(LandingState::create(
|
|
||||||
grounded_common,
|
|
||||||
landing_type,
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ use crate::{
|
|||||||
animation::AnimKind,
|
animation::AnimKind,
|
||||||
state::{
|
state::{
|
||||||
CollisionContext, EnterContext, FighterState, FighterStateImpl, InterruptContext,
|
CollisionContext, EnterContext, FighterState, FighterStateImpl, InterruptContext,
|
||||||
UpdateContext, air, fall::FallState, land::LandingType,
|
UpdateContext, air,
|
||||||
|
fall::FallState,
|
||||||
|
ground::GroundedStateCommon,
|
||||||
|
land::{LandingState, LandingType},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
input,
|
input,
|
||||||
@@ -40,7 +43,19 @@ impl FighterStateImpl for AirDodgeState {
|
|||||||
&mut self,
|
&mut self,
|
||||||
state_context: &mut CollisionContext,
|
state_context: &mut CollisionContext,
|
||||||
) -> Option<FighterState> {
|
) -> Option<FighterState> {
|
||||||
air::collision_interrupt(state_context, LandingType::Special)
|
if let Some(res) = state_context.air_collide_with_stage() {
|
||||||
|
// Adjust translation
|
||||||
|
state_context.translation.0 = res.hit_position - state_context.ecb.get_bottom_point();
|
||||||
|
let grounded_common = GroundedStateCommon {
|
||||||
|
current_line_id: res.line_id,
|
||||||
|
};
|
||||||
|
Some(FighterState::Land(LandingState {
|
||||||
|
grounded_common,
|
||||||
|
landing_type: LandingType::Special,
|
||||||
|
}))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ use super::{
|
|||||||
use crate::fighter::FighterFacingDirection;
|
use crate::fighter::FighterFacingDirection;
|
||||||
use crate::fighter::animation::AnimKind;
|
use crate::fighter::animation::AnimKind;
|
||||||
use crate::fighter::state::FighterState;
|
use crate::fighter::state::FighterState;
|
||||||
use crate::fighter::state::ground::GroundedStateCommon;
|
use crate::fighter::state::fall::FallState;
|
||||||
|
use crate::fighter::state::ground::{GroundedMotionResult, GroundedStateCommon};
|
||||||
use crate::input::FighterCommands::{SmashMoveLeft, SmashMoveRight};
|
use crate::input::FighterCommands::{SmashMoveLeft, SmashMoveRight};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash)]
|
#[derive(Debug, Clone, Hash)]
|
||||||
@@ -106,7 +107,13 @@ impl FighterStateImpl for DashState {
|
|||||||
&mut self,
|
&mut self,
|
||||||
state_context: &mut CollisionContext,
|
state_context: &mut CollisionContext,
|
||||||
) -> Option<FighterState> {
|
) -> Option<FighterState> {
|
||||||
ground::collision_interrupt(state_context, &mut self.ground_common, true)
|
if let GroundedMotionResult::InAir =
|
||||||
|
ground::collide_with_stage_grounded(state_context, &mut self.ground_common, true)
|
||||||
|
{
|
||||||
|
Some(FighterState::Fall(FallState))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use super::{CollisionContext, EnterContext, FighterStateImpl, InterruptContext, UpdateContext};
|
use super::{CollisionContext, EnterContext, FighterStateImpl, InterruptContext, UpdateContext};
|
||||||
use crate::fighter::animation::AnimKind;
|
use crate::fighter::animation::AnimKind;
|
||||||
|
use crate::fighter::state::ground::GroundedStateCommon;
|
||||||
|
use crate::fighter::state::land::{LandingState, LandingType};
|
||||||
use crate::fighter::state::{FighterState, air, jump};
|
use crate::fighter::state::{FighterState, air, jump};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Hash)]
|
#[derive(Debug, Clone, Copy, Hash)]
|
||||||
@@ -16,17 +18,36 @@ impl FighterStateImpl for FallState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, state_context: &mut UpdateContext) {
|
fn update(&mut self, state_context: &mut UpdateContext) {
|
||||||
air::update_standard_motion(state_context);
|
air::integrate_gravity(state_context.velocity, state_context.fighter_attributes);
|
||||||
|
air::apply_air_drift(
|
||||||
|
state_context.velocity,
|
||||||
|
state_context.fighter_attributes,
|
||||||
|
state_context.input,
|
||||||
|
);
|
||||||
|
air::apply_air_motion(
|
||||||
|
state_context.velocity,
|
||||||
|
state_context.translation,
|
||||||
|
state_context.prev_translation,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_collision_interrupt(
|
fn check_collision_interrupt(
|
||||||
&mut self,
|
&mut self,
|
||||||
state_context: &mut CollisionContext,
|
state_context: &mut CollisionContext,
|
||||||
) -> Option<FighterState> {
|
) -> Option<FighterState> {
|
||||||
air::collision_interrupt(
|
if let Some(res) = state_context.air_collide_with_stage() {
|
||||||
state_context,
|
// Adjust translation
|
||||||
crate::fighter::state::land::LandingType::Normal,
|
state_context.translation.0 = res.hit_position - state_context.ecb.get_bottom_point();
|
||||||
)
|
let grounded_common = GroundedStateCommon {
|
||||||
|
current_line_id: res.line_id,
|
||||||
|
};
|
||||||
|
Some(FighterState::Land(LandingState::create(
|
||||||
|
grounded_common,
|
||||||
|
LandingType::Normal,
|
||||||
|
)))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
//! bit-for-bit deterministic for rollback.
|
//! bit-for-bit deterministic for rollback.
|
||||||
|
|
||||||
use crate::fighter::state::{
|
use crate::fighter::state::{
|
||||||
CollisionContext, FighterState, InterruptContext, dash, fall, ground_attack, turn, wait, walk,
|
CollisionContext, FighterState, InterruptContext, dash, ground_attack, turn, wait, walk,
|
||||||
};
|
};
|
||||||
use crate::fighter::{
|
use crate::fighter::{
|
||||||
FighterAttributes, FighterPreviousTranslation, FighterTranslation, FighterVelocity,
|
FighterAttributes, FighterPreviousTranslation, FighterTranslation, FighterVelocity,
|
||||||
@@ -163,22 +163,6 @@ pub fn apply_grounded_motion(
|
|||||||
translation.0 += FGVec2::new(velocity.0.x, FGi32::ZERO);
|
translation.0 += FGVec2::new(velocity.0.x, FGi32::ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_friction_motion(ctx: &mut crate::fighter::state::UpdateContext) {
|
|
||||||
let friction = if ctx.velocity.x.abs() > ctx.fighter_attributes.max_walk_vel {
|
|
||||||
ctx.fighter_attributes.ground_friction
|
|
||||||
* ctx
|
|
||||||
.game_settings
|
|
||||||
.fighter_common
|
|
||||||
.ground_friction_over_walk_speed_multiplier
|
|
||||||
} else {
|
|
||||||
ctx.fighter_attributes.ground_friction
|
|
||||||
};
|
|
||||||
|
|
||||||
let ground_velocity = ctx.velocity.x;
|
|
||||||
ctx.velocity.x += apply_grounded_friction(friction, ground_velocity);
|
|
||||||
apply_grounded_motion(ctx.velocity, ctx.translation, ctx.prev_translation);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn collide_with_stage_grounded(
|
pub fn collide_with_stage_grounded(
|
||||||
state_context: &mut CollisionContext,
|
state_context: &mut CollisionContext,
|
||||||
ground_common: &mut GroundedStateCommon,
|
ground_common: &mut GroundedStateCommon,
|
||||||
@@ -226,17 +210,6 @@ pub fn collide_with_stage_grounded(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collision_interrupt(
|
|
||||||
ctx: &mut CollisionContext,
|
|
||||||
common: &mut GroundedStateCommon,
|
|
||||||
can_walk_off: bool,
|
|
||||||
) -> Option<FighterState> {
|
|
||||||
match collide_with_stage_grounded(ctx, common, can_walk_off) {
|
|
||||||
GroundedMotionResult::InGround => None,
|
|
||||||
GroundedMotionResult::InAir => Some(FighterState::Fall(fall::FallState)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ use crate::{
|
|||||||
CollisionContext, EnterContext, ExitContext, FighterState, FighterStateImpl,
|
CollisionContext, EnterContext, ExitContext, FighterState, FighterStateImpl,
|
||||||
InterruptContext, UpdateContext, air,
|
InterruptContext, UpdateContext, air,
|
||||||
fall::FallState,
|
fall::FallState,
|
||||||
ground::{GroundedStateCommon, collision_interrupt},
|
ground::{GroundedMotionResult, GroundedStateCommon, collide_with_stage_grounded},
|
||||||
land::LandingType,
|
land::{LandingState, LandingType},
|
||||||
wait::WaitState,
|
wait::WaitState,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -88,10 +88,29 @@ impl FighterStateImpl for HitstunState {
|
|||||||
) -> Option<FighterState> {
|
) -> Option<FighterState> {
|
||||||
match &mut self.hitstop_kind {
|
match &mut self.hitstop_kind {
|
||||||
HitstopStateKind::Grounded(grounded_state_common) => {
|
HitstopStateKind::Grounded(grounded_state_common) => {
|
||||||
collision_interrupt(state_context, grounded_state_common, true)
|
if let GroundedMotionResult::InAir =
|
||||||
|
collide_with_stage_grounded(state_context, grounded_state_common, true)
|
||||||
|
{
|
||||||
|
Some(FighterState::Fall(FallState {}))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
HitstopStateKind::Airborne => {
|
HitstopStateKind::Airborne => {
|
||||||
air::collision_interrupt(state_context, LandingType::Normal)
|
if let Some(res) = state_context.air_collide_with_stage() {
|
||||||
|
// Adjust translation
|
||||||
|
state_context.translation.0 =
|
||||||
|
res.hit_position - state_context.ecb.get_bottom_point();
|
||||||
|
let grounded_common = GroundedStateCommon {
|
||||||
|
current_line_id: res.line_id,
|
||||||
|
};
|
||||||
|
Some(FighterState::Land(LandingState::create(
|
||||||
|
grounded_common,
|
||||||
|
LandingType::Normal,
|
||||||
|
)))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ use crate::{
|
|||||||
CollisionContext, EnterContext, FighterState, FighterStateImpl, InterruptContext,
|
CollisionContext, EnterContext, FighterState, FighterStateImpl, InterruptContext,
|
||||||
UpdateContext, air,
|
UpdateContext, air,
|
||||||
air_dodge::{self, AirDodgeState},
|
air_dodge::{self, AirDodgeState},
|
||||||
ground::{self, GroundedStateCommon},
|
fall::FallState,
|
||||||
|
ground::{self, GroundedMotionResult, GroundedStateCommon},
|
||||||
|
land::{LandingState, LandingType},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
input::FighterCommands,
|
input::FighterCommands,
|
||||||
@@ -82,14 +84,40 @@ impl FighterStateImpl for JumpSquatState {
|
|||||||
|
|
||||||
fn update(&mut self, state_context: &mut UpdateContext) {
|
fn update(&mut self, state_context: &mut UpdateContext) {
|
||||||
self.duration_counter += 1;
|
self.duration_counter += 1;
|
||||||
ground::update_friction_motion(state_context);
|
|
||||||
|
let friction =
|
||||||
|
if state_context.velocity.x.abs() > state_context.fighter_attributes.max_walk_vel {
|
||||||
|
state_context.fighter_attributes.ground_friction
|
||||||
|
* state_context
|
||||||
|
.game_settings
|
||||||
|
.fighter_common
|
||||||
|
.ground_friction_over_walk_speed_multiplier
|
||||||
|
} else {
|
||||||
|
state_context.fighter_attributes.ground_friction
|
||||||
|
};
|
||||||
|
|
||||||
|
let ground_velocity = state_context.velocity.x;
|
||||||
|
|
||||||
|
state_context.velocity.x += ground::apply_grounded_friction(friction, ground_velocity);
|
||||||
|
|
||||||
|
ground::apply_grounded_motion(
|
||||||
|
state_context.velocity,
|
||||||
|
state_context.translation,
|
||||||
|
state_context.prev_translation,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_collision_interrupt(
|
fn check_collision_interrupt(
|
||||||
&mut self,
|
&mut self,
|
||||||
state_context: &mut CollisionContext,
|
state_context: &mut CollisionContext,
|
||||||
) -> Option<FighterState> {
|
) -> Option<FighterState> {
|
||||||
ground::collision_interrupt(state_context, &mut self.grounded_common, false)
|
if let GroundedMotionResult::InAir =
|
||||||
|
ground::collide_with_stage_grounded(state_context, &mut self.grounded_common, false)
|
||||||
|
{
|
||||||
|
Some(FighterState::Fall(FallState))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
||||||
@@ -111,7 +139,17 @@ impl FighterStateImpl for JumpState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, state_context: &mut UpdateContext) {
|
fn update(&mut self, state_context: &mut UpdateContext) {
|
||||||
air::update_standard_motion(state_context);
|
air::integrate_gravity(state_context.velocity, state_context.fighter_attributes);
|
||||||
|
air::apply_air_drift(
|
||||||
|
state_context.velocity,
|
||||||
|
state_context.fighter_attributes,
|
||||||
|
state_context.input,
|
||||||
|
);
|
||||||
|
air::apply_air_motion(
|
||||||
|
state_context.velocity,
|
||||||
|
state_context.translation,
|
||||||
|
state_context.prev_translation,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
||||||
@@ -169,10 +207,19 @@ impl FighterStateImpl for JumpState {
|
|||||||
&mut self,
|
&mut self,
|
||||||
state_context: &mut CollisionContext,
|
state_context: &mut CollisionContext,
|
||||||
) -> Option<FighterState> {
|
) -> Option<FighterState> {
|
||||||
air::collision_interrupt(
|
if let Some(res) = state_context.air_collide_with_stage() {
|
||||||
state_context,
|
// Adjust translation
|
||||||
crate::fighter::state::land::LandingType::Normal,
|
state_context.translation.0 = res.hit_position - state_context.ecb.get_bottom_point();
|
||||||
)
|
let grounded_common = GroundedStateCommon {
|
||||||
|
current_line_id: res.line_id,
|
||||||
|
};
|
||||||
|
Some(FighterState::Land(LandingState::create(
|
||||||
|
grounded_common,
|
||||||
|
LandingType::Normal,
|
||||||
|
)))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ use crate::fighter::{
|
|||||||
state::{
|
state::{
|
||||||
CollisionContext, EnterContext, FighterState, FighterStateImpl, InterruptContext,
|
CollisionContext, EnterContext, FighterState, FighterStateImpl, InterruptContext,
|
||||||
UpdateContext, dash,
|
UpdateContext, dash,
|
||||||
ground::{self, GroundedStateCommon, grounded_movement_standstill_common_interrupts},
|
fall::FallState,
|
||||||
|
ground::{
|
||||||
|
self, GroundedMotionResult, GroundedStateCommon,
|
||||||
|
grounded_movement_standstill_common_interrupts,
|
||||||
|
},
|
||||||
walk,
|
walk,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -49,14 +53,39 @@ impl FighterStateImpl for LandingState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, state_context: &mut UpdateContext) {
|
fn update(&mut self, state_context: &mut UpdateContext) {
|
||||||
ground::update_friction_motion(state_context);
|
let friction =
|
||||||
|
if state_context.velocity.x.abs() > state_context.fighter_attributes.max_walk_vel {
|
||||||
|
state_context.fighter_attributes.ground_friction
|
||||||
|
* state_context
|
||||||
|
.game_settings
|
||||||
|
.fighter_common
|
||||||
|
.ground_friction_over_walk_speed_multiplier
|
||||||
|
} else {
|
||||||
|
state_context.fighter_attributes.ground_friction
|
||||||
|
};
|
||||||
|
|
||||||
|
let ground_velocity = state_context.velocity.x;
|
||||||
|
|
||||||
|
state_context.velocity.x += ground::apply_grounded_friction(friction, ground_velocity);
|
||||||
|
|
||||||
|
ground::apply_grounded_motion(
|
||||||
|
state_context.velocity,
|
||||||
|
state_context.translation,
|
||||||
|
state_context.prev_translation,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_collision_interrupt(
|
fn check_collision_interrupt(
|
||||||
&mut self,
|
&mut self,
|
||||||
state_context: &mut CollisionContext,
|
state_context: &mut CollisionContext,
|
||||||
) -> Option<FighterState> {
|
) -> Option<FighterState> {
|
||||||
ground::collision_interrupt(state_context, &mut self.grounded_common, true)
|
if let GroundedMotionResult::InAir =
|
||||||
|
ground::collide_with_stage_grounded(state_context, &mut self.grounded_common, true)
|
||||||
|
{
|
||||||
|
Some(FighterState::Fall(FallState))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
||||||
|
|||||||
@@ -150,7 +150,6 @@ pub struct UpdateContext<'a> {
|
|||||||
pub fighter_attributes: &'a FighterAttributes,
|
pub fighter_attributes: &'a FighterAttributes,
|
||||||
pub attack_scripts: &'a Assets<FighterAttackScript>,
|
pub attack_scripts: &'a Assets<FighterAttackScript>,
|
||||||
pub attack_script_assets: &'a FighterAttackScriptAssets,
|
pub attack_script_assets: &'a FighterAttackScriptAssets,
|
||||||
pub facing_direction: &'a FighterFacingDirection,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UpdateContext<'_> {
|
impl UpdateContext<'_> {
|
||||||
@@ -291,7 +290,6 @@ impl<'w, 's> FighterFrameQueryItem<'w, 's> {
|
|||||||
fighter_attributes: attributes,
|
fighter_attributes: attributes,
|
||||||
attack_scripts,
|
attack_scripts,
|
||||||
attack_script_assets,
|
attack_script_assets,
|
||||||
facing_direction: &self.facing_direction
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ use super::{
|
|||||||
};
|
};
|
||||||
use crate::fighter::animation::AnimKind;
|
use crate::fighter::animation::AnimKind;
|
||||||
use crate::fighter::state::FighterState;
|
use crate::fighter::state::FighterState;
|
||||||
use crate::fighter::state::ground::GroundedStateCommon;
|
use crate::fighter::state::fall::FallState;
|
||||||
|
use crate::fighter::state::ground::{GroundedMotionResult, GroundedStateCommon};
|
||||||
|
use crate::math::int::FGi32;
|
||||||
|
|
||||||
#[derive(Component, Debug, Clone, Hash)]
|
#[derive(Component, Debug, Clone, Hash)]
|
||||||
pub struct RunState {
|
pub struct RunState {
|
||||||
@@ -41,7 +43,7 @@ impl FighterStateImpl for RunState {
|
|||||||
let last_frame = state_context.input.get_last_frame();
|
let last_frame = state_context.input.get_last_frame();
|
||||||
let (accel, target_vel) = state_context
|
let (accel, target_vel) = state_context
|
||||||
.fighter_attributes
|
.fighter_attributes
|
||||||
.get_accel_and_target_dashrun(&last_frame, state_context.facing_direction.to_sign());
|
.get_accel_and_target_dashrun(&last_frame, FGi32::ONE);
|
||||||
let accel = ground::compute_ground_accel(
|
let accel = ground::compute_ground_accel(
|
||||||
accel,
|
accel,
|
||||||
target_vel,
|
target_vel,
|
||||||
@@ -62,7 +64,13 @@ impl FighterStateImpl for RunState {
|
|||||||
&mut self,
|
&mut self,
|
||||||
state_context: &mut CollisionContext,
|
state_context: &mut CollisionContext,
|
||||||
) -> Option<FighterState> {
|
) -> Option<FighterState> {
|
||||||
ground::collision_interrupt(state_context, &mut self.grounded_common, true)
|
if let GroundedMotionResult::InAir =
|
||||||
|
ground::collide_with_stage_grounded(state_context, &mut self.grounded_common, false)
|
||||||
|
{
|
||||||
|
Some(FighterState::Fall(FallState))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use super::{CollisionContext, EnterContext, FighterStateImpl, InterruptContext, UpdateContext};
|
use super::{CollisionContext, EnterContext, FighterStateImpl, InterruptContext, UpdateContext};
|
||||||
use crate::fighter::animation::AnimKind;
|
use crate::fighter::animation::AnimKind;
|
||||||
use crate::fighter::state::ground::{self, GroundedStateCommon};
|
use crate::fighter::state::fall::FallState;
|
||||||
|
use crate::fighter::state::ground::{self, GroundedMotionResult, GroundedStateCommon};
|
||||||
use crate::fighter::state::{FighterState, dash, jump, wait, walk};
|
use crate::fighter::state::{FighterState, dash, jump, wait, walk};
|
||||||
use crate::input::FighterCommands;
|
use crate::input::FighterCommands;
|
||||||
|
|
||||||
@@ -47,14 +48,39 @@ impl FighterStateImpl for TurnState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, state_context: &mut UpdateContext) {
|
fn update(&mut self, state_context: &mut UpdateContext) {
|
||||||
ground::update_friction_motion(state_context);
|
let friction =
|
||||||
|
if state_context.velocity.x.abs() > state_context.fighter_attributes.max_walk_vel {
|
||||||
|
state_context.fighter_attributes.ground_friction
|
||||||
|
* state_context
|
||||||
|
.game_settings
|
||||||
|
.fighter_common
|
||||||
|
.ground_friction_over_walk_speed_multiplier
|
||||||
|
} else {
|
||||||
|
state_context.fighter_attributes.ground_friction
|
||||||
|
};
|
||||||
|
|
||||||
|
let ground_velocity = state_context.velocity.x;
|
||||||
|
|
||||||
|
state_context.velocity.x += ground::apply_grounded_friction(friction, ground_velocity);
|
||||||
|
|
||||||
|
ground::apply_grounded_motion(
|
||||||
|
state_context.velocity,
|
||||||
|
state_context.translation,
|
||||||
|
state_context.prev_translation,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_collision_interrupt(
|
fn check_collision_interrupt(
|
||||||
&mut self,
|
&mut self,
|
||||||
state_context: &mut CollisionContext,
|
state_context: &mut CollisionContext,
|
||||||
) -> Option<FighterState> {
|
) -> Option<FighterState> {
|
||||||
ground::collision_interrupt(state_context, &mut self.grounded_common, false)
|
if let GroundedMotionResult::InAir =
|
||||||
|
ground::collide_with_stage_grounded(state_context, &mut self.grounded_common, false)
|
||||||
|
{
|
||||||
|
Some(FighterState::Fall(FallState))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ use super::{
|
|||||||
};
|
};
|
||||||
use crate::fighter::animation::AnimKind;
|
use crate::fighter::animation::AnimKind;
|
||||||
use crate::fighter::state::FighterState;
|
use crate::fighter::state::FighterState;
|
||||||
use crate::fighter::state::ground::GroundedStateCommon;
|
use crate::fighter::state::fall::FallState;
|
||||||
|
use crate::fighter::state::ground::{GroundedMotionResult, GroundedStateCommon};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash)]
|
#[derive(Debug, Clone, Hash)]
|
||||||
pub struct WaitState {
|
pub struct WaitState {
|
||||||
@@ -37,14 +38,39 @@ impl FighterStateImpl for WaitState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, state_context: &mut UpdateContext) {
|
fn update(&mut self, state_context: &mut UpdateContext) {
|
||||||
ground::update_friction_motion(state_context);
|
let friction =
|
||||||
|
if state_context.velocity.x.abs() > state_context.fighter_attributes.max_walk_vel {
|
||||||
|
state_context.fighter_attributes.ground_friction
|
||||||
|
* state_context
|
||||||
|
.game_settings
|
||||||
|
.fighter_common
|
||||||
|
.ground_friction_over_walk_speed_multiplier
|
||||||
|
} else {
|
||||||
|
state_context.fighter_attributes.ground_friction
|
||||||
|
};
|
||||||
|
|
||||||
|
let ground_velocity = state_context.velocity.x;
|
||||||
|
|
||||||
|
state_context.velocity.x += ground::apply_grounded_friction(friction, ground_velocity);
|
||||||
|
|
||||||
|
ground::apply_grounded_motion(
|
||||||
|
state_context.velocity,
|
||||||
|
state_context.translation,
|
||||||
|
state_context.prev_translation,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_collision_interrupt(
|
fn check_collision_interrupt(
|
||||||
&mut self,
|
&mut self,
|
||||||
state_context: &mut CollisionContext,
|
state_context: &mut CollisionContext,
|
||||||
) -> Option<FighterState> {
|
) -> Option<FighterState> {
|
||||||
ground::collision_interrupt(state_context, &mut self.grounded_common, false)
|
if let GroundedMotionResult::InAir =
|
||||||
|
ground::collide_with_stage_grounded(state_context, &mut self.grounded_common, false)
|
||||||
|
{
|
||||||
|
Some(FighterState::Fall(FallState))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ use super::{
|
|||||||
};
|
};
|
||||||
use crate::fighter::animation::AnimKind;
|
use crate::fighter::animation::AnimKind;
|
||||||
use crate::fighter::state::FighterState;
|
use crate::fighter::state::FighterState;
|
||||||
use crate::fighter::state::ground::GroundedStateCommon;
|
use crate::fighter::state::fall::FallState;
|
||||||
|
use crate::fighter::state::ground::{GroundedMotionResult, GroundedStateCommon};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Hash)]
|
#[derive(Debug, Clone, Hash)]
|
||||||
pub struct WalkState {
|
pub struct WalkState {
|
||||||
@@ -54,7 +55,13 @@ impl FighterStateImpl for WalkState {
|
|||||||
&mut self,
|
&mut self,
|
||||||
state_context: &mut CollisionContext,
|
state_context: &mut CollisionContext,
|
||||||
) -> Option<FighterState> {
|
) -> Option<FighterState> {
|
||||||
ground::collision_interrupt(state_context, &mut self.grounded_common, false)
|
if let GroundedMotionResult::InAir =
|
||||||
|
ground::collide_with_stage_grounded(state_context, &mut self.grounded_common, false)
|
||||||
|
{
|
||||||
|
Some(FighterState::Fall(FallState))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user