Removed most hardcoded ability keys.

This commit is contained in:
Sam 2020-10-31 13:44:00 -05:00
parent f1f5c2b21b
commit b8f722af8d
6 changed files with 34 additions and 12 deletions

View File

@ -452,6 +452,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState {
swing_duration: *swing_duration,
recover_duration: *recover_duration,
is_interruptible: *is_interruptible,
ability_key: key,
},
auto_charge: false,
timer: Duration::default(),
@ -489,6 +490,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState {
speed_increase: 1.0 - *speed_increase,
max_speed_increase: *max_speed_increase - 1.0,
is_interruptible: *is_interruptible,
ability_key: key,
},
stage: 1,
combo: 0,
@ -552,6 +554,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState {
is_interruptible: *is_interruptible,
forward_speed: *forward_speed,
num_spins: *num_spins,
ability_key: key,
},
timer: Duration::default(),
spins_remaining: *num_spins - 1,
@ -583,6 +586,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState {
charge_duration: *charge_duration,
swing_duration: *swing_duration,
recover_duration: *recover_duration,
ability_key: key,
},
stage_section: StageSection::Charge,
timer: Duration::default(),
@ -619,6 +623,7 @@ impl From<(&CharacterAbility, AbilityKey)> for CharacterState {
projectile_gravity: *projectile_gravity,
initial_projectile_speed: *initial_projectile_speed,
max_projectile_speed: *max_projectile_speed,
ability_key: key,
},
timer: Duration::default(),
stage_section: StageSection::Buildup,

View File

@ -32,6 +32,8 @@ pub struct StaticData {
pub swing_duration: Duration,
/// How long the state has until exiting
pub recover_duration: Duration,
/// What key is used to press ability
pub ability_key: AbilityKey,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@ -58,7 +60,7 @@ impl CharacterBehavior for Data {
match self.stage_section {
StageSection::Charge => {
if data.inputs.secondary.is_pressed()
if ability_key_is_pressed(data, self.static_data.ability_key)
&& update.energy.current() >= self.static_data.energy_cost
&& self.timer < self.static_data.charge_duration
{
@ -81,7 +83,7 @@ impl CharacterBehavior for Data {
amount: -(self.static_data.energy_drain as f32 * data.dt.0) as i32,
source: EnergySource::Ability,
});
} else if data.inputs.secondary.is_pressed()
} else if ability_key_is_pressed(data, self.static_data.ability_key)
&& update.energy.current() >= self.static_data.energy_cost
{
// Maintains charge

View File

@ -37,6 +37,8 @@ pub struct StaticData {
pub projectile_gravity: Option<Gravity>,
pub initial_projectile_speed: f32,
pub max_projectile_speed: f32,
/// What key is used to press ability
pub ability_key: AbilityKey,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@ -80,7 +82,7 @@ impl CharacterBehavior for Data {
}
},
StageSection::Charge => {
if !data.inputs.secondary.is_pressed() && !self.exhausted {
if !ability_key_is_pressed(data, self.static_data.ability_key) && !self.exhausted {
let charge_frac = (self.timer.as_secs_f32()
/ self.static_data.charge_duration.as_secs_f32())
.min(1.0);
@ -138,7 +140,7 @@ impl CharacterBehavior for Data {
..*self
});
} else if self.timer < self.static_data.charge_duration
&& data.inputs.secondary.is_pressed()
&& ability_key_is_pressed(data, self.static_data.ability_key)
{
// Charges
update.character = CharacterState::ChargedRanged(Data {
@ -154,7 +156,7 @@ impl CharacterBehavior for Data {
amount: -(self.static_data.energy_drain as f32 * data.dt.0) as i32,
source: EnergySource::Ability,
});
} else if data.inputs.secondary.is_pressed() {
} else if ability_key_is_pressed(data, self.static_data.ability_key) {
// Holds charge
update.character = CharacterState::ChargedRanged(Data {
timer: self

View File

@ -54,6 +54,8 @@ pub struct StaticData {
pub max_speed_increase: f32,
/// Whether the state can be interrupted by other abilities
pub is_interruptible: bool,
/// What key is used to press ability
pub ability_key: AbilityKey,
}
/// A sequence of attacks that can incrementally become faster and more
/// damaging.
@ -84,7 +86,9 @@ impl CharacterBehavior for Data {
let stage_index = (self.stage - 1) as usize;
// Allows for other states to interrupt this state
if self.static_data.is_interruptible && !data.inputs.primary.is_pressed() {
if self.static_data.is_interruptible
&& !ability_key_is_pressed(data, self.static_data.ability_key)
{
handle_interrupt(data, &mut update);
match update.character {
CharacterState::ComboMelee(_) => {},
@ -183,7 +187,7 @@ impl CharacterBehavior for Data {
StageSection::Recover => {
if self.timer < self.static_data.stage_data[stage_index].base_recover_duration {
// Recovers
if data.inputs.primary.is_pressed() {
if ability_key_is_pressed(data, self.static_data.ability_key) {
// Checks if state will transition to next stage after recover
update.character = CharacterState::ComboMelee(Data {
static_data: self.static_data.clone(),

View File

@ -39,6 +39,8 @@ pub struct StaticData {
pub recover_duration: Duration,
/// Whether the state can be interrupted by other abilities
pub is_interruptible: bool,
/// What key is used to press ability
pub ability_key: AbilityKey,
}
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
@ -66,7 +68,9 @@ impl CharacterBehavior for Data {
handle_move(data, &mut update, 0.1);
// Allows for other states to interrupt this state
if self.static_data.is_interruptible && !data.inputs.secondary.is_pressed() {
if self.static_data.is_interruptible
&& !ability_key_is_pressed(data, self.static_data.ability_key)
{
handle_interrupt(data, &mut update);
match update.character {
CharacterState::DashMelee(_) => {},
@ -90,7 +94,7 @@ impl CharacterBehavior for Data {
} else {
// Transitions to charge section of stage
update.character = CharacterState::DashMelee(Data {
auto_charge: !data.inputs.secondary.is_pressed(),
auto_charge: !ability_key_is_pressed(data, self.static_data.ability_key),
timer: Duration::default(),
stage_section: StageSection::Charge,
..*self
@ -100,7 +104,7 @@ impl CharacterBehavior for Data {
StageSection::Charge => {
if (self.static_data.infinite_charge
|| self.timer < self.static_data.charge_duration)
&& (data.inputs.secondary.is_pressed()
&& (ability_key_is_pressed(data, self.static_data.ability_key)
|| (self.auto_charge && self.timer < self.static_data.charge_duration))
&& update.energy.current() > 0
{

View File

@ -38,6 +38,8 @@ pub struct StaticData {
pub forward_speed: f32,
/// Number of spins
pub num_spins: u32,
/// What key is used to press ability
pub ability_key: AbilityKey,
}
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
@ -65,7 +67,9 @@ impl CharacterBehavior for Data {
}
// Allows for other states to interrupt this state
if self.static_data.is_interruptible && !data.inputs.ability3.is_pressed() {
if self.static_data.is_interruptible
&& !ability_key_is_pressed(data, self.static_data.ability_key)
{
handle_interrupt(data, &mut update);
match update.character {
CharacterState::SpinMelee(_) => {},
@ -140,7 +144,8 @@ impl CharacterBehavior for Data {
});
} else if update.energy.current() >= self.static_data.energy_cost
&& (self.spins_remaining != 0
|| (self.static_data.is_infinite && data.inputs.secondary.is_pressed()))
|| (self.static_data.is_infinite
&& ability_key_is_pressed(data, self.static_data.ability_key)))
{
let new_spins_remaining = if self.static_data.is_infinite {
self.spins_remaining