Files
shinespark/src/fighter/state/run.rs
T
EIREXE a3fe5123f1
CI / build-and-test (pull_request) Failing after 1m33s
CI / production-build (pull_request) Successful in 10m52s
Preserve grounded motion presentation snapshot
2026-10-06 20:00:24 +02:00

74 lines
2.3 KiB
Rust

use bevy::prelude::*;
use super::{
CollisionContext, EnterContext, FighterStateImpl, InterruptContext, UpdateContext, ground,
wait, walk,
};
use crate::fighter::animation::AnimKind;
use crate::fighter::state::FighterState;
#[derive(Component, Debug, Clone, Hash)]
pub struct RunState;
impl FighterStateImpl for RunState {
const NAME: &'static str = "Run";
fn check_interrupt(&self, state_context: &mut InterruptContext) -> Option<FighterState> {
if let Some(state) = ground::grounded_movement_common_interrupts(state_context) {
return Some(state);
}
let input_frame = state_context.input.get_last_frame();
if input_frame.movement.x.abs()
>= state_context.game_settings.input_common.run_stick_threshold
{
None
} else {
walk::check_input(state_context).or_else(|| wait::check_input(state_context))
}
}
fn on_enter(&mut self, state_context: &mut EnterContext) {
state_context.play_animation(AnimKind::Run, true);
}
fn update(&mut self, state_context: &mut UpdateContext) {
let last_frame = state_context.input.get_last_frame();
let (accel, target_vel) = state_context
.fighter_attributes
.get_accel_and_target_dashrun(&last_frame, state_context.facing_direction.to_sign());
let accel = ground::compute_ground_accel(
accel,
target_vel,
state_context.velocity.x,
state_context.fighter_attributes,
state_context.game_settings,
);
state_context.velocity.x += accel;
ground::apply_grounded_motion(
state_context.velocity,
state_context.translation,
);
}
fn check_collision_interrupt(
&mut self,
state_context: &mut CollisionContext,
) -> Option<FighterState> {
ground::collision_interrupt(state_context, true)
}
fn is_visually_grounded<'a>(&'a self) -> bool {
true
}
}
pub fn check_input(state_context: &InterruptContext) -> 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));
}
None
}