From 84e07a80aa76e1f8c9f1169150a1ca7bb7be0252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex=20Rom=C3=A1n=20N=C3=BA=C3=B1ez?= Date: Sat, 26 Sep 2026 01:26:39 +0200 Subject: [PATCH] Implement being able to drop through soft platforms --- src/fighter/animation.rs | 2 + src/fighter/state/crouch.rs | 94 ++++++++++++++++++++---------- src/fighter/state/mod.rs | 18 +++++- src/fighter/state/platform_pass.rs | 61 +++++++++++++++++++ src/fighter/surface.rs | 8 +++ src/game_settings.rs | 4 +- src/input/buffer.rs | 2 + src/stage/line.rs | 2 +- 8 files changed, 158 insertions(+), 33 deletions(-) create mode 100644 src/fighter/state/platform_pass.rs diff --git a/src/fighter/animation.rs b/src/fighter/animation.rs index 0667ee7..f87cce0 100644 --- a/src/fighter/animation.rs +++ b/src/fighter/animation.rs @@ -88,6 +88,8 @@ pub enum AnimKind { CrouchIdle, CrouchExit, + PlatformPass, + FlinchGround, FlinchAir, diff --git a/src/fighter/state/crouch.rs b/src/fighter/state/crouch.rs index 0b92390..b23f0cf 100644 --- a/src/fighter/state/crouch.rs +++ b/src/fighter/state/crouch.rs @@ -1,25 +1,30 @@ use super::{ CollisionContext, EnterContext, FighterStateImpl, InterruptContext, UpdateContext, ground, }; +use crate::fighter::FighterSurfaceState; use crate::fighter::animation::AnimKind; +use crate::fighter::state::air::AirborneStateCommon; +use crate::fighter::state::ground::{ + grounded_movement_common_interrupts, grounded_movement_standstill_common_interrupts, +}; +use crate::fighter::state::platform_pass::PlatformPassState; use crate::fighter::state::{FighterState, dash, ground_attack, turn, walk}; -use crate::fighter::state::ground::{grounded_movement_common_interrupts, grounded_movement_standstill_common_interrupts}; +use crate::input::FighterCommands; +use crate::stage::line::StagePolyType; #[derive(Debug, Clone, Hash)] pub enum CrouchSubState { - Entering, + Entering { pass_queued: bool }, Idle, - Exiting + Exiting, } #[derive(Debug, Clone, Hash)] pub struct CrouchState { - sub_state: CrouchSubState + sub_state: CrouchSubState, } -pub fn crouch_idle_interrupts( - state_context: &InterruptContext, -) -> Option { +pub fn crouch_idle_interrupts(state_context: &InterruptContext) -> Option { if let Some(state) = ground_attack::check_interrupt(state_context) { Some(state) } else if let Some(state) = dash::check_input(state_context) { @@ -33,9 +38,7 @@ pub fn crouch_idle_interrupts( } } -pub fn crouch_entering_interrupts( - state_context: &InterruptContext, -) -> Option { +pub fn crouch_entering_interrupts(state_context: &InterruptContext) -> Option { if let Some(state) = ground_attack::check_interrupt(state_context) { Some(state) } else { @@ -51,54 +54,85 @@ impl FighterStateImpl for CrouchState { } match self.sub_state { - CrouchSubState::Entering => { + CrouchSubState::Entering { pass_queued } => { + // pass + if let FighterSurfaceState::Grounded { line_id } = state_context.surface { + if let Some(stage_poly) = state_context + .stage_collision + .stage_polys + .get(line_id.polygon) + { + let is_inputting_crouch = -state_context.game_settings.input_common.run_stick_threshold > state_context.input.get_last_frame().movement.y; + let is_on_a_soft_platform = matches!(stage_poly.poly_type, StagePolyType::Platform); + if pass_queued && is_inputting_crouch && is_on_a_soft_platform + { + return Some(FighterState::PlatformPass(PlatformPassState::new( + AirborneStateCommon::default(), + line_id.polygon, + ))); + } + } + } + // While entering the crouch animation we do not allow movement inputs, but we do allow attacks and jumps if state_context.is_current_animation_finished() { - return Some(FighterState::Crouch( - CrouchState { - sub_state: CrouchSubState::Idle, - } - )); + return Some(FighterState::Crouch(CrouchState { + sub_state: CrouchSubState::Idle, + })); } else { return crouch_entering_interrupts(state_context); } - }, + } CrouchSubState::Idle => { - if state_context.input.get_last_frame().movement.y > -state_context.game_settings.input_common.run_stick_threshold { - return Some(FighterState::Crouch ( - CrouchState { - sub_state: CrouchSubState::Exiting, - } - )); + if state_context.input.get_last_frame().movement.y + > -state_context.game_settings.input_common.run_stick_threshold + { + return Some(FighterState::Crouch(CrouchState { + sub_state: CrouchSubState::Exiting, + })); } else { return crouch_idle_interrupts(state_context); } - }, + } CrouchSubState::Exiting => { if state_context.is_current_animation_finished() { return grounded_movement_standstill_common_interrupts(state_context); } else { return crouch_idle_interrupts(state_context); } - }, + } } } fn on_enter(&mut self, state_context: &mut EnterContext) { match self.sub_state { - CrouchSubState::Entering => { + CrouchSubState::Entering { .. } => { state_context.play_animation(AnimKind::CrouchEnter, false); - }, + } CrouchSubState::Idle => { state_context.play_animation(AnimKind::CrouchIdle, true); - }, + } CrouchSubState::Exiting => { state_context.play_animation(AnimKind::CrouchExit, false); - }, + } } } fn update(&mut self, state_context: &mut UpdateContext) { + if let CrouchSubState::Entering { + ref mut pass_queued, + } = self.sub_state + { + if state_context + .input + .has_command(FighterCommands::SmashMoveDown) + { + state_context + .input + .clear_command(FighterCommands::SmashMoveDown); + *pass_queued = true; + } + } ground::update_friction_motion(state_context); } @@ -119,7 +153,7 @@ pub fn check_input(state_context: &InterruptContext) -> Option { if input_frame.movement.y <= -state_context.game_settings.input_common.run_stick_threshold { return Some(FighterState::Crouch(CrouchState { - sub_state: CrouchSubState::Entering + sub_state: CrouchSubState::Entering { pass_queued: false }, })); } None diff --git a/src/fighter/state/mod.rs b/src/fighter/state/mod.rs index 8e9a38a..5d66460 100644 --- a/src/fighter/state/mod.rs +++ b/src/fighter/state/mod.rs @@ -42,6 +42,7 @@ pub mod turn; pub mod wait; pub mod walk; pub mod crouch; +pub mod platform_pass; #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] pub enum SurfacePolicy { @@ -127,7 +128,9 @@ pub struct InterruptContext<'a> { pub facing_direction: &'a mut FighterFacingDirection, pub game_settings: &'a GameSettings, pub fighter_attributes: &'a FighterAttributes, + pub surface: &'a FighterSurfaceState, pub animation: AnimationStatus, + pub stage_collision: &'a StageCollision, } impl InterruptContext<'_> { @@ -148,8 +151,10 @@ pub struct EnterContext<'a> { pub stale_move_queue: &'a mut FighterStaleMoveQueue, pub facing_direction: &'a mut FighterFacingDirection, pub animation_frame: &'a mut FighterAnimationFrame, + pub surface: &'a mut FighterSurfaceState, pub fighter_attributes: &'a FighterAttributes, pub attack_script_assets: &'a FighterAttackScriptAssets, + pub game_settings: &'a GameSettings, } impl EnterContext<'_> { @@ -160,6 +165,7 @@ impl EnterContext<'_> { pub struct ExitContext<'a> { pub hitboxes: &'a mut FighterHitboxes, + pub surface: &'a mut FighterSurfaceState, } pub struct UpdateContext<'a> { @@ -214,6 +220,7 @@ impl CollisionContext<'_> { fighter_states! { Wait => wait::WaitState, Walk => walk::WalkState, + PlatformPass => platform_pass::PlatformPassState, Crouch => crouch::CrouchState, Dash => dash::DashState, Run => run::RunState, @@ -268,6 +275,7 @@ impl<'w, 's> FighterFrameQueryItem<'w, 's> { animations: &'a FighterAnimations, baked_animations: &'a Assets, attributes: &'a FighterAttributes, + stage_collision: &'a StageCollision, ) -> InterruptContext<'a> { let animation = self.animation_status(animations, baked_animations); InterruptContext { @@ -276,6 +284,8 @@ impl<'w, 's> FighterFrameQueryItem<'w, 's> { game_settings, fighter_attributes: attributes, animation, + surface: &self.surface, + stage_collision, } } @@ -283,6 +293,7 @@ impl<'w, 's> FighterFrameQueryItem<'w, 's> { &'a mut self, attributes: &'a FighterAttributes, attack_script_assets: &'a FighterAttackScriptAssets, + game_settings: &'a GameSettings, ) -> EnterContext<'a> { EnterContext { input: &mut self.input, @@ -292,14 +303,17 @@ impl<'w, 's> FighterFrameQueryItem<'w, 's> { stale_move_queue: &mut self.stale_move_queue, facing_direction: &mut self.facing_direction, animation_frame: &mut self.animation_frame, + surface: &mut self.surface, fighter_attributes: attributes, attack_script_assets, + game_settings } } fn exit_context(&mut self) -> ExitContext<'_> { ExitContext { hitboxes: &mut self.hitboxes, + surface: &mut self.surface, } } @@ -407,7 +421,7 @@ fn transition_state( game_settings.fighter_common.leave_ground_ecb_frame_lock_duration, ); } - next.on_enter(&mut frame.enter_context(attributes, attack_script_assets)); + next.on_enter(&mut frame.enter_context(attributes, attack_script_assets, game_settings)); *current = next; info!("{} -> {}", old_name, new_name); } @@ -417,6 +431,7 @@ pub fn state_interrupt_system( game_settings: Res, baked_animations: Res>, fighter_manifests: Res>, + stage_collision: Res, ) { for fighter in &mut query { let StatefulFighterQueryItem { @@ -490,6 +505,7 @@ pub fn state_interrupt_system( animations, &baked_animations, &manifest.attributes, + &stage_collision )) }; diff --git a/src/fighter/state/platform_pass.rs b/src/fighter/state/platform_pass.rs new file mode 100644 index 0000000..ff172d1 --- /dev/null +++ b/src/fighter/state/platform_pass.rs @@ -0,0 +1,61 @@ +use super::{CollisionContext, EnterContext, FighterStateImpl, InterruptContext, UpdateContext}; +use crate::fighter::animation::AnimKind; +use crate::fighter::state::air::AirborneStateCommon; +use crate::fighter::state::{ExitContext, FighterState, air, jump}; + +#[derive(Debug, Clone, Copy, Hash, Default)] +pub struct PlatformPassState { + airborne_state_common: AirborneStateCommon, + ignored_polygon: usize, +} + +impl PlatformPassState { + pub fn new(airborne_state_common: AirborneStateCommon, ignored_polygon: usize) -> Self { + Self { + airborne_state_common, + ignored_polygon + } + } +} + +impl FighterStateImpl for PlatformPassState { + const NAME: &'static str = "PlatformPass"; + + fn check_interrupt(&self, state_context: &mut InterruptContext) -> Option { + jump::check_input_double_jump(state_context) + } + + fn on_enter(&mut self, state_context: &mut EnterContext) { + state_context.surface.ignore_polygon(self.ignored_polygon, state_context.game_settings.fighter_common.platform_pass_platform_ignore_duration_frames); + state_context.velocity.y = state_context.game_settings.fighter_common.platform_pass_initial_downwards_velocity; + state_context.play_animation(AnimKind::PlatformPass, false); + } + + fn on_exit(&mut self, state_context: &mut ExitContext) { + state_context.surface.clear_polygon_ignore(self.ignored_polygon); + } + + fn update(&mut self, state_context: &mut UpdateContext) { + air::update_standard_motion(state_context, &mut self.airborne_state_common); + } + + fn check_collision_interrupt( + &mut self, + state_context: &mut CollisionContext, + ) -> Option { + air::collision_interrupt( + state_context, + crate::fighter::state::land::LandingType::Normal, + ) + } + + fn is_visually_grounded<'a>( + &'a self, + ) -> bool { + false + } + + fn surface_policy(&self) -> super::SurfacePolicy { + super::SurfacePolicy::Airborne(crate::fighter::surface::EcbLockPolicy::StartOnDetach) + } +} diff --git a/src/fighter/surface.rs b/src/fighter/surface.rs index 306eb6e..33b0ad4 100644 --- a/src/fighter/surface.rs +++ b/src/fighter/surface.rs @@ -57,6 +57,14 @@ impl FighterSurfaceState { *self = Self::Grounded { line_id }; } + pub fn clear_polygon_ignore(&mut self, polygon: usize) { + let Self::Airborne { ignored_polys, .. } = self else { + return; + }; + + ignored_polys.retain(|element| element.polygon != polygon); + } + pub fn ignore_polygon(&mut self, polygon: usize, duration_frames: u32) { let Self::Airborne { ignored_polys, .. } = self else { return; diff --git a/src/game_settings.rs b/src/game_settings.rs index 29aec52..cc3254d 100644 --- a/src/game_settings.rs +++ b/src/game_settings.rs @@ -39,7 +39,9 @@ pub struct FighterSettingsCommon { /// Maximum angle changed caused by directional influence pub di_max_angle: FGi32, - pub leave_ground_ecb_frame_lock_duration: u32 + pub leave_ground_ecb_frame_lock_duration: u32, + pub platform_pass_platform_ignore_duration_frames: u32, + pub platform_pass_initial_downwards_velocity: FGi32, } #[derive(Reflect, Serialize, Deserialize, Clone)] #[reflect(opaque)] diff --git a/src/input/buffer.rs b/src/input/buffer.rs index 2e500cb..5426425 100644 --- a/src/input/buffer.rs +++ b/src/input/buffer.rs @@ -233,6 +233,8 @@ pub fn postprocess_input( input.clear_command(FighterCommands::SmashMoveUp); input.clear_command(FighterCommands::SmashMoveDown); + input.frames_in_y_flick_deadzone = 0xFF; + let command_to_set = if input.current_frame.movement.y > 0.0 { FighterCommands::SmashMoveUp } else { diff --git a/src/stage/line.rs b/src/stage/line.rs index 665561b..7756285 100644 --- a/src/stage/line.rs +++ b/src/stage/line.rs @@ -34,7 +34,7 @@ pub struct StageLineID { #[derive(Reflect, Clone, Default)] pub struct StagePoly { - poly_type: StagePolyType, + pub poly_type: StagePolyType, pub segments: Vec, }