CI / build-and-test (push) Failing after 10m51s
Fixes #22 Extracts shared grounded collision/friction and airborne movement/landing policies while preserving state-specific behavior. Running fighters now pass `can_walk_off = true` so they can run off platform edges. Includes grounded and airborne hitstun call sites. Reviewed-on: #36 Co-authored-by: Álex Román Núñez <eirexe@eirteam.moe>
75 lines
2.3 KiB
Rust
75 lines
2.3 KiB
Rust
use super::{
|
|
CollisionContext, EnterContext, FighterStateImpl, InterruptContext, UpdateContext, dash,
|
|
ground, wait,
|
|
};
|
|
use crate::fighter::animation::AnimKind;
|
|
use crate::fighter::state::FighterState;
|
|
use crate::fighter::state::ground::GroundedStateCommon;
|
|
|
|
#[derive(Debug, Clone, Hash)]
|
|
pub struct WalkState {
|
|
pub grounded_common: GroundedStateCommon,
|
|
}
|
|
|
|
impl FighterStateImpl for WalkState {
|
|
const NAME: &'static str = "Walk";
|
|
fn check_interrupt(&self, state_context: &mut InterruptContext) -> Option<FighterState> {
|
|
if let Some(state) =
|
|
ground::grounded_movement_common_interrupts(state_context, &self.grounded_common)
|
|
{
|
|
return Some(state);
|
|
}
|
|
wait::check_input(state_context, &self.grounded_common)
|
|
.or_else(|| dash::check_input(state_context, &self.grounded_common))
|
|
}
|
|
|
|
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
|
state_context.play_animation(AnimKind::Walk, true);
|
|
}
|
|
|
|
fn update(&mut self, state_context: &mut UpdateContext) {
|
|
let last_frame = state_context.input.get_last_frame();
|
|
let (accel, target_vel) = state_context
|
|
.fighter_attributes
|
|
.get_accel_and_target_walk(&last_frame);
|
|
|
|
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, &mut self.grounded_common, false)
|
|
}
|
|
}
|
|
|
|
pub fn check_input(
|
|
state_context: &InterruptContext,
|
|
ground_state_common: &GroundedStateCommon,
|
|
) -> Option<FighterState> {
|
|
let input_frame = state_context.input.get_last_frame();
|
|
|
|
if !input_frame.movement.x.is_zero() {
|
|
return Some(FighterState::Walk(WalkState {
|
|
grounded_common: ground_state_common.clone(),
|
|
}));
|
|
}
|
|
|
|
None
|
|
}
|