Refactor loading
This commit is contained in:
+32
-24
@@ -2,7 +2,7 @@ use std::time::Duration;
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
use super::{FighterStateImpl, FighterStateContext, ground, wait, walk};
|
||||
use super::{FighterStateContext, FighterStateImpl, ground, wait, walk};
|
||||
use crate::fighter::animation::AnimKind;
|
||||
use crate::fighter::state::FighterState;
|
||||
use crate::fighter::state::fall::FallState;
|
||||
@@ -14,34 +14,39 @@ use crate::math::int::FGi32;
|
||||
|
||||
#[derive(Component, Debug, Clone, Hash)]
|
||||
pub struct RunState {
|
||||
pub grounded_common: GroundedStateCommon
|
||||
pub grounded_common: GroundedStateCommon,
|
||||
}
|
||||
|
||||
impl FighterStateImpl for RunState {
|
||||
const NAME: &'static str = "Run";
|
||||
fn check_interrupt(
|
||||
&self,
|
||||
state_context: &FighterStateContext,
|
||||
) -> Option<FighterState> {
|
||||
fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> {
|
||||
let input_frame = state_context.input.get_last_frame();
|
||||
if input_frame.movement.x.abs() >= state_context.game_settings.input_common.run_stick_threshold {
|
||||
if input_frame.movement.x.abs()
|
||||
>= state_context.game_settings.input_common.run_stick_threshold
|
||||
{
|
||||
None
|
||||
} else {
|
||||
walk::check_input(state_context, &self.grounded_common).or_else(|| wait::check_input(state_context, &self.grounded_common))
|
||||
walk::check_input(state_context, &self.grounded_common)
|
||||
.or_else(|| wait::check_input(state_context, &self.grounded_common))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn on_enter(&mut self, state_context: &mut super::FighterStateContext) {
|
||||
state_context.animation_transitions.play(
|
||||
&mut state_context.animation_player,
|
||||
state_context.animations.clips[&AnimKind::Run],
|
||||
Duration::ZERO,
|
||||
).repeat();
|
||||
state_context
|
||||
.animation_transitions
|
||||
.play(
|
||||
&mut state_context.animation_player,
|
||||
state_context.animations.clips[&AnimKind::Run],
|
||||
Duration::ZERO,
|
||||
)
|
||||
.repeat();
|
||||
}
|
||||
|
||||
|
||||
fn update(&mut self, state_context: &mut super::FighterStateContext) {
|
||||
let last_frame = state_context.input.get_last_frame();
|
||||
let (accel, target_vel) = state_context.fighter_attribs.get_accel_and_target_dashrun(&last_frame, FGi32::ONE);
|
||||
let (accel, target_vel) = state_context
|
||||
.fighter_attribs
|
||||
.get_accel_and_target_dashrun(&last_frame, FGi32::ONE);
|
||||
let accel = ground::compute_ground_accel(
|
||||
accel,
|
||||
target_vel,
|
||||
@@ -62,11 +67,9 @@ impl FighterStateImpl for RunState {
|
||||
&mut self,
|
||||
state_context: &mut FighterStateContext,
|
||||
) -> Option<FighterState> {
|
||||
if let GroundedMotionResult::InAir = ground::collide_with_stage_grounded(
|
||||
state_context,
|
||||
&mut self.grounded_common,
|
||||
false
|
||||
) {
|
||||
if let GroundedMotionResult::InAir =
|
||||
ground::collide_with_stage_grounded(state_context, &mut self.grounded_common, false)
|
||||
{
|
||||
Some(FighterState::Fall(FallState))
|
||||
} else {
|
||||
None
|
||||
@@ -74,11 +77,16 @@ impl FighterStateImpl for RunState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_input(state_context: &FighterStateContext, ground_state_common: &GroundedStateCommon) -> Option<FighterState> {
|
||||
pub fn check_input(
|
||||
state_context: &FighterStateContext,
|
||||
ground_state_common: &GroundedStateCommon,
|
||||
) -> Option<FighterState> {
|
||||
let input_frame = state_context.input.get_last_frame();
|
||||
if input_frame.movement.x.abs() >= state_context.game_settings.input_common.run_stick_threshold
|
||||
{
|
||||
return Some(FighterState::Run(RunState { grounded_common: ground_state_common.clone() }));
|
||||
return Some(FighterState::Run(RunState {
|
||||
grounded_common: ground_state_common.clone(),
|
||||
}));
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user