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