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>
99 lines
3.3 KiB
Rust
99 lines
3.3 KiB
Rust
use crate::{
|
|
fighter::{
|
|
animation::AnimKind,
|
|
attack::FighterHitReaction,
|
|
state::{
|
|
CollisionContext, EnterContext, ExitContext, FighterState, FighterStateImpl,
|
|
InterruptContext, UpdateContext, air,
|
|
fall::FallState,
|
|
ground::{GroundedStateCommon, collision_interrupt},
|
|
land::LandingType,
|
|
wait::WaitState,
|
|
},
|
|
},
|
|
math::int::FGi32,
|
|
};
|
|
|
|
#[derive(Clone, Debug, Hash)]
|
|
pub enum HitstopStateKind {
|
|
Grounded(GroundedStateCommon),
|
|
Airborne,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Hash)]
|
|
pub struct HitstunState {
|
|
pub hit_reaction: FighterHitReaction,
|
|
pub hitstop_kind: HitstopStateKind,
|
|
}
|
|
|
|
impl FighterStateImpl for HitstunState {
|
|
const NAME: &'static str = "Hitstun";
|
|
|
|
fn name(&self) -> String {
|
|
let hitstop_kind = match self.hitstop_kind {
|
|
HitstopStateKind::Grounded(_) => "Grounded",
|
|
HitstopStateKind::Airborne => "Airborne",
|
|
};
|
|
|
|
let hit_reaction_type = match &self.hit_reaction.kind {
|
|
crate::fighter::attack::HitReactionKind::Flinch => "Flinch",
|
|
crate::fighter::attack::HitReactionKind::Tumble => "Tumble",
|
|
};
|
|
|
|
format!("Hitstun ({hitstop_kind}, {hit_reaction_type})")
|
|
}
|
|
|
|
fn check_interrupt(&self, state_context: &mut InterruptContext) -> Option<FighterState> {
|
|
if state_context.get_current_animation_frame() > self.hit_reaction.hitstun_frames {
|
|
match &self.hitstop_kind {
|
|
HitstopStateKind::Grounded(grounded_state_common) => {
|
|
Some(FighterState::Wait(WaitState {
|
|
grounded_common: grounded_state_common.clone(),
|
|
}))
|
|
}
|
|
HitstopStateKind::Airborne => Some(FighterState::Fall(FallState)),
|
|
}
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
|
|
fn update(&mut self, ctx: &mut UpdateContext) {
|
|
air::integrate_gravity(ctx.velocity, ctx.fighter_attributes);
|
|
|
|
let speed = ctx.knockback_velocity.length();
|
|
let next_speed = speed
|
|
.saturating_sub(ctx.game_settings.fighter_common.knockback_decay_per_frame)
|
|
.max(FGi32::ZERO);
|
|
|
|
ctx.knockback_velocity.0 = ctx.knockback_velocity.normalize_or_zero() * next_speed;
|
|
|
|
ctx.translation.0 += ctx.velocity.0 + ctx.knockback_velocity.0;
|
|
}
|
|
|
|
fn on_enter(&mut self, state_context: &mut EnterContext) {
|
|
let animation = match self.hitstop_kind {
|
|
HitstopStateKind::Grounded(_) => AnimKind::FlinchGround,
|
|
HitstopStateKind::Airborne => AnimKind::FlinchAir,
|
|
};
|
|
state_context.play_animation(animation, false);
|
|
state_context.knockback_velocity.0 = self.hit_reaction.launch_velocity;
|
|
}
|
|
|
|
fn on_exit(&mut self, _state_context: &mut ExitContext) {}
|
|
|
|
fn check_collision_interrupt(
|
|
&mut self,
|
|
state_context: &mut CollisionContext,
|
|
) -> Option<FighterState> {
|
|
match &mut self.hitstop_kind {
|
|
HitstopStateKind::Grounded(grounded_state_common) => {
|
|
collision_interrupt(state_context, grounded_state_common, true)
|
|
}
|
|
HitstopStateKind::Airborne => {
|
|
air::collision_interrupt(state_context, LandingType::Normal)
|
|
}
|
|
}
|
|
}
|
|
}
|