Dash now stops when colliding with entity

This commit is contained in:
Sam 2020-09-10 21:17:33 -05:00
parent 04af75bf8d
commit 744843d03f
2 changed files with 21 additions and 12 deletions

View File

@ -92,11 +92,22 @@ impl CharacterBehavior for Data {
timer: Duration::default(),
stage_section: StageSection::Charge,
})
} else if self.stage_section == StageSection::Charge /*&& data.physics.touch_entities.is_empty()*/ && ((self.timer < self.charge_duration && !self.infinite_charge) || (data.inputs.secondary.is_pressed() && self.infinite_charge)) && update.energy.current() > 0
} else if self.stage_section == StageSection::Charge && data.physics.touch_entities.is_empty() && ((self.timer < self.charge_duration && !self.infinite_charge) || (data.inputs.secondary.is_pressed() && self.infinite_charge)) && update.energy.current() > 0
{
// Forward movement
forward_move(data, &mut update, 0.1, self.forward_speed);
// Checks how much a charge has built up
let charge_attained = if self.timer > self.charge_duration_attained {
if self.timer > self.charge_duration_attained {
self.charge_duration
} else {
self.timer
}
} else {
self.charge_duration_attained
};
// Charges
update.character = CharacterState::DashMelee(Data {
base_damage: self.base_damage,
@ -109,7 +120,7 @@ impl CharacterBehavior for Data {
forward_speed: self.forward_speed,
buildup_duration: self.buildup_duration,
charge_duration: self.charge_duration,
charge_duration_attained: self.charge_duration_attained,
charge_duration_attained: charge_attained,
infinite_charge: self.infinite_charge,
swing_duration: self.swing_duration,
recover_duration: self.recover_duration,
@ -147,15 +158,6 @@ impl CharacterBehavior for Data {
})
} else if self.stage_section == StageSection::Swing && self.timer < self.swing_duration {
// Swings
let charge_attained = if self.timer > self.charge_duration_attained {
if self.timer > self.charge_duration_attained {
self.charge_duration
} else {
self.timer
}
} else {
self.charge_duration_attained
};
update.character = CharacterState::DashMelee(Data {
base_damage: self.base_damage,
max_damage: self.max_damage,
@ -167,7 +169,7 @@ impl CharacterBehavior for Data {
forward_speed: self.forward_speed,
buildup_duration: self.buildup_duration,
charge_duration: self.charge_duration,
charge_duration_attained: charge_attained,
charge_duration_attained: self.charge_duration_attained,
infinite_charge: self.infinite_charge,
swing_duration: self.swing_duration,
recover_duration: self.recover_duration,

View File

@ -156,6 +156,9 @@ impl<'a> System<'a> for Sys {
let z_limits = collider.map(|c| c.get_z_limits()).unwrap_or((-0.5, 0.5));
let mass = mass.map(|m| m.0).unwrap_or(scale);
// Resets touch_entities in physics
physics.touch_entities.clear();
// Group to ignore collisions with
let ignore_group = projectile
.filter(|p| p.ignore_group)
@ -190,6 +193,10 @@ impl<'a> System<'a> for Sys {
continue;
}
if entity_other == entity {
continue;
}
let scale_other = scale_other.map(|s| s.0).unwrap_or(1.0);
let radius_other = collider_other.map(|c| c.get_radius()).unwrap_or(0.5);
let z_limits_other = collider_other