Implement tap jump and clean some fluff (#83)
Reviewed-on: #83 Co-authored-by: Álex Román Núñez <eirexe@eirteam.moe>
This commit was merged in pull request #83.
This commit is contained in:
+46
-23
@@ -1,4 +1,3 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
fighter::{
|
||||
@@ -21,21 +20,30 @@ pub enum JumpType {
|
||||
DoubleJump,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
pub enum JumpStateInitiator {
|
||||
Tap,
|
||||
Button,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
pub struct JumpState {
|
||||
pub jump_type: JumpType,
|
||||
pub airborne_state_common: AirborneStateCommon,
|
||||
pub initiator: JumpStateInitiator,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
pub struct JumpSquatState {
|
||||
pub duration_counter: u32,
|
||||
pub initiator: JumpStateInitiator,
|
||||
}
|
||||
|
||||
impl JumpSquatState {
|
||||
pub fn create() -> Self {
|
||||
pub fn create(initiator: JumpStateInitiator) -> Self {
|
||||
Self {
|
||||
duration_counter: 0,
|
||||
initiator,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,17 +76,17 @@ impl FighterStateImpl for JumpSquatState {
|
||||
direction: wavedash_dir.normalize_or_zero(),
|
||||
}))
|
||||
} else if self.duration_counter >= state_context.fighter_attributes.jumpsquat_duration {
|
||||
info!(
|
||||
"Jump {}",
|
||||
state_context
|
||||
let tap_jump_held = matches!(self.initiator, JumpStateInitiator::Tap)
|
||||
&& state_context.input.get_last_frame().movement.y
|
||||
> state_context
|
||||
.game_settings
|
||||
.input_common
|
||||
.smash_input_axis_threshold;
|
||||
let jump_type = if tap_jump_held
|
||||
|| state_context
|
||||
.input
|
||||
.get_last_frame()
|
||||
.is_held(DigitalAction::Jump)
|
||||
);
|
||||
let jump_type = if state_context
|
||||
.input
|
||||
.get_last_frame()
|
||||
.is_held(DigitalAction::Jump)
|
||||
{
|
||||
JumpType::LongJump
|
||||
} else {
|
||||
@@ -87,6 +95,7 @@ impl FighterStateImpl for JumpSquatState {
|
||||
Some(FighterState::Jump(JumpState {
|
||||
jump_type,
|
||||
airborne_state_common: AirborneStateCommon::default(),
|
||||
initiator: self.initiator.clone(),
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
@@ -109,6 +118,7 @@ impl FighterStateImpl for JumpSquatState {
|
||||
state_context.play_animation(AnimKind::JumpSquat, false);
|
||||
state_context.input.enable_hold_all(10);
|
||||
state_context.input.clear_command(FighterCommands::Jump);
|
||||
state_context.input.clear_command(FighterCommands::TapJump);
|
||||
}
|
||||
|
||||
fn on_exit(&mut self, state_context: &mut crate::fighter::state::ExitContext) {
|
||||
@@ -208,20 +218,33 @@ impl FighterStateImpl for JumpState {
|
||||
}
|
||||
|
||||
pub fn check_input(state_context: &InterruptContext) -> Option<FighterState> {
|
||||
state_context
|
||||
.input
|
||||
.has_command(FighterCommands::Jump)
|
||||
.then(|| FighterState::JumpSquat(JumpSquatState::create()))
|
||||
if state_context.input.has_command(FighterCommands::Jump) {
|
||||
Some(FighterState::JumpSquat(JumpSquatState::create(
|
||||
JumpStateInitiator::Button,
|
||||
)))
|
||||
} else if state_context.input.has_command(FighterCommands::TapJump) {
|
||||
Some(FighterState::JumpSquat(JumpSquatState::create(
|
||||
JumpStateInitiator::Tap,
|
||||
)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_input_double_jump(state_context: &InterruptContext) -> Option<FighterState> {
|
||||
state_context
|
||||
.input
|
||||
.has_command(FighterCommands::Jump)
|
||||
.then(|| {
|
||||
FighterState::Jump(JumpState {
|
||||
jump_type: JumpType::DoubleJump,
|
||||
airborne_state_common: AirborneStateCommon::default(),
|
||||
})
|
||||
})
|
||||
if state_context.input.has_command(FighterCommands::Jump) {
|
||||
Some(FighterState::Jump(JumpState {
|
||||
jump_type: JumpType::DoubleJump,
|
||||
airborne_state_common: AirborneStateCommon::default(),
|
||||
initiator: JumpStateInitiator::Button,
|
||||
}))
|
||||
} else if state_context.input.has_command(FighterCommands::TapJump) {
|
||||
Some(FighterState::Jump(JumpState {
|
||||
jump_type: JumpType::DoubleJump,
|
||||
airborne_state_common: AirborneStateCommon::default(),
|
||||
initiator: JumpStateInitiator::Tap,
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user