Use animation frame data where possible
This commit is contained in:
@@ -17,7 +17,6 @@ use crate::{
|
||||
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
pub struct AirDodgeState {
|
||||
pub duration_counter: u32,
|
||||
pub direction: FGVec2,
|
||||
}
|
||||
|
||||
@@ -25,7 +24,7 @@ impl FighterStateImpl for AirDodgeState {
|
||||
const NAME: &'static str = "AirDodge";
|
||||
|
||||
fn check_interrupt(&self, state_context: &mut FighterStateContext) -> Option<FighterState> {
|
||||
if self.duration_counter >= state_context.fighter_manifest.attributes.air_dodge_duration {
|
||||
if state_context.is_current_animation_finished() {
|
||||
Some(FighterState::Fall(FallState))
|
||||
} else {
|
||||
None
|
||||
@@ -33,8 +32,6 @@ impl FighterStateImpl for AirDodgeState {
|
||||
}
|
||||
|
||||
fn update(&mut self, state_context: &mut FighterStateContext) {
|
||||
self.duration_counter += 1;
|
||||
|
||||
state_context.velocity.0 *= state_context.fighter_manifest.attributes.air_dodge_decay;
|
||||
|
||||
air::apply_air_motion(
|
||||
@@ -55,8 +52,7 @@ impl FighterStateImpl for AirDodgeState {
|
||||
current_line_id: res.line_id,
|
||||
};
|
||||
Some(FighterState::Land(LandingState {
|
||||
grounded_common,
|
||||
duration_counter: 0,
|
||||
grounded_common
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
@@ -77,7 +73,6 @@ pub fn check_input(state_context: &FighterStateContext) -> Option<FighterState>
|
||||
.has_command(input::FighterCommands::Shield)
|
||||
.then(|| {
|
||||
FighterState::AirDodge(AirDodgeState {
|
||||
duration_counter: 0,
|
||||
direction: state_context
|
||||
.input
|
||||
.get_last_frame()
|
||||
|
||||
@@ -10,7 +10,6 @@ use crate::input::FighterCommands::{SmashMoveLeft, SmashMoveRight};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DashState {
|
||||
frames_in_dash: u32,
|
||||
direction: FighterFacingDirection,
|
||||
ground_common: GroundedStateCommon,
|
||||
}
|
||||
@@ -18,14 +17,12 @@ pub struct DashState {
|
||||
impl std::hash::Hash for DashState {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.direction.hash(state);
|
||||
self.frames_in_dash.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
impl DashState {
|
||||
pub fn new(direction: FighterFacingDirection, ground_common: GroundedStateCommon) -> Self {
|
||||
Self {
|
||||
frames_in_dash: 0,
|
||||
direction,
|
||||
ground_common,
|
||||
}
|
||||
@@ -52,13 +49,13 @@ impl FighterStateImpl for DashState {
|
||||
return Some(state);
|
||||
}
|
||||
|
||||
if self.frames_in_dash > attributes.dash_duration {
|
||||
if ctx.is_current_animation_finished() {
|
||||
return run::check_input(ctx, ground)
|
||||
.or_else(|| walk::check_input(ctx, ground))
|
||||
.or_else(|| wait::check_input(ctx, ground));
|
||||
}
|
||||
|
||||
if self.frames_in_dash > attributes.dash_acceleration_duration {
|
||||
if ctx.get_current_animation_frame() > attributes.dash_acceleration_duration {
|
||||
return run::check_input(ctx, ground);
|
||||
}
|
||||
|
||||
@@ -90,9 +87,7 @@ impl FighterStateImpl for DashState {
|
||||
}
|
||||
|
||||
fn update(&mut self, state_context: &mut FighterStateContext) {
|
||||
self.frames_in_dash += 1;
|
||||
|
||||
if self.frames_in_dash
|
||||
if state_context.get_current_animation_frame()
|
||||
< state_context
|
||||
.fighter_manifest
|
||||
.attributes
|
||||
|
||||
@@ -46,8 +46,7 @@ impl FighterStateImpl for FallState {
|
||||
current_line_id: res.line_id,
|
||||
};
|
||||
Some(FighterState::Land(LandingState {
|
||||
grounded_common,
|
||||
duration_counter: 0,
|
||||
grounded_common
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -68,7 +68,6 @@ impl FighterStateImpl for JumpSquatState {
|
||||
}
|
||||
|
||||
Some(FighterState::AirDodge(AirDodgeState {
|
||||
duration_counter: 0,
|
||||
direction: wavedash_dir.normalize_or_zero(),
|
||||
}))
|
||||
} else if self.duration_counter
|
||||
@@ -241,8 +240,7 @@ impl FighterStateImpl for JumpState {
|
||||
current_line_id: res.line_id,
|
||||
};
|
||||
Some(FighterState::Land(LandingState {
|
||||
grounded_common,
|
||||
duration_counter: 0,
|
||||
grounded_common
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -13,15 +13,13 @@ use crate::fighter::{
|
||||
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
pub struct LandingState {
|
||||
pub grounded_common: GroundedStateCommon,
|
||||
pub duration_counter: u32,
|
||||
pub grounded_common: GroundedStateCommon
|
||||
}
|
||||
|
||||
impl LandingState {
|
||||
pub fn create(grounded_common: GroundedStateCommon) -> Self {
|
||||
Self {
|
||||
grounded_common,
|
||||
duration_counter: 0,
|
||||
grounded_common
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +30,7 @@ impl FighterStateImpl for LandingState {
|
||||
fn check_interrupt(&self, state_context: &mut FighterStateContext) -> Option<FighterState> {
|
||||
if state_context.is_current_animation_finished() {
|
||||
grounded_movement_standstill_common_interrupts(state_context, &self.grounded_common)
|
||||
} else if self.duration_counter >= state_context.fighter_manifest.attributes.landing_iasa {
|
||||
} else if state_context.get_current_animation_frame() >= state_context.fighter_manifest.attributes.landing_iasa {
|
||||
dash::check_input(state_context, &self.grounded_common).or_else(|| {
|
||||
ground::grounded_movement_common_interrupts(state_context, &self.grounded_common)
|
||||
.or_else(|| walk::check_input(state_context, &self.grounded_common))
|
||||
@@ -43,8 +41,6 @@ impl FighterStateImpl for LandingState {
|
||||
}
|
||||
|
||||
fn update(&mut self, state_context: &mut FighterStateContext) {
|
||||
self.duration_counter += 1;
|
||||
|
||||
let friction = if state_context.velocity.x.abs()
|
||||
> state_context.fighter_manifest.attributes.max_walk_vel
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user