Add airdodge
This commit is contained in:
@@ -89,4 +89,5 @@ pub enum AnimKind {
|
||||
JumpForward,
|
||||
JumpBack,
|
||||
Landing,
|
||||
AirDodge,
|
||||
}
|
||||
|
||||
@@ -35,6 +35,10 @@ pub struct FighterAttributes {
|
||||
pub terminal_velocity: FGi32,
|
||||
pub gravity: FGi32,
|
||||
pub air_friction: FGi32,
|
||||
|
||||
pub air_dodge_duration: u32,
|
||||
pub air_dodge_velocity: FGi32,
|
||||
pub air_dodge_decay: FGi32
|
||||
}
|
||||
|
||||
impl FighterAttributes {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
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,
|
||||
},
|
||||
}, input};
|
||||
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
pub struct AirDodgeState {
|
||||
pub duration_counter: u32,
|
||||
}
|
||||
|
||||
impl FighterStateImpl for AirDodgeState {
|
||||
const NAME: &'static str = "AirDodge";
|
||||
|
||||
fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> {
|
||||
if self.duration_counter >= state_context.fighter_attribs.air_dodge_duration {
|
||||
Some(FighterState::Fall(FallState))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn update(&mut self, state_context: &mut FighterStateContext) {
|
||||
self.duration_counter += 1;
|
||||
|
||||
state_context.velocity.0 *= state_context.fighter_attribs.air_dodge_decay;
|
||||
|
||||
air::apply_air_motion(
|
||||
state_context.velocity,
|
||||
state_context.translation,
|
||||
state_context.prev_translation,
|
||||
);
|
||||
}
|
||||
|
||||
fn check_collision_interrupt(
|
||||
&mut self,
|
||||
state_context: &mut FighterStateContext,
|
||||
) -> Option<FighterState> {
|
||||
if let Some(res) = collision::air_collide_with_stage(state_context) {
|
||||
// Adjust translation
|
||||
state_context.translation.0 = res.hit_position - state_context.ecb.get_bottom_point();
|
||||
let grounded_common = GroundedStateCommon {
|
||||
current_line_id: res.line_id,
|
||||
};
|
||||
Some(FighterState::Land(LandingState { grounded_common, duration_counter: 0 }))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn on_enter(&mut self, state_context: &mut FighterStateContext) {
|
||||
state_context.animation_transitions.play(
|
||||
state_context.animation_player,
|
||||
state_context.animations.clips[&AnimKind::AirDodge],
|
||||
Duration::ZERO,
|
||||
);
|
||||
|
||||
state_context.velocity.0 = state_context.input.get_last_frame().movement.normalize_or_zero() * 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 })
|
||||
)
|
||||
}
|
||||
@@ -5,7 +5,7 @@ use bevy::prelude::*;
|
||||
use crate::{
|
||||
fighter::{
|
||||
animation::AnimKind, collision, state::{
|
||||
FighterState, FighterStateContext, FighterStateImpl, air, fall::FallState, ground::{self, GroundedMotionResult, GroundedStateCommon}, land::LandingState,
|
||||
FighterState, FighterStateContext, FighterStateImpl, air, air_dodge, fall::FallState, ground::{self, GroundedMotionResult, GroundedStateCommon}, land::LandingState,
|
||||
},
|
||||
}, input::FighterCommands,
|
||||
};
|
||||
@@ -98,8 +98,8 @@ impl FighterStateImpl for JumpSquatState {
|
||||
|
||||
impl FighterStateImpl for JumpState {
|
||||
const NAME: &'static str = "Jump";
|
||||
fn check_interrupt(&self, _state_context: &FighterStateContext) -> Option<FighterState> {
|
||||
None
|
||||
fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> {
|
||||
air_dodge::check_input(state_context)
|
||||
}
|
||||
|
||||
fn update(&mut self, state_context: &mut FighterStateContext) {
|
||||
|
||||
@@ -24,6 +24,7 @@ pub mod run;
|
||||
pub mod wait;
|
||||
pub mod walk;
|
||||
pub mod land;
|
||||
pub mod air_dodge;
|
||||
|
||||
macro_rules! fighter_states {
|
||||
($($variant:ident => $ty:ty),* $(,)?) => {
|
||||
@@ -95,7 +96,8 @@ fighter_states! {
|
||||
Fall => fall::FallState,
|
||||
JumpSquat => jump::JumpSquatState,
|
||||
Jump => jump::JumpState,
|
||||
Land => land::LandingState
|
||||
Land => land::LandingState,
|
||||
AirDodge => air_dodge::AirDodgeState
|
||||
}
|
||||
|
||||
#[derive(QueryData)]
|
||||
|
||||
Reference in New Issue
Block a user