## Summary - add a rollback-tracked `FighterSurfaceState` as the single source of truth for stage contact - move active stage line ownership out of individual grounded fighter states - update landing, airborne motion, ledge departure, hit reactions, and debug save states to maintain surface contact - add tests for contact lifecycle, connected-segment traversal, and ledge departure Reviewed-on: #60 Co-authored-by: Álex Román Núñez <eirexe@eirteam.moe>
121 lines
3.9 KiB
Rust
121 lines
3.9 KiB
Rust
use super::{
|
|
CollisionContext, EnterContext, FighterStateImpl, InterruptContext, UpdateContext, ground, run,
|
|
wait, walk,
|
|
};
|
|
use crate::fighter::FighterFacingDirection;
|
|
use crate::fighter::animation::AnimKind;
|
|
use crate::fighter::state::FighterState;
|
|
use crate::input::FighterCommands::{SmashMoveLeft, SmashMoveRight};
|
|
|
|
#[derive(Debug, Clone, Hash)]
|
|
pub struct DashState {
|
|
direction: FighterFacingDirection,
|
|
}
|
|
|
|
impl DashState {
|
|
pub fn new(direction: FighterFacingDirection) -> Self {
|
|
Self { direction }
|
|
}
|
|
}
|
|
|
|
impl FighterStateImpl for DashState {
|
|
const NAME: &'static str = "Dash";
|
|
fn check_interrupt(&self, ctx: &mut InterruptContext) -> Option<FighterState> {
|
|
let attributes = ctx.fighter_attributes;
|
|
|
|
// A reverse dash can interrupt before IASA
|
|
if let Some(direction) =
|
|
check_smash_input_with_dir(ctx).filter(|direction| *direction != self.direction)
|
|
{
|
|
return Some(FighterState::Dash(DashState::new(direction)));
|
|
}
|
|
|
|
if let Some(state) = ground::grounded_movement_common_interrupts(ctx) {
|
|
return Some(state);
|
|
}
|
|
|
|
if ctx.is_current_animation_finished() {
|
|
return run::check_input(ctx)
|
|
.or_else(|| walk::check_input(ctx))
|
|
.or_else(|| wait::check_input(ctx));
|
|
}
|
|
|
|
if ctx.get_current_animation_frame() > attributes.dash_acceleration_duration {
|
|
return run::check_input(ctx);
|
|
}
|
|
|
|
None
|
|
}
|
|
|
|
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
|
*state_context.facing_direction = self.direction;
|
|
state_context.velocity.x =
|
|
state_context.fighter_attributes.dash_initial_velocity * self.direction.to_sign();
|
|
|
|
state_context.play_animation(AnimKind::Dash, false);
|
|
|
|
match state_context.facing_direction {
|
|
FighterFacingDirection::Left => {
|
|
state_context
|
|
.input
|
|
.clear_command(crate::input::FighterCommands::SmashMoveLeft);
|
|
}
|
|
FighterFacingDirection::Right => {
|
|
state_context
|
|
.input
|
|
.clear_command(crate::input::FighterCommands::SmashMoveRight);
|
|
}
|
|
}
|
|
}
|
|
|
|
fn update(&mut self, state_context: &mut UpdateContext) {
|
|
if state_context.get_current_animation_frame()
|
|
< state_context.fighter_attributes.dash_acceleration_duration
|
|
{}
|
|
|
|
let last_frame = state_context.input.get_last_frame();
|
|
let (accel, target_vel) = state_context
|
|
.fighter_attributes
|
|
.get_accel_and_target_dashrun(&last_frame, self.direction.to_sign());
|
|
let accel = ground::compute_ground_accel(
|
|
accel,
|
|
target_vel,
|
|
state_context.velocity.x,
|
|
state_context.fighter_attributes,
|
|
state_context.game_settings,
|
|
);
|
|
state_context.velocity.x += accel;
|
|
|
|
ground::apply_grounded_motion(
|
|
state_context.velocity,
|
|
state_context.translation,
|
|
state_context.prev_translation,
|
|
);
|
|
}
|
|
|
|
fn check_collision_interrupt(
|
|
&mut self,
|
|
state_context: &mut CollisionContext,
|
|
) -> Option<FighterState> {
|
|
ground::collision_interrupt(state_context, true)
|
|
}
|
|
|
|
fn is_visually_grounded<'a>(&'a self) -> bool {
|
|
true
|
|
}
|
|
}
|
|
|
|
fn check_smash_input_with_dir(state_context: &InterruptContext) -> Option<FighterFacingDirection> {
|
|
if state_context.input.has_command(SmashMoveLeft) {
|
|
return Some(FighterFacingDirection::Left);
|
|
} else if state_context.input.has_command(SmashMoveRight) {
|
|
return Some(FighterFacingDirection::Right);
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
|
|
pub fn check_input(state_context: &InterruptContext) -> Option<FighterState> {
|
|
check_smash_input_with_dir(state_context).map(|dir| FighterState::Dash(DashState::new(dir)))
|
|
}
|