Implement directional influence #43

Merged
EIREXE merged 3 commits from di into master 2026-09-18 20:43:42 +00:00
3 changed files with 28 additions and 6 deletions
Showing only changes of commit 540b0cda8d - Show all commits
+15 -3
View File
@@ -26,13 +26,17 @@ pub fn apply_directional_influence(
let normal = FGVec2::new(-base_launch_direction.y, base_launch_direction.x); let normal = FGVec2::new(-base_launch_direction.y, base_launch_direction.x);
let di_amount = receiver_stick.dot(normal); let di_amount = receiver_stick.dot(normal);
let angle_change = di_amount * di_max_angle.to_fixed::<FGWide>(); let angle_change = di_amount * di_max_angle.to_fixed::<FGWide>();
let angle_change = angle_change.clamp(
-di_max_angle.to_fixed::<FGWide>(),
di_max_angle.to_fixed::<FGWide>(),
);
let (sin, cos) = (attack_angle + angle_change.to_fixed::<FGi32>()).sin_cos(); let (sin, cos) = (attack_angle + angle_change.to_fixed::<FGi32>()).sin_cos();
FGVec2::new(cos, sin).normalize_or_zero() FGVec2::new(cos, sin).normalize_or_zero()
} }
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crate::{ use crate::{
fighter::attack::directional_influence::apply_directional_influence, fighter::attack::directional_influence::apply_directional_influence,
math::{int::FGi32, vec::FGVec2}, math::{int::FGi32, vec::FGVec2},
}; };
@@ -47,10 +51,18 @@ use crate::{
#[test] #[test]
fn di_applies_on_the_correct_side() { fn di_applies_on_the_correct_side() {
let di = apply_directional_influence(FGVec2::lit("0.0", "1.0"), FGi32::lit("0.0"), FGi32::lit("18.0")); let di = apply_directional_influence(
FGVec2::lit("0.0", "1.0"),
FGi32::lit("0.0"),
FGi32::lit("18.0"),
);
assert!(di.x > FGi32::ZERO); assert!(di.x > FGi32::ZERO);
assert!(di.y > FGi32::ZERO); assert!(di.y > FGi32::ZERO);
let di = apply_directional_influence(FGVec2::lit("0.0", "-1.0"), FGi32::lit("0.0"), FGi32::lit("18.0")); let di = apply_directional_influence(
FGVec2::lit("0.0", "-1.0"),
FGi32::lit("0.0"),
FGi32::lit("18.0"),
);
assert!(di.x > FGi32::ZERO); assert!(di.x > FGi32::ZERO);
assert!(di.y < FGi32::ZERO); assert!(di.y < FGi32::ZERO);
} }
+10
View File
@@ -24,6 +24,16 @@ pub struct HitstunState {
knockback_applied: bool knockback_applied: bool
} }
impl HitstunState {
pub fn new(hit_reaction: FighterHitReaction, hitstop_kind: HitstopStateKind) -> Self {
Self {
hit_reaction,
hitstop_kind,
knockback_applied: false
}
}
}
impl FighterStateImpl for HitstunState { impl FighterStateImpl for HitstunState {
const NAME: &'static str = "Hitstun"; const NAME: &'static str = "Hitstun";
+3 -3
View File
@@ -451,10 +451,10 @@ pub fn state_interrupt_system(
} }
info!("Entering hitstop kind: {:?}", hitstop_kind); info!("Entering hitstop kind: {:?}", hitstop_kind);
Some(FighterState::Hitstun(HitstunState { Some(FighterState::Hitstun(HitstunState::new(
hit_reaction: reaction, reaction,
hitstop_kind, hitstop_kind,
})) )))
} else if hitstop.remaining_frames > 0 { } else if hitstop.remaining_frames > 0 {
None None
} else { } else {