Start integrating asset loading and animations

This commit is contained in:
2026-08-26 16:33:00 +02:00
parent 73855ea354
commit 4ff388f9c0
23 changed files with 724 additions and 301 deletions
+24 -12
View File
@@ -1,9 +1,12 @@
use std::hash::{Hash, Hasher};
use std::time::Duration;
use bevy::prelude::*;
use super::{FighterStateImpl, FighterStateContext, ground, run, wait, walk};
use crate::fighter::state::ground::GroundedStateCommon;
use crate::fighter::animation::AnimKind;
use crate::fighter::state::fall::FallState;
use crate::fighter::state::ground::{GroundedMotionResult, GroundedStateCommon};
use crate::fighter::state::wait::WaitState;
use crate::fighter::state::{FighterState};
use crate::fighter::{FighterAttributes, FighterVelocity, collision};
@@ -45,10 +48,13 @@ impl FighterStateImpl for DashState {
state_context: &FighterStateContext,
) -> Option<FighterState> {
if self.frames_in_dash > state_context.fighter_attribs.dash_duration {
// Dash finish shenanigans
run::check_input(state_context, &self.ground_common)
.or_else(|| walk::check_input(state_context, &self.ground_common))
.or_else(|| wait::check_input(state_context, &self.ground_common))
} else if self.frames_in_dash > state_context.fighter_attribs.dash_acceleration_duration {
// Dash finish shenanigans
run::check_input(state_context, &self.ground_common)
.or_else(|| walk::check_input(state_context, &self.ground_common))
} else {
check_smash_input_with_dir(state_context)
.filter(|dir| *dir != self.direction)
@@ -59,13 +65,21 @@ impl FighterStateImpl for DashState {
fn on_enter(&mut self, state_context: &mut FighterStateContext) {
state_context.input.clear_buffer();
state_context.velocity.x = state_context.fighter_attribs.dash_initial_velocity * self.direction;
state_context.animation_transitions.play(
&mut state_context.animation_player,
state_context.animations.clips[&AnimKind::Dash],
Duration::ZERO,
);
}
fn update(&mut self, state_context: &mut FighterStateContext) {
self.frames_in_dash += 1;
info!("{}", self.frames_in_dash);
let last_frame = state_context.input.get_last_frame();
let (accel, target_vel) = state_context.fighter_attribs.get_accel_and_target_dashrun(&last_frame);
let (accel, target_vel) = state_context.fighter_attribs.get_accel_and_target_dashrun(&last_frame, self.direction);
let accel = ground::compute_ground_accel(
accel,
target_vel,
@@ -86,13 +100,12 @@ impl FighterStateImpl for DashState {
&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::Wait(WaitState { grounded_common } ))
if let GroundedMotionResult::InAir = ground::collide_with_stage_grounded(
state_context,
&mut self.ground_common,
true
) {
Some(FighterState::Fall(FallState))
} else {
None
}
@@ -110,6 +123,5 @@ fn check_smash_input_with_dir(state_context: &FighterStateContext) -> Option<FGi
}
pub fn check_input(state_context: &FighterStateContext, ground_common: &GroundedStateCommon) -> Option<FighterState> {
check_smash_input_with_dir(state_context).map(|dir| FighterState::Dash(DashState::new(dir, ground_common.clone())));
None
check_smash_input_with_dir(state_context).map(|dir| FighterState::Dash(DashState::new(dir, ground_common.clone())))
}
+18 -7
View File
@@ -2,7 +2,7 @@
//! ECS types so it stays cheap to reason about and to unit-test — it has to be
//! bit-for-bit deterministic for rollback.
use crate::fighter::state::FighterStateContext;
use crate::fighter::state::{FighterState, FighterStateContext};
use crate::fighter::{
FighterAttributes, FighterECB, FighterPreviousTranslation, FighterTranslation, FighterVelocity,
};
@@ -10,7 +10,9 @@ use crate::game_settings::GameSettings;
use crate::math::int::FGi32;
use crate::math::vec::FGVec2;
use crate::stage::StagePoly;
use crate::stage::line::{StageCollision, StageLineID, StagePolyLineSegment, StagePolyLineSegmentType};
use crate::stage::line::{
StageCollision, StageLineID, StagePolyLineSegment, StagePolyLineSegmentType,
};
use bevy::prelude::*;
use fixed::traits::Fixed;
@@ -37,7 +39,7 @@ pub fn compute_ground_accel(
attribs: &FighterAttributes,
game_settings: &GameSettings,
) -> FGi32 {
if target_vel == 0.0 {
if target_vel == FGi32::ZERO {
apply_grounded_friction(attribs.ground_friction, gr_vel)
} else {
let mut accel = accel;
@@ -81,13 +83,13 @@ pub fn apply_grounded_motion(
) {
// Vertical velocity should be 0 on the ground
prev_translation.0 = translation.0;
translation.0 += FGVec2::new(velocity.0.x ,FGi32::ZERO);
translation.0 += FGVec2::new(velocity.0.x, FGi32::ZERO);
}
pub fn collide_with_stage_grounded(
state_context: &mut FighterStateContext,
ground_common: &mut GroundedStateCommon,
can_walk_off: bool
can_walk_off: bool,
) -> GroundedMotionResult {
let translation = &mut state_context.translation;
let ecb = &state_context.ecb;
@@ -116,7 +118,8 @@ pub fn collide_with_stage_grounded(
}
let line_dir = segment.segment.direction();
let projected_point = segment.segment.point1() + (ecb_bottom_pos - segment.segment.point1()).project_onto(line_dir);
let projected_point = segment.segment.point1()
+ (ecb_bottom_pos - segment.segment.point1()).project_onto(line_dir);
let closest_point = segment.segment.closest_point(ecb_bottom_pos);
let distance = closest_point.distance(projected_point);
@@ -129,7 +132,8 @@ pub fn collide_with_stage_grounded(
if let Some((bp, new_segment_idx, normal)) = grounded_ecb_bottom_pos {
translation.0 = bp - ecb.get_bottom_point();
state_context.velocity.0 = state_context.velocity.0 - state_context.velocity.0.project_onto_normalized(normal);
state_context.velocity.0 =
state_context.velocity.0 - state_context.velocity.0.project_onto_normalized(normal);
ground_common.current_line_id.segment = new_segment_idx;
GroundedMotionResult::InGround
} else {
@@ -139,3 +143,10 @@ pub fn collide_with_stage_grounded(
GroundedMotionResult::InAir
}
}
pub fn grounded_movement_common_interrupts(
state_context: &FighterStateContext,
ground_common: &GroundedStateCommon
) -> Option<FighterState> {
super::jump::check_input(state_context, ground_common)
}
+2 -3
View File
@@ -99,8 +99,7 @@ pub fn check_input(
state_context
.input
.has_command(FighterCommands::Jump)
.then_some(FighterState::JumpSquat(JumpSquatState::create(
.then(|| FighterState::JumpSquat(JumpSquatState::create(
ground_common.clone(),
)));
None
)))
}
+143 -70
View File
@@ -2,28 +2,27 @@
//! implements, the context they inspect, and the generic system that runs the
//! interrupt check. One state per submodule.
use bevy::ecs::component::Mutable;
use bevy::ecs::system::ScheduleSystem;
use bevy::ecs::query::QueryData;
use bevy::prelude::*;
use bevy_ggrs::{GgrsSchedule, RollbackApp};
use crate::fighter::animation::FighterAnimationPlayerLink;
use crate::fighter::ecb::FighterPreviousECB;
use crate::fighter::{FighterAttributes, FighterECB, FighterPreviousTranslation, FighterTranslation, FighterVelocity};
use crate::fighter::visual::FighterAnimations;
use crate::fighter::{
FighterAttributes, FighterECB, FighterPreviousTranslation, FighterTranslation, FighterVelocity,
};
use crate::game_settings::GameSettings;
use crate::input::FighterInput;
use crate::math::int::FGi32;
use crate::schedule::GameplaySet;
use crate::stage::StagePoly;
use crate::stage::line::StageCollision;
pub mod air;
pub mod dash;
pub mod fall;
pub mod ground;
pub mod jump;
pub mod run;
pub mod wait;
pub mod walk;
pub mod fall;
pub mod air;
pub mod jump;
macro_rules! fighter_states {
($($variant:ident => $ty:ty),* $(,)?) => {
@@ -37,6 +36,10 @@ macro_rules! fighter_states {
pub fn check_interrupt(&self, ctx: &FighterStateContext) -> Option<FighterState> {
match self { $(Self::$variant(s) => s.check_interrupt(ctx)),* }
}
pub fn play_animation(&self, transitions: &mut AnimationTransitions, player: &mut AnimationPlayer, anims: &FighterAnimations) {
match self { $(Self::$variant(s) => s.play_animation(transitions, player, anims)),* }
}
pub fn update(&mut self, ctx: &mut FighterStateContext) {
match self { $(Self::$variant(s) => s.update(ctx)),* }
}
@@ -57,11 +60,15 @@ macro_rules! fighter_states {
pub trait FighterStateImpl: Sized {
const NAME: &'static str;
fn check_interrupt(
&self,
state_context: &FighterStateContext,
) -> Option<FighterState>;
fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState>;
fn play_animation(
&self,
_transitions: &mut AnimationTransitions,
_player: &mut AnimationPlayer,
_anims: &FighterAnimations,
) {
}
fn on_enter(&mut self, _state_context: &mut FighterStateContext) {}
fn update(&mut self, _state_context: &mut FighterStateContext);
@@ -73,7 +80,7 @@ pub trait FighterStateImpl: Sized {
}
}
pub struct FighterStateContext<'a, 'w, 's> {
pub struct FighterStateContext<'a> {
pub translation: &'a mut FighterTranslation,
pub prev_translation: &'a mut FighterPreviousTranslation,
pub input: &'a mut FighterInput,
@@ -82,9 +89,10 @@ pub struct FighterStateContext<'a, 'w, 's> {
pub prev_ecb: &'a mut FighterPreviousECB,
pub fighter_attribs: &'a FighterAttributes,
pub game_settings: &'a GameSettings,
pub entity: Entity,
pub stage_collision: &'a StageCollision,
pub gizmos: Option<&'a mut Gizmos<'w, 's>>,
pub animations: &'a FighterAnimations,
pub animation_player: &'a mut AnimationPlayer,
pub animation_transitions: &'a mut AnimationTransitions,
}
fighter_states! {
@@ -97,6 +105,54 @@ fighter_states! {
Jump => jump::JumpState
}
#[derive(QueryData)]
#[query_data(mutable)]
pub struct FighterFrameQuery {
pub translation: &'static mut FighterTranslation,
pub prev_translation: &'static mut FighterPreviousTranslation,
pub input: &'static mut FighterInput,
pub velocity: &'static mut FighterVelocity,
pub ecb: &'static mut FighterECB,
pub prev_ecb: &'static mut FighterPreviousECB,
pub attributes: &'static FighterAttributes,
}
impl<'w, 's> FighterFrameQueryItem<'w, 's> {
fn context<'a>(
&'a mut self,
game_settings: &'a GameSettings,
stage_collision: &'a StageCollision,
animations: &'a FighterAnimations,
animation_player: &'a mut AnimationPlayer,
animation_transitions: &'a mut AnimationTransitions,
) -> FighterStateContext<'a> {
FighterStateContext {
translation: &mut self.translation,
prev_translation: &mut self.prev_translation,
input: &mut self.input,
velocity: &mut self.velocity,
ecb: &mut self.ecb,
prev_ecb: &mut self.prev_ecb,
fighter_attribs: self.attributes,
game_settings,
stage_collision,
animations,
animation_player,
animation_transitions,
}
}
}
#[derive(QueryData)]
#[query_data(mutable)]
pub struct StatefulFighterQuery {
pub entity: Entity,
pub state: &'static mut FighterState,
pub frame: FighterFrameQuery,
pub animations: &'static FighterAnimations,
pub animation_player_link: &'static FighterAnimationPlayerLink,
}
#[derive(Component)]
pub struct StateNameDebug(pub &'static str);
@@ -107,93 +163,110 @@ impl std::fmt::Display for StateNameDebug {
}
pub fn state_update_system(
query: Query<(Entity, &mut FighterState, &mut FighterTranslation, &mut FighterPreviousTranslation, &mut FighterInput, &mut FighterVelocity, &mut FighterECB, &mut FighterPreviousECB, &FighterAttributes)>,
mut query: Query<StatefulFighterQuery>,
mut animation_players: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>,
stage_collision: Res<StageCollision>,
game_settings: Res<GameSettings>,
mut gizmos: Gizmos,
) {
for (ent, mut state, mut translation, mut prev_translation, mut input, mut velocity, mut ecb, mut prev_ecb, attribs) in query {
let mut update_ctx = FighterStateContext {
translation: &mut translation,
prev_translation: &mut prev_translation,
input: &mut input,
velocity: &mut velocity,
ecb: &mut ecb,
prev_ecb: &mut prev_ecb,
fighter_attribs: &attribs,
game_settings: &game_settings,
entity: ent,
stage_collision: &stage_collision,
gizmos: Some(&mut gizmos),
for fighter in &mut query {
let StatefulFighterQueryItem {
mut state,
mut frame,
animations,
animation_player_link,
..
} = fighter;
let Ok((mut animation_player, mut animation_transitions)) =
animation_players.get_mut(animation_player_link.player())
else {
continue;
};
let mut update_ctx = frame.context(
&game_settings,
&stage_collision,
animations,
&mut animation_player,
&mut animation_transitions,
);
state.update(&mut update_ctx);
}
}
pub fn state_interrupt_system (
query: Query<(Entity, &FighterState, &mut FighterTranslation, &mut FighterPreviousTranslation, &mut FighterInput, &mut FighterVelocity, &mut FighterECB, &mut FighterPreviousECB, &FighterAttributes)>,
pub fn state_interrupt_system(
mut query: Query<StatefulFighterQuery>,
mut animation_players: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>,
stage_collision: Res<StageCollision>,
game_settings: Res<GameSettings>,
mut commands: Commands,
) {
for (ent, state, mut translation, mut prev_translation, mut input, mut velocity, mut ecb, mut prev_ecb, attribs) in query {
let mut state_context = FighterStateContext {
translation: &mut translation,
prev_translation: &mut prev_translation,
input: &mut input,
velocity: &mut velocity,
ecb: &mut ecb,
prev_ecb: &mut prev_ecb,
fighter_attribs: &attribs,
game_settings: &game_settings,
entity: ent,
stage_collision: &stage_collision,
gizmos: None,
for fighter in &mut query {
let StatefulFighterQueryItem {
entity,
state,
mut frame,
animations,
animation_player_link,
} = fighter;
let Ok((mut animation_player, mut animation_transitions)) =
animation_players.get_mut(animation_player_link.player())
else {
continue;
};
let mut state_context = frame.context(
&game_settings,
&stage_collision,
animations,
&mut animation_player,
&mut animation_transitions,
);
if let Some(new_state) = state.check_interrupt(&state_context) {
let mut new_state = new_state;
let old_state_name = state.name();
let new_state_name = new_state.name();
new_state.on_enter(&mut state_context);
commands.entity(ent).insert((
new_state,
StateNameDebug(new_state_name)
));
commands
.entity(entity)
.insert((new_state, StateNameDebug(new_state_name)));
info!("State {} -> {}", old_state_name, new_state_name);
}
}
}
pub fn state_collision_interrupt_system(
query: Query<(Entity, &mut FighterState, &mut FighterTranslation, &mut FighterPreviousTranslation, &mut FighterInput, &mut FighterVelocity, &mut FighterECB, &mut FighterPreviousECB, &FighterAttributes)>,
mut query: Query<StatefulFighterQuery>,
mut animation_players: Query<(&mut AnimationPlayer, &mut AnimationTransitions)>,
stage_collision: Res<StageCollision>,
game_settings: Res<GameSettings>,
mut commands: Commands,
mut gizmos: Gizmos,
) {
for (ent, mut state, mut translation, mut prev_translation, mut input, mut velocity, mut ecb, mut prev_ecb, attribs) in query {
let mut state_context = FighterStateContext {
translation: &mut translation,
prev_translation: &mut prev_translation,
input: &mut input,
velocity: &mut velocity,
ecb: &mut ecb,
prev_ecb: &mut prev_ecb,
fighter_attribs: &attribs,
game_settings: &game_settings,
entity: ent,
stage_collision: &stage_collision,
gizmos: Some(&mut gizmos),
for fighter in &mut query {
let StatefulFighterQueryItem {
entity,
mut state,
mut frame,
animations,
animation_player_link,
} = fighter;
let Ok((mut animation_player, mut animation_transitions)) =
animation_players.get_mut(animation_player_link.player())
else {
continue;
};
let mut state_context = frame.context(
&game_settings,
&stage_collision,
animations,
&mut animation_player,
&mut animation_transitions,
);
if let Some(new_state) = state.check_collision_interrupt(&mut state_context) {
let mut new_state = new_state;
let old_state_name = state.name();
let new_state_name = new_state.name();
new_state.on_enter(&mut state_context);
commands.entity(ent).insert((
new_state,
StateNameDebug(new_state_name)
));
commands
.entity(entity)
.insert((new_state, StateNameDebug(new_state_name)));
info!("State {} -> {}", old_state_name, new_state_name);
}
}
+12 -2
View File
@@ -1,12 +1,16 @@
use std::time::Duration;
use bevy::prelude::*;
use super::{FighterStateImpl, FighterStateContext, ground, wait, walk};
use crate::fighter::animation::AnimKind;
use crate::fighter::state::FighterState;
use crate::fighter::state::fall::FallState;
use crate::fighter::state::ground::{GroundedMotionResult, GroundedStateCommon};
use crate::fighter::{FighterAttributes, FighterVelocity};
use crate::game_settings::GameSettings;
use crate::input::FighterInput;
use crate::math::int::FGi32;
#[derive(Component, Debug, Clone, Hash)]
pub struct RunState {
@@ -27,11 +31,17 @@ impl FighterStateImpl for RunState {
}
}
fn on_enter(&mut self, _state_context: &mut super::FighterStateContext) {}
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();
}
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);
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,
+43 -29
View File
@@ -1,38 +1,50 @@
use std::time::Duration;
use bevy::prelude::*;
use super::{FighterStateImpl, FighterStateContext, ground, walk};
use crate::fighter::state::FighterState;
use super::{FighterStateContext, FighterStateImpl, ground, walk};
use crate::fighter::animation::AnimKind;
use crate::fighter::state::{FighterState, dash};
use crate::fighter::state::fall::FallState;
use crate::fighter::state::ground::{GroundedMotionResult, GroundedStateCommon};
use crate::fighter::state::ground::{
GroundedMotionResult, GroundedStateCommon, grounded_movement_common_interrupts,
};
use crate::fighter::{FighterAttributes, FighterVelocity};
use crate::game_settings::GameSettings;
use crate::stage::line::StageLineID;
#[derive(Debug, Clone, Hash)]
pub struct WaitState {
pub grounded_common: GroundedStateCommon
pub grounded_common: GroundedStateCommon,
}
impl FighterStateImpl for WaitState {
const NAME: &'static str = "Wait";
fn check_interrupt(
&self,
state_context: &FighterStateContext,
) -> Option<FighterState> {
walk::check_input(state_context, &self.grounded_common)
fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> {
dash::check_input(state_context, &self.grounded_common).or_else(||
grounded_movement_common_interrupts(state_context, &self.grounded_common)
.or_else(|| walk::check_input(state_context, &self.grounded_common)))
}
fn on_enter(&mut self, _state_context: &mut super::FighterStateContext) {}
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::Wait],
Duration::ZERO,
).repeat();
}
fn update(&mut self, state_context: &mut super::FighterStateContext) {
let friction = if state_context.velocity.x.abs() > state_context.fighter_attribs.max_walk_vel {
state_context.fighter_attribs.ground_friction
* state_context.game_settings
.figher_common
.ground_friction_over_walk_speed_multiplier
} else {
state_context.fighter_attribs.ground_friction
};
let friction =
if state_context.velocity.x.abs() > state_context.fighter_attribs.max_walk_vel {
state_context.fighter_attribs.ground_friction
* state_context
.game_settings
.figher_common
.ground_friction_over_walk_speed_multiplier
} else {
state_context.fighter_attribs.ground_friction
};
let ground_velocity = state_context.velocity.x;
@@ -44,16 +56,14 @@ impl FighterStateImpl for WaitState {
state_context.prev_translation,
);
}
fn check_collision_interrupt(
&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
@@ -61,12 +71,16 @@ impl FighterStateImpl for WaitState {
}
}
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.stick_deadzone {
return Some(FighterState::Wait(WaitState { grounded_common: ground_state_common.clone() }));
return Some(FighterState::Wait(WaitState {
grounded_common: ground_state_common.clone(),
}));
}
None
}
+38 -21
View File
@@ -1,6 +1,9 @@
use std::time::Duration;
use bevy::prelude::*;
use super::{FighterStateImpl, FighterStateContext, dash, ground, wait};
use super::{FighterStateContext, FighterStateImpl, dash, ground, wait};
use crate::fighter::animation::AnimKind;
use crate::fighter::state::fall::FallState;
use crate::fighter::state::ground::{GroundedMotionResult, GroundedStateCommon};
use crate::fighter::state::{self, FighterState};
@@ -10,26 +13,37 @@ use crate::input::FighterInput;
#[derive(Debug, Clone, Hash)]
pub struct WalkState {
pub grounded_common: GroundedStateCommon
pub grounded_common: GroundedStateCommon,
}
impl FighterStateImpl for WalkState {
const NAME: &'static str = "Walk";
fn check_interrupt(
&self,
state_context: &FighterStateContext,
) -> Option<FighterState> {
wait::check_input(state_context, &self.grounded_common).or_else(|| dash::check_input(state_context, &self.grounded_common))
fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> {
wait::check_input(state_context, &self.grounded_common)
.or_else(|| dash::check_input(state_context, &self.grounded_common))
}
fn on_enter(&mut self, _state_context: &mut FighterStateContext) {}
fn on_enter(&mut self, state_context: &mut FighterStateContext) {
state_context.animation_transitions.play(
&mut state_context.animation_player,
state_context.animations.clips[&AnimKind::Walk],
Duration::ZERO,
).repeat();
}
fn update(&mut self, state_context: &mut FighterStateContext) {
let last_frame = state_context.input.get_last_frame();
let (accel, target_vel) = state_context.fighter_attribs.get_accel_and_target_walk(&last_frame);
let (accel, target_vel) = state_context
.fighter_attribs
.get_accel_and_target_walk(&last_frame);
let accel =
ground::compute_ground_accel(accel, target_vel, state_context.velocity.x, state_context.fighter_attribs, &state_context.game_settings);
let accel = ground::compute_ground_accel(
accel,
target_vel,
state_context.velocity.x,
state_context.fighter_attribs,
&state_context.game_settings,
);
state_context.velocity.x += accel;
@@ -39,16 +53,14 @@ impl FighterStateImpl for WalkState {
state_context.prev_translation,
);
}
fn check_collision_interrupt(
&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
@@ -56,11 +68,16 @@ impl FighterStateImpl for WalkState {
}
}
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.stick_deadzone {
return Some(FighterState::Walk(WalkState { grounded_common: ground_state_common.clone() }));
return Some(FighterState::Walk(WalkState {
grounded_common: ground_state_common.clone(),
}));
}
None