From 6a2801add078ae4ba89a13541c50cc87460c9047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=80lex=20Rom=C3=A0n?= Date: Thu, 27 Aug 2026 16:36:36 +0200 Subject: [PATCH] Implement double jumping and RoA style wavedash --- assets/fighters/test/test.fighter.ron | 7 +- assets/game_settings.ron | 2 +- src/fighter/animation.rs | 1 + src/fighter/attributes.rs | 2 + src/fighter/state/air_dodge.rs | 43 ++++++-- src/fighter/state/fall.rs | 11 +- src/fighter/state/jump.rs | 144 ++++++++++++++++++++------ src/input/buffer.rs | 3 + src/math/segment.rs | 1 - src/math/vec.rs | 2 +- 10 files changed, 169 insertions(+), 47 deletions(-) diff --git a/assets/fighters/test/test.fighter.ron b/assets/fighters/test/test.fighter.ron index 5ff0889..5b805e5 100644 --- a/assets/fighters/test/test.fighter.ron +++ b/assets/fighters/test/test.fighter.ron @@ -5,7 +5,7 @@ base_walk_accel: "0.1", stick_walk_accel: "0.16", max_walk_vel: "0.7", - ground_friction: "0.09", + ground_friction: "0.02", dash_acceleration_duration: 13, dash_duration: 24, base_dash_accel: "0.02", @@ -14,10 +14,12 @@ short_hop_vertical_velocity: "1.05", full_jump_vertical_velocity: "1.6", jump_horizontal_velocity: "0.7", + air_jump_horizontal_velocity: "0.5", + air_jump_multiplier: "1.0", dash_initial_velocity: "1.4", terminal_velocity: "1.3", gravity: "0.064", - jumpsquat_duration: 4, + jumpsquat_duration: 5, landing_iasa: 4, landing_duration: 30, @@ -40,5 +42,6 @@ JumpBack: "PlyPurin5K_Share_ACTION_JumpB", Landing: "PlyPurin5K_Share_ACTION_Landing", AirDodge: "PlyPurin5K_Share_ACTION_EscapeAir", + DoubleJump: "PlyPurin5K_Share_ACTION_JumpAerialF1", } ) diff --git a/assets/game_settings.ron b/assets/game_settings.ron index 6d99ce0..3bd58d2 100644 --- a/assets/game_settings.ron +++ b/assets/game_settings.ron @@ -1,6 +1,6 @@ ( input_common: ( - stick_deadzone: "0.28", + stick_deadzone: "0.275", trigger_deadzone: "0.3", smash_input_reset_axis_threshold: "0.25", smash_input_axis_threshold: "0.8", diff --git a/src/fighter/animation.rs b/src/fighter/animation.rs index 0d6f87f..8ed35c8 100644 --- a/src/fighter/animation.rs +++ b/src/fighter/animation.rs @@ -88,6 +88,7 @@ pub enum AnimKind { JumpSquat, JumpForward, JumpBack, + DoubleJump, Landing, AirDodge, } diff --git a/src/fighter/attributes.rs b/src/fighter/attributes.rs index 8eb15b2..4467706 100644 --- a/src/fighter/attributes.rs +++ b/src/fighter/attributes.rs @@ -24,6 +24,8 @@ pub struct FighterAttributes { pub short_hop_vertical_velocity: FGi32, pub full_jump_vertical_velocity: FGi32, pub jump_horizontal_velocity: FGi32, + pub air_jump_multiplier: FGi32, + pub air_jump_horizontal_velocity: FGi32, pub landing_iasa: u32, pub landing_duration: u32, diff --git a/src/fighter/state/air_dodge.rs b/src/fighter/state/air_dodge.rs index d69a28d..e9e8c3c 100644 --- a/src/fighter/state/air_dodge.rs +++ b/src/fighter/state/air_dodge.rs @@ -2,15 +2,25 @@ use std::time::Duration; use bevy::prelude::*; -use crate::{fighter::{ - animation::AnimKind, collision, state::{ - FighterState, FighterStateContext, FighterStateImpl, air, dash, fall::FallState, ground::{self, GroundedMotionResult, GroundedStateCommon}, land::LandingState, wait::WaitState, walk, +use crate::{ + fighter::{ + animation::AnimKind, + collision, + state::{ + FighterState, FighterStateContext, FighterStateImpl, air, dash, + fall::FallState, + ground::{self, GroundedMotionResult, GroundedStateCommon}, + land::LandingState, + wait::WaitState, + walk, }, - }, input}; + }, input, math::vec::FGVec2, +}; #[derive(Debug, Clone, Hash)] pub struct AirDodgeState { pub duration_counter: u32, + pub direction: FGVec2, } impl FighterStateImpl for AirDodgeState { @@ -46,7 +56,10 @@ impl FighterStateImpl for AirDodgeState { let grounded_common = GroundedStateCommon { current_line_id: res.line_id, }; - Some(FighterState::Land(LandingState { grounded_common, duration_counter: 0 })) + Some(FighterState::Land(LandingState { + grounded_common, + duration_counter: 0, + })) } else { None } @@ -59,12 +72,22 @@ impl FighterStateImpl for AirDodgeState { Duration::ZERO, ); - state_context.velocity.0 = state_context.input.get_last_frame().movement.normalize_or_zero() * state_context.fighter_attribs.air_dodge_velocity; + state_context.velocity.0 = self.direction * state_context.fighter_attribs.air_dodge_velocity; } } pub fn check_input(state_context: &FighterStateContext) -> Option { - state_context.input.has_command(input::FighterCommands::Shield).then(|| - FighterState::AirDodge(AirDodgeState { duration_counter: 0 }) - ) -} \ No newline at end of file + state_context + .input + .has_command(input::FighterCommands::Shield) + .then(|| { + FighterState::AirDodge(AirDodgeState { + duration_counter: 0, + direction: state_context + .input + .get_last_frame() + .movement + .normalize_or_zero(), + }) + }) +} diff --git a/src/fighter/state/fall.rs b/src/fighter/state/fall.rs index b23eeb1..97e7582 100644 --- a/src/fighter/state/fall.rs +++ b/src/fighter/state/fall.rs @@ -2,7 +2,7 @@ use super::{FighterStateContext, FighterStateImpl}; use crate::fighter::state::ground::GroundedStateCommon; use crate::fighter::state::land::LandingState; -use crate::fighter::state::{FighterState, air}; +use crate::fighter::state::{FighterState, air, jump}; use crate::fighter::collision; #[derive(Debug, Clone, Copy, Hash)] @@ -10,14 +10,19 @@ pub struct FallState; impl FighterStateImpl for FallState { const NAME: &'static str = "Fall"; - fn check_interrupt(&self, _state_context: &FighterStateContext) -> Option { - None + fn check_interrupt(&self, state_context: &FighterStateContext) -> Option { + jump::check_input_double_jump(state_context) } fn on_enter(&mut self, _state_context: &mut super::FighterStateContext) {} fn update(&mut self, state_context: &mut super::FighterStateContext) { air::integrate_gravity(state_context.velocity, state_context.fighter_attribs); + air::apply_air_drift( + state_context.velocity, + state_context.fighter_attribs, + state_context.input, + ); air::apply_air_motion( state_context.velocity, state_context.translation, diff --git a/src/fighter/state/jump.rs b/src/fighter/state/jump.rs index a4041a1..871c911 100644 --- a/src/fighter/state/jump.rs +++ b/src/fighter/state/jump.rs @@ -4,10 +4,18 @@ use bevy::prelude::*; use crate::{ fighter::{ - animation::AnimKind, collision, state::{ - FighterState, FighterStateContext, FighterStateImpl, air, air_dodge, fall::FallState, ground::{self, GroundedMotionResult, GroundedStateCommon}, land::LandingState, + animation::AnimKind, + collision, + state::{ + FighterState, FighterStateContext, FighterStateImpl, air, + air_dodge::{self, AirDodgeState}, + fall::FallState, + ground::{self, GroundedMotionResult, GroundedStateCommon}, + land::LandingState, }, - }, input::FighterCommands, + }, + input::FighterCommands, + math::{int::FGi32, vec::FGVec2}, }; #[derive(Debug, Hash, Clone, Copy)] pub enum JumpType { @@ -18,7 +26,7 @@ pub enum JumpType { #[derive(Debug, Clone, Hash)] pub struct JumpState { - jump_type: JumpType + jump_type: JumpType, } #[derive(Debug, Clone, Hash)] @@ -40,10 +48,37 @@ impl FighterStateImpl for JumpSquatState { const NAME: &'static str = "JumpSquat"; fn check_interrupt(&self, state_context: &FighterStateContext) -> Option { - if self.duration_counter >= state_context.fighter_attribs.jumpsquat_duration { + // Special handling for wavedash from jump squat + if state_context.input.has_command(FighterCommands::Shield) { + // If aiming sideways and in the deadzone, do a perfect wavedash + let mut wavedash_dir = state_context + .input + .get_last_frame() + .movement + .normalize_or_zero(); + let movement = state_context.input.get_last_frame().movement; + if movement.y.is_zero() && !movement.x.is_zero() { + wavedash_dir.y = + -state_context.game_settings.input_common.stick_deadzone - FGi32::lit("-0.01"); + wavedash_dir.x = movement.x.signum(); + } + + if wavedash_dir == FGVec2::ZERO { + wavedash_dir = FGVec2::lit("0.0", "-1.0"); + } + + Some(FighterState::AirDodge(AirDodgeState { + duration_counter: 0, + direction: wavedash_dir.normalize_or_zero(), + })) + } else if self.duration_counter >= state_context.fighter_attribs.jumpsquat_duration { info!("Jump {}", state_context.input.get_last_frame().jump); - let jump_type = if state_context.input.get_last_frame().jump {JumpType::LongJump} else {JumpType::ShortHop}; - Some(FighterState::Jump(JumpState { jump_type})) + let jump_type = if state_context.input.get_last_frame().jump { + JumpType::LongJump + } else { + JumpType::ShortHop + }; + Some(FighterState::Jump(JumpState { jump_type })) } else { None } @@ -93,54 +128,91 @@ impl FighterStateImpl for JumpSquatState { state_context.animations.clips[&AnimKind::JumpSquat], Duration::ZERO, ); - state_context.input.clear_buffer(); + state_context.input.clear_command(FighterCommands::Jump); } } impl FighterStateImpl for JumpState { const NAME: &'static str = "Jump"; fn check_interrupt(&self, state_context: &FighterStateContext) -> Option { - air_dodge::check_input(state_context) + if state_context.input.has_command(FighterCommands::Jump) { + Some(FighterState::Jump(JumpState { + jump_type: JumpType::DoubleJump, + })) + } else { + air_dodge::check_input(state_context) + } } fn update(&mut self, state_context: &mut FighterStateContext) { - info!("TRF1 {}", state_context.translation.0); air::integrate_gravity(state_context.velocity, state_context.fighter_attribs); - air::apply_air_drift(state_context.velocity, state_context.fighter_attribs, state_context.input); + air::apply_air_drift( + state_context.velocity, + state_context.fighter_attribs, + state_context.input, + ); air::apply_air_motion( state_context.velocity, state_context.translation, state_context.prev_translation, ); - info!("TRF12 {}", state_context.translation.0); } fn on_enter(&mut self, state_context: &mut FighterStateContext) { - + if let JumpType::DoubleJump = self.jump_type { + state_context.input.clear_command(FighterCommands::Jump); + } let movement_stick_x = state_context.input.get_last_frame().movement.x; - if movement_stick_x.is_zero() || movement_stick_x.signum() == state_context.facing_direction.to_sign() { - state_context.animation_transitions.play( - state_context.animation_player, - state_context.animations.clips[&AnimKind::JumpForward], - Duration::ZERO, - ); - } else { - state_context.animation_transitions.play( - state_context.animation_player, - state_context.animations.clips[&AnimKind::JumpBack], - Duration::ZERO, - ); + match self.jump_type { + JumpType::ShortHop | JumpType::LongJump => { + if movement_stick_x.is_zero() + || movement_stick_x.signum() == state_context.facing_direction.to_sign() + { + state_context.animation_transitions.play( + state_context.animation_player, + state_context.animations.clips[&AnimKind::JumpForward], + Duration::ZERO, + ); + } else { + state_context.animation_transitions.play( + state_context.animation_player, + state_context.animations.clips[&AnimKind::JumpBack], + Duration::ZERO, + ); + } + } + JumpType::DoubleJump => { + state_context.animation_transitions.play( + state_context.animation_player, + state_context.animations.clips[&AnimKind::DoubleJump], + Duration::ZERO, + ); + } } let vertical_vel = match self.jump_type { JumpType::ShortHop => state_context.fighter_attribs.short_hop_vertical_velocity, JumpType::LongJump => state_context.fighter_attribs.full_jump_vertical_velocity, - JumpType::DoubleJump => todo!(), + JumpType::DoubleJump => { + state_context.fighter_attribs.full_jump_vertical_velocity + * state_context.fighter_attribs.air_jump_multiplier + } + }; + + match self.jump_type { + JumpType::ShortHop | JumpType::LongJump => { + state_context.velocity.x += + state_context.fighter_attribs.jump_horizontal_velocity * movement_stick_x; + } + JumpType::DoubleJump => { + state_context.velocity.x = + state_context.fighter_attribs.air_jump_horizontal_velocity * movement_stick_x; + } }; state_context.velocity.y = vertical_vel; - state_context.velocity.x += state_context.fighter_attribs.jump_horizontal_velocity * movement_stick_x; - state_context.input.clear_buffer(); + state_context.velocity.x += + state_context.fighter_attribs.jump_horizontal_velocity * movement_stick_x; } fn check_collision_interrupt( @@ -153,7 +225,10 @@ impl FighterStateImpl for JumpState { let grounded_common = GroundedStateCommon { current_line_id: res.line_id, }; - Some(FighterState::Land(LandingState { grounded_common, duration_counter: 0 })) + Some(FighterState::Land(LandingState { + grounded_common, + duration_counter: 0, + })) } else { None } @@ -169,3 +244,14 @@ pub fn check_input( .has_command(FighterCommands::Jump) .then(|| FighterState::JumpSquat(JumpSquatState::create(ground_common.clone()))) } + +pub fn check_input_double_jump( + state_context: &FighterStateContext +) -> Option { + state_context + .input + .has_command(FighterCommands::Jump) + .then(|| FighterState::Jump(JumpState{ + jump_type: JumpType::DoubleJump + })) +} diff --git a/src/input/buffer.rs b/src/input/buffer.rs index f9ce0b4..0b59299 100644 --- a/src/input/buffer.rs +++ b/src/input/buffer.rs @@ -154,6 +154,9 @@ pub fn postprocess_input( FighterCommands::SmashMoveLeft }; + if !input.has_command(command_to_set) { + dbg!(command_to_set); + } input.set_lifetime(command_to_set, game_settings.input_common.input_buffer_size); } } diff --git a/src/math/segment.rs b/src/math/segment.rs index 67d0269..4b0d206 100644 --- a/src/math/segment.rs +++ b/src/math/segment.rs @@ -128,7 +128,6 @@ impl FGSegment2d { if denom == FGWide::ZERO { return None; // Parallel or collinear } - info!("{p0}, {p1}, {p2}, {p3}"); let s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / denom; let t = (s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / denom; diff --git a/src/math/vec.rs b/src/math/vec.rs index 3cef389..d7adb24 100644 --- a/src/math/vec.rs +++ b/src/math/vec.rs @@ -6,7 +6,7 @@ use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Sub}; use super::int::{FGWide, FGi32}; -#[derive(Clone, Copy, PartialEq, Default, Debug, Reflect, Serialize, Deserialize)] +#[derive(Clone, Copy, PartialEq, Default, Debug, Reflect, Serialize, Deserialize, Hash)] #[reflect(opaque)] pub struct FGVec2 { pub x: FGi32,