better triple_strike

This commit is contained in:
Adam Whitehurst 2020-03-20 15:03:29 -07:00
parent 4153df66ea
commit 0cdb80427d
4 changed files with 52 additions and 28 deletions

View File

@ -150,6 +150,7 @@ impl From<&CharacterAbility> for CharacterState {
stage: 0,
stage_exhausted: false,
stage_time_active: Duration::default(),
should_transition: true,
})
},
}

View File

@ -10,7 +10,7 @@ use vek::vec::Vec2;
const STAGE_DURATION: u64 = 600;
const BASE_ACCEL: f32 = 200.0;
const BASE_SPEED: f32 = 250.0;
const BASE_SPEED: f32 = 25.0;
/// ### A sequence of 3 incrementally increasing attacks.
///
/// While holding down the `primary` button, perform a series of 3 attacks,
@ -27,6 +27,8 @@ pub struct Data {
pub stage_time_active: Duration,
/// Whether current stage has exhausted its attack
pub stage_exhausted: bool,
/// Whether to go to next stage
pub should_transition: bool,
}
impl CharacterBehavior for Data {
@ -41,26 +43,28 @@ impl CharacterBehavior for Data {
server_events: VecDeque::new(),
};
let new_stage_time_active = self
let stage_time_active = self
.stage_time_active
.checked_add(Duration::from_secs_f32(data.dt.0))
.unwrap_or(Duration::default());
let mut should_transition = self.should_transition;
// If player stops holding input,
if !data.inputs.primary.is_pressed() {
// Done
update.character = CharacterState::Wielding;
// Make sure attack component is removed
data.updater.remove::<Attacking>(data.entity);
return update;
// // Done
// update.character = CharacterState::Wielding;
// // Make sure attack component is removed
// data.updater.remove::<Attacking>(data.entity);
// return update;
should_transition = false;
}
handle_move(data, &mut update);
if self.stage < 3 {
if new_stage_time_active < Duration::from_millis(STAGE_DURATION / 3) {
// Handling movement
if stage_time_active < Duration::from_millis(STAGE_DURATION / 3) {
// Move player forward while in first third of each stage
// Move player according to move_dir
if update.vel.0.magnitude_squared() < BASE_SPEED.powf(2.0) {
update.vel.0 =
update.vel.0 + Vec2::broadcast(data.dt.0) * data.ori.0 * BASE_ACCEL;
@ -69,14 +73,12 @@ impl CharacterBehavior for Data {
update.vel.0 = update.vel.0.normalized() * BASE_SPEED;
}
};
} else {
handle_orientation(data, &mut update);
}
update.character = CharacterState::TripleStrike(Data {
base_damage: self.base_damage,
stage: self.stage,
stage_time_active: new_stage_time_active,
stage_exhausted: false,
});
} else if new_stage_time_active > Duration::from_millis(STAGE_DURATION / 2)
// Handling attacking
if stage_time_active > Duration::from_millis(STAGE_DURATION / 2)
&& !self.stage_exhausted
{
// Try to deal damage in second half of stage
@ -90,22 +92,32 @@ impl CharacterBehavior for Data {
update.character = CharacterState::TripleStrike(Data {
base_damage: self.base_damage,
stage: self.stage,
stage_time_active: new_stage_time_active,
stage_time_active,
stage_exhausted: true,
should_transition,
});
} else if new_stage_time_active > Duration::from_millis(STAGE_DURATION) {
update.character = CharacterState::TripleStrike(Data {
base_damage: self.base_damage,
stage: self.stage + 1,
stage_time_active: Duration::default(),
stage_exhausted: false,
});
} else if stage_time_active > Duration::from_millis(STAGE_DURATION) {
if should_transition {
update.character = CharacterState::TripleStrike(Data {
base_damage: self.base_damage,
stage: self.stage + 1,
stage_time_active: Duration::default(),
stage_exhausted: false,
should_transition,
});
} else {
// Done
update.character = CharacterState::Wielding;
// Make sure attack component is removed
data.updater.remove::<Attacking>(data.entity);
}
} else {
update.character = CharacterState::TripleStrike(Data {
base_damage: self.base_damage,
stage: self.stage,
stage_time_active: new_stage_time_active,
stage_time_active,
stage_exhausted: self.stage_exhausted,
should_transition,
});
}
} else {

View File

@ -53,6 +53,10 @@ fn basic_move(data: &JoinData, update: &mut StateUpdate) {
}
}
handle_orientation(data, update);
}
pub fn handle_orientation(data: &JoinData, update: &mut StateUpdate) {
// Set direction based on move direction
let ori_dir = if update.character.is_attack() || update.character.is_block() {
Vec2::from(data.inputs.look_dir).normalized()

View File

@ -504,7 +504,14 @@ impl FigureMgr {
)
},
CharacterState::TripleStrike(s) => match s.stage {
0 | 2 => anim::character::AttackAnimation::update_skeleton(
0 => anim::character::AttackAnimation::update_skeleton(
&target_base,
(active_tool_kind, time),
state.state_time,
&mut state_animation_rate,
skeleton_attr,
),
1 => anim::character::AttackAnimation::update_skeleton(
&target_base,
(active_tool_kind, time),
state.state_time,