Update triple_strike:

* add knockback
* prevent infinite repeat
* more dashes
This commit is contained in:
AdamWhitehurst 2020-03-25 07:24:55 -07:00
parent 3889ec7292
commit 857652ee23
7 changed files with 57 additions and 37 deletions

View File

@ -132,6 +132,7 @@ pub struct Attacking {
pub max_angle: f32, pub max_angle: f32,
pub applied: bool, pub applied: bool,
pub hit_count: u32, pub hit_count: u32,
pub knockback: f32,
} }
impl Component for Attacking { impl Component for Attacking {

View File

@ -48,6 +48,7 @@ impl CharacterBehavior for Data {
max_angle: self.max_angle.to_radians(), max_angle: self.max_angle.to_radians(),
applied: false, applied: false,
hit_count: 0, hit_count: 0,
knockback: 0.0,
}); });
update.character = CharacterState::BasicMelee(Data { update.character = CharacterState::BasicMelee(Data {

View File

@ -58,6 +58,7 @@ impl CharacterBehavior for Data {
max_angle: 180_f32.to_radians(), max_angle: 180_f32.to_radians(),
applied: false, applied: false,
hit_count: 0, hit_count: 0,
knockback: 0.0,
}); });
update.character = CharacterState::DashMelee(Data { update.character = CharacterState::DashMelee(Data {

View File

@ -57,6 +57,7 @@ impl CharacterBehavior for Data {
max_angle: 75_f32.to_radians(), max_angle: 75_f32.to_radians(),
applied: false, applied: false,
hit_count: 0, hit_count: 0,
knockback: 0.0,
}); });
update.character = CharacterState::TimedCombo(Data { update.character = CharacterState::TimedCombo(Data {

View File

@ -60,28 +60,26 @@ impl CharacterBehavior for Data {
let initialized = true; let initialized = true;
// Handling movement // Handling movement
if let Stage::First = self.stage {
if stage_time_active < Duration::from_millis(STAGE_DURATION / 3) {
let adjusted_accel = if data.physics.touch_entity.is_none() {
INITIAL_ACCEL
} else {
0.0
};
// Move player forward while in first third of first stage if stage_time_active < Duration::from_millis(STAGE_DURATION / 3) {
if update.vel.0.magnitude_squared() < BASE_SPEED.powf(2.0) { let adjusted_accel = match (self.stage, data.physics.touch_entity.is_none()) {
update.vel.0 = (Stage::First, true) => INITIAL_ACCEL,
update.vel.0 + Vec2::broadcast(data.dt.0) * data.ori.0 * adjusted_accel; (Stage::Second, true) => INITIAL_ACCEL * 0.75,
let mag2 = update.vel.0.magnitude_squared(); (Stage::Third, true) => INITIAL_ACCEL * 0.75,
if mag2 > BASE_SPEED.powf(2.0) { (_, _) => 0.0,
update.vel.0 = update.vel.0.normalized() * BASE_SPEED; };
}
}; // Move player forward while in first third of first stage
} else { if update.vel.0.magnitude_squared() < BASE_SPEED.powf(2.0) {
handle_orientation(data, &mut update, 10.0); update.vel.0 =
} update.vel.0 + Vec2::broadcast(data.dt.0) * data.ori.0 * adjusted_accel;
let mag2 = update.vel.0.magnitude_squared();
if mag2 > BASE_SPEED.powf(2.0) {
update.vel.0 = update.vel.0.normalized() * BASE_SPEED;
}
};
} else { } else {
handle_move(data, &mut update); handle_orientation(data, &mut update, 10.0);
} }
// Handling attacking // Handling attacking
@ -101,6 +99,7 @@ impl CharacterBehavior for Data {
max_angle: 180_f32.to_radians(), max_angle: 180_f32.to_radians(),
applied: false, applied: false,
hit_count: 0, hit_count: 0,
knockback: 7.0,
}); });
CharacterState::TripleStrike(Data { CharacterState::TripleStrike(Data {
@ -113,18 +112,25 @@ impl CharacterBehavior for Data {
}) })
} else if stage_time_active > Duration::from_millis(STAGE_DURATION) { } else if stage_time_active > Duration::from_millis(STAGE_DURATION) {
if should_transition { if should_transition {
CharacterState::TripleStrike(Data { if let Stage::Third = self.stage {
base_damage: self.base_damage, // Make sure attack component is removed
stage: match self.stage { data.updater.remove::<Attacking>(data.entity);
Stage::First => Stage::Second, // Done
Stage::Second => Stage::Third, CharacterState::Wielding
Stage::Third => Stage::First, } else {
}, CharacterState::TripleStrike(Data {
stage_time_active: Duration::default(), base_damage: self.base_damage,
stage_exhausted: false, stage: match self.stage {
should_transition, Stage::First => Stage::Second,
initialized, Stage::Second => Stage::Third,
}) Stage::Third => Stage::First,
},
stage_time_active: Duration::default(),
stage_exhausted: false,
should_transition,
initialized,
})
}
} else { } else {
// Make sure attack component is removed // Make sure attack component is removed
data.updater.remove::<Attacking>(data.entity); data.updater.remove::<Attacking>(data.entity);

View File

@ -159,7 +159,7 @@ pub fn handle_jump(data: &JoinData, update: &mut StateUpdate) {
/// Will attempt to go into `loadout.active_item.ability1` /// Will attempt to go into `loadout.active_item.ability1`
pub fn handle_ability1_input(data: &JoinData, update: &mut StateUpdate) { pub fn handle_ability1_input(data: &JoinData, update: &mut StateUpdate) {
if data.inputs.primary.is_pressed() { if data.inputs.primary.is_just_pressed() {
if let Some(ability) = data if let Some(ability) = data
.loadout .loadout
.active_item .active_item
@ -174,7 +174,7 @@ pub fn handle_ability1_input(data: &JoinData, update: &mut StateUpdate) {
/// Will attempt to go into `loadout.active_item.ability2` /// Will attempt to go into `loadout.active_item.ability2`
pub fn handle_ability2_input(data: &JoinData, update: &mut StateUpdate) { pub fn handle_ability2_input(data: &JoinData, update: &mut StateUpdate) {
if data.inputs.secondary.is_pressed() { if data.inputs.secondary.is_just_pressed() {
if let Some(ability) = data if let Some(ability) = data
.loadout .loadout
.active_item .active_item
@ -189,7 +189,7 @@ pub fn handle_ability2_input(data: &JoinData, update: &mut StateUpdate) {
/// Will attempt to go into `loadout.active_item.ability3` /// Will attempt to go into `loadout.active_item.ability3`
pub fn handle_ability3_input(data: &JoinData, update: &mut StateUpdate) { pub fn handle_ability3_input(data: &JoinData, update: &mut StateUpdate) {
if data.inputs.ability3.is_pressed() { if data.inputs.ability3.is_just_pressed() {
if let Some(ability) = data if let Some(ability) = data
.loadout .loadout
.active_item .active_item
@ -205,7 +205,7 @@ pub fn handle_ability3_input(data: &JoinData, update: &mut StateUpdate) {
/// Checks that player can perform a dodge, then /// Checks that player can perform a dodge, then
/// attempts to go into `loadout.active_item.dodge_ability` /// attempts to go into `loadout.active_item.dodge_ability`
pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) { pub fn handle_dodge_input(data: &JoinData, update: &mut StateUpdate) {
if data.inputs.roll.is_pressed() { if data.inputs.roll.is_just_pressed() {
if let Some(ability) = data if let Some(ability) = data
.loadout .loadout
.active_item .active_item

View File

@ -3,7 +3,7 @@ use crate::{
Agent, Attacking, Body, CharacterState, Controller, HealthChange, HealthSource, Ori, Pos, Agent, Attacking, Body, CharacterState, Controller, HealthChange, HealthSource, Ori, Pos,
Scale, Stats, Scale, Stats,
}, },
event::{EventBus, ServerEvent}, event::{EventBus, LocalEvent, ServerEvent},
sync::Uid, sync::Uid,
}; };
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage}; use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
@ -19,6 +19,7 @@ impl<'a> System<'a> for Sys {
type SystemData = ( type SystemData = (
Entities<'a>, Entities<'a>,
Read<'a, EventBus<ServerEvent>>, Read<'a, EventBus<ServerEvent>>,
Read<'a, EventBus<LocalEvent>>,
ReadStorage<'a, Uid>, ReadStorage<'a, Uid>,
ReadStorage<'a, Pos>, ReadStorage<'a, Pos>,
ReadStorage<'a, Ori>, ReadStorage<'a, Ori>,
@ -36,6 +37,7 @@ impl<'a> System<'a> for Sys {
( (
entities, entities,
server_bus, server_bus,
local_bus,
uids, uids,
positions, positions,
orientations, orientations,
@ -49,6 +51,7 @@ impl<'a> System<'a> for Sys {
): Self::SystemData, ): Self::SystemData,
) { ) {
let mut server_emitter = server_bus.emitter(); let mut server_emitter = server_bus.emitter();
let mut local_emitter = local_bus.emitter();
// Attacks // Attacks
for (entity, uid, pos, ori, scale_maybe, agent_maybe, _, _attacker_stats, attack) in ( for (entity, uid, pos, ori, scale_maybe, agent_maybe, _, _attacker_stats, attack) in (
&entities, &entities,
@ -128,6 +131,13 @@ impl<'a> System<'a> for Sys {
cause: HealthSource::Attack { by: *uid }, cause: HealthSource::Attack { by: *uid },
}, },
}); });
if attack.knockback != 0.0 {
local_emitter.emit(LocalEvent::KnockUp {
entity: b,
dir: ori.0,
force: attack.knockback,
});
}
attack.hit_count += 1; attack.hit_count += 1;
} }
} }