Added swing duration to dash melee. Added framework for animation to be added.

This commit is contained in:
Sam 2020-09-11 14:56:04 -05:00
parent 6dede05a0e
commit c99e4c3c18
5 changed files with 83 additions and 8 deletions

View File

@ -82,8 +82,9 @@ pub enum CharacterAbility {
forward_speed: f32,
buildup_duration: Duration,
charge_duration: Duration,
infinite_charge: bool,
swing_duration: Duration,
recover_duration: Duration,
infinite_charge: bool,
},
BasicBlock,
Roll,
@ -330,8 +331,9 @@ impl From<&CharacterAbility> for CharacterState {
forward_speed,
buildup_duration,
charge_duration,
infinite_charge,
swing_duration,
recover_duration,
infinite_charge,
} => CharacterState::DashMelee(dash_melee::Data {
static_data: dash_melee::StaticData {
base_damage: *base_damage,
@ -345,6 +347,7 @@ impl From<&CharacterAbility> for CharacterState {
infinite_charge: *infinite_charge,
buildup_duration: *buildup_duration,
charge_duration: *charge_duration,
swing_duration: *swing_duration,
recover_duration: *recover_duration,
},
end_charge: false,

View File

@ -177,6 +177,7 @@ impl Tool {
forward_speed: 4.0,
buildup_duration: Duration::from_millis(200),
charge_duration: Duration::from_millis(400),
swing_duration: Duration::from_millis(100),
recover_duration: Duration::from_millis(750),
infinite_charge: true,
},

View File

@ -31,6 +31,8 @@ pub struct StaticData {
pub buildup_duration: Duration,
/// How long the state charges for until it reaches max damage
pub charge_duration: Duration,
/// Suration of state spent in swing
pub swing_duration: Duration,
/// How long the state has until exiting
pub recover_duration: Duration,
}
@ -174,6 +176,27 @@ impl CharacterBehavior for Data {
);
} else if self.stage_section == StageSection::Charge {
// Transitions to swing section of stage
update.character = CharacterState::DashMelee(Data {
static_data: self.static_data,
end_charge: self.end_charge,
timer: Duration::default(),
stage_section: StageSection::Swing,
exhausted: self.exhausted,
})
} else if self.stage_section == StageSection::Swing && self.timer < self.static_data.swing_duration {
// Swings
update.character = CharacterState::DashMelee(Data {
static_data: self.static_data,
end_charge: self.end_charge,
timer: self
.timer
.checked_add(Duration::from_secs_f32(data.dt.0))
.unwrap_or_default(),
stage_section: self.stage_section,
exhausted: self.exhausted,
})
} else if self.stage_section == StageSection::Swing {
// Transitions to recover section of stage
update.character = CharacterState::DashMelee(Data {
static_data: self.static_data,
end_charge: self.end_charge,

View File

@ -2,7 +2,10 @@ use super::{
super::{vek::*, Animation},
CharacterSkeleton, SkeletonAttr,
};
use common::comp::item::{Hands, ToolKind};
use common::{
comp::item::{Hands, ToolKind},
states::utils::StageSection,
};
pub struct Input {
pub attack: bool,
@ -10,7 +13,7 @@ pub struct Input {
pub struct DashAnimation;
impl Animation for DashAnimation {
type Dependency = (Option<ToolKind>, Option<ToolKind>, f64);
type Dependency = (Option<ToolKind>, Option<ToolKind>, f64, Option<StageSection>);
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
@ -20,7 +23,7 @@ impl Animation for DashAnimation {
#[allow(clippy::single_match)] // TODO: Pending review in #587
fn update_skeleton_inner(
skeleton: &Self::Skeleton,
(active_tool_kind, second_tool_kind, _global_time): Self::Dependency,
(active_tool_kind, second_tool_kind, _global_time, stage_section): Self::Dependency,
anim_time: f64,
rate: &mut f32,
skeleton_attr: &SkeletonAttr,
@ -42,6 +45,23 @@ impl Animation for DashAnimation {
match active_tool_kind {
//TODO: Inventory
Some(ToolKind::Sword(_)) => {
if let Some(stage_section) = stage_section {
match stage_section {
StageSection::Buildup => {
},
StageSection::Charge => {
},
StageSection::Swing => {
},
StageSection::Recover => {
}
}
}
next.head.position = Vec3::new(
0.0,
-2.0 + skeleton_attr.head.0,

View File

@ -897,11 +897,39 @@ impl FigureMgr {
skeleton_attr,
)
},
CharacterState::DashMelee(_) => {
CharacterState::DashMelee(s) => {
let stage_time = s.timer.as_secs_f64();
let stage_progress = match s.stage_section {
StageSection::Buildup => {
stage_time
/ s.static_data
.buildup_duration
.as_secs_f64()
},
StageSection::Charge => {
stage_time
/ s.static_data
.charge_duration
.as_secs_f64()
},
StageSection::Swing => {
stage_time
/ s.static_data
.swing_duration
.as_secs_f64()
},
StageSection::Recover => {
stage_time
/ s.static_data
.recover_duration
.as_secs_f64()
},
_ => 0.0,
};
anim::character::DashAnimation::update_skeleton(
&target_base,
(active_tool_kind, second_tool_kind, time),
state.state_time,
(active_tool_kind, second_tool_kind, time, Some(s.stage_section)),
stage_progress,
&mut state_animation_rate,
skeleton_attr,
)