use std::ops::Range;
use super::cat::Facing;
#[derive(Debug, Clone, Copy, PartialEq)]
#[non_exhaustive]
pub enum Flight {
Drop,
Punch(Facing),
Burst {
vx: f32,
vy: f32,
spin: f32,
},
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct Knocked {
pub glyphs: Range<usize>,
pub ruby: Option<usize>,
pub flight: Flight,
pub since: f32,
pub fall: Fall,
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[non_exhaustive]
pub struct Fall {
pub offset: (f32, f32),
pub rotation: f32,
pub alpha: f32,
pub gone: bool,
}
pub(crate) const KNOCK_HIT: f32 = 0.3;
pub(crate) const KNOCK_SECS: f32 = 0.6;
pub(crate) const PUNCH_SECS: f32 = 0.4;
pub(crate) const PUNCH_HIT: f32 = 0.2;
pub(crate) const FALL_SECS: f32 = 1.0;
pub(crate) const RETURN_WAIT: f32 = 1.2;
pub(crate) const RETURN_SECS: f32 = 0.6;
pub(crate) const FLIGHT_TOTAL: f32 = FALL_SECS + RETURN_WAIT + RETURN_SECS;
pub(crate) const STRETCH_SECS: f32 = 1.2;
impl Flight {
pub fn at(self, s: f32) -> Option<Fall> {
fall_at(self, s)
}
}
pub(crate) fn fall_at(flight: Flight, s: f32) -> Option<Fall> {
let s = s.max(0.0);
if s >= FLIGHT_TOTAL {
return None;
}
if s >= FALL_SECS {
let back = ((s - FALL_SECS - RETURN_WAIT) / RETURN_SECS).clamp(0.0, 1.0);
return Some(Fall {
offset: (0.0, 0.0),
rotation: 0.0,
alpha: back,
gone: back <= 0.0,
});
}
let alpha = ((FALL_SECS - s) / 0.3).clamp(0.0, 1.0);
let (offset, rotation) = match flight {
Flight::Drop => {
const SLIDE: f32 = 0.2;
let slide = s.min(SLIDE) / SLIDE;
let drop = (s - SLIDE).max(0.0);
((0.5 * slide + 0.6 * drop, 9.0 * drop * drop), 2.5 * drop)
}
Flight::Punch(f) => {
let d = f.sign();
((d * 5.0 * s, -3.0 * s + 7.0 * s * s), d * 7.0 * s)
}
Flight::Burst { vx, vy, spin } => ((vx * s, vy * s + 6.0 * s * s), spin * s),
#[allow(unreachable_patterns)]
_ => ((0.0, 0.0), 0.0),
};
Some(Fall {
offset,
rotation,
alpha,
gone: false,
})
}