Implement double jumping and RoA style wavedash
This commit is contained in:
@@ -88,6 +88,7 @@ pub enum AnimKind {
|
||||
JumpSquat,
|
||||
JumpForward,
|
||||
JumpBack,
|
||||
DoubleJump,
|
||||
Landing,
|
||||
AirDodge,
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
|
||||
@@ -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<FighterState> {
|
||||
state_context.input.has_command(input::FighterCommands::Shield).then(||
|
||||
FighterState::AirDodge(AirDodgeState { duration_counter: 0 })
|
||||
)
|
||||
}
|
||||
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(),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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<FighterState> {
|
||||
None
|
||||
fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> {
|
||||
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,
|
||||
|
||||
+115
-29
@@ -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<FighterState> {
|
||||
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<FighterState> {
|
||||
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<FighterState> {
|
||||
state_context
|
||||
.input
|
||||
.has_command(FighterCommands::Jump)
|
||||
.then(|| FighterState::Jump(JumpState{
|
||||
jump_type: JumpType::DoubleJump
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user