Files
shinespark/src/fighter/state/turn.rs
T
EIREXE ae8f7b5850
CI / build-and-test (push) Failing after 10m51s
Deduplicate fighter state lifecycle policies (#36)
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>
2026-09-16 18:30:53 +00:00

84 lines
2.9 KiB
Rust

use super::{CollisionContext, EnterContext, FighterStateImpl, InterruptContext, UpdateContext};
use crate::fighter::animation::AnimKind;
use crate::fighter::state::ground::{self, GroundedStateCommon};
use crate::fighter::state::{FighterState, dash, jump, wait, walk};
use crate::input::FighterCommands;
#[derive(Debug, Clone, Hash)]
pub struct TurnState {
pub grounded_common: GroundedStateCommon,
}
impl FighterStateImpl for TurnState {
const NAME: &'static str = "Turn";
fn check_interrupt(&self, state_context: &mut InterruptContext) -> Option<FighterState> {
// State chain that results in the turn completing
if state_context.get_current_animation_frame()
<= state_context
.game_settings
.input_common
.turn_into_dashback_window as u32
{
if let Some(state) = dash::check_input(state_context, &self.grounded_common) {
return Some(state);
}
}
if let Some(state) = jump::check_input(state_context, &self.grounded_common) {
*state_context.facing_direction = state_context.facing_direction.reverse();
Some(state)
} else if state_context.is_current_animation_finished() {
if let Some(state) = dash::check_input(state_context, &self.grounded_common) {
Some(state)
} else if let Some(state) = walk::check_input(state_context, &self.grounded_common) {
Some(state)
} else if let Some(state) = wait::check_input(state_context, &self.grounded_common) {
Some(state)
} else {
None
}
} else {
None
}
}
fn on_enter(&mut self, state_context: &mut EnterContext) {
state_context.play_animation(AnimKind::Turn, false);
*state_context.facing_direction = state_context.facing_direction.reverse();
}
fn update(&mut self, state_context: &mut UpdateContext) {
ground::update_friction_motion(state_context);
}
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,
grounded_common: &GroundedStateCommon,
) -> Option<FighterState> {
let input_frame = state_context.input.get_last_frame();
let has_smash_input = state_context
.input
.has_command(FighterCommands::SmashMoveLeft)
|| state_context
.input
.has_command(FighterCommands::SmashMoveRight);
if !input_frame.movement.x.is_zero()
&& input_frame.movement.x.signum() != state_context.facing_direction.to_sign()
&& !has_smash_input
{
return Some(FighterState::Turn(TurnState {
grounded_common: grounded_common.clone(),
}));
}
None
}