Skip to content

Commit

Permalink
Make dumbbell act as gravity scaling in combos
Browse files Browse the repository at this point in the history
This required changing combo from a resource to a component.
  • Loading branch information
haihala committed Aug 10, 2024
1 parent 68afba2 commit ced19b9
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 28 deletions.
4 changes: 2 additions & 2 deletions client/characters/src/characters/equipment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ pub fn universal_items() -> impl Iterator<Item = (ItemId, Item)> {
ItemId::Dumbbell,
Item {
cost: 350,
explanation: "Makes you ever so slightly heavier\n\nNot for training purposes"
explanation: "Makes you fall faster when comboed."
.into(),
effect: Stats {
gravity: 0.02,
gravity_scaling: 0.03,
..Stats::identity()
},
icon: Icon::Dumbbell,
Expand Down
8 changes: 5 additions & 3 deletions client/lib/src/damage/combo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use bevy::prelude::Resource;
use bevy::prelude::Component;

// A resource that exists or doesn't containing info on the ongoing combo if one is ongoing.
#[derive(Debug, Resource)]
pub struct Combo;
#[derive(Debug, Component)]
pub struct Combo {
pub hits: usize,
}
30 changes: 17 additions & 13 deletions client/lib/src/damage/hitreg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub struct HitPlayerQuery<'a> {
spawner: &'a mut HitboxSpawner,
pushbox: &'a Pushbox,
stats: &'a Stats,
combo: Option<&'a mut Combo>,
}

#[allow(clippy::type_complexity)]
Expand Down Expand Up @@ -131,7 +132,6 @@ pub(super) fn clash_parry(
pub(super) fn detect_hits(
clock: Res<Clock>,
mut notifications: ResMut<Notifications>,
combo: Option<Res<Combo>>,
mut hitboxes: Query<(
Entity,
&Owner,
Expand All @@ -142,7 +142,7 @@ pub(super) fn detect_hits(
)>,
players: Res<Players>,
hurtboxes: Query<(&Hurtbox, &Owner)>,
defenders: Query<(&Transform, &PlayerState, &InputParser)>,
defenders: Query<(&Transform, &PlayerState, &InputParser, Option<&Combo>)>,
) -> Vec<AttackConnection> {
hitboxes
.iter_mut()
Expand All @@ -157,7 +157,7 @@ pub(super) fn detect_hits(

let defender = players.get(defending_player);
let attacker = players.get(**hit_owner);
let (defender_tf, state, parser) = defenders.get(defender).unwrap();
let (defender_tf, state, parser, combo) = defenders.get(defender).unwrap();

let offset_hitbox = hitbox.with_offset(hitbox_tf.translation().truncate());

Expand Down Expand Up @@ -247,7 +247,6 @@ pub(super) fn apply_connections(
In(mut hits): In<Vec<AttackConnection>>,
mut commands: Commands,
mut notifications: ResMut<Notifications>,
combo: Option<Res<Combo>>,
clock: Res<Clock>,
mut players: Query<HitPlayerQuery>,
mut sounds: ResMut<Sounds>,
Expand Down Expand Up @@ -354,9 +353,14 @@ pub(super) fn apply_connections(
};

if !avoided {
if combo.is_none() {
commands.insert_resource(Combo);
sounds.play(SoundEffect::Whoosh); // TODO change sound effect
if let Some(mut combo) = defender.combo {
combo.hits += 1;
} else {
// First hit of a combo
commands.entity(hit.defender).insert(Combo { hits: 1 });

sounds.play(SoundEffect::Whoosh); // TODO: Opener sound effect
notifications.add(*attacker.player, "Opener!".to_owned());
if attacker.stats.opener_damage_multiplier > 1.0 {
attacker_actions = handle_opener(attacker_actions, attacker.stats);
attacker_actions.push(ActionEvent::ModifyResource(
Expand All @@ -365,12 +369,12 @@ pub(super) fn apply_connections(
));
defender_actions = handle_opener(defender_actions, attacker.stats);
}
notifications.add(*attacker.player, "Opener!".to_owned());
} else if defender.stats.direct_influence > 0.0 {
defender.velocity.add_impulse(defender.facing.mirror_vec2(
defender.parser.get_relative_stick_position().as_vec2()
* defender.stats.direct_influence,
));
if defender.stats.direct_influence > 0.0 {
defender.velocity.add_impulse(defender.facing.mirror_vec2(
defender.parser.get_relative_stick_position().as_vec2()
* defender.stats.direct_influence,
));
}
}
}

Expand Down
12 changes: 9 additions & 3 deletions client/lib/src/movement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use wag_core::{Area, Clock, Facing, Players, Stats, WAGStage};

use crate::{
camera::{CameraWrapper, VIEWPORT_HALFWIDTH},
damage::{HitTracker, HitboxSpawner},
damage::{Combo, HitTracker, HitboxSpawner},
};

pub const GROUND_PLANE_HEIGHT: f32 = 0.0;
Expand Down Expand Up @@ -57,6 +57,7 @@ impl Plugin for PhysicsPlugin {
}
}

#[allow(clippy::type_complexity)]
fn player_gravity(
clock: Res<Clock>,
mut players: Query<(
Expand All @@ -65,17 +66,22 @@ fn player_gravity(
&mut HitboxSpawner,
&Transform,
&Stats,
Option<&Combo>,
)>,
) {
for (mut velocity, mut state, mut spawner, tf, stats) in &mut players {
for (mut velocity, mut state, mut spawner, tf, stats, combo) in &mut players {
if state.active_cinematic().is_some() {
continue;
}

let is_airborne = tf.translation.y > GROUND_PLANE_HEIGHT;

if is_airborne {
velocity.add_impulse(-Vec2::Y * stats.gravity);
velocity.add_impulse(
-Vec2::Y
* (stats.gravity
+ stats.gravity_scaling * combo.map_or(0.0, |c| c.hits as f32)),
);

if state.is_grounded() {
state.jump();
Expand Down
13 changes: 6 additions & 7 deletions client/lib/src/player_state_management/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ use crate::damage::Combo;

pub fn stun_recovery(
mut commands: Commands,
combo: Option<Res<Combo>>,
mut players: Query<&mut PlayerState>,
mut players: Query<(&mut PlayerState, Option<&Combo>, Entity)>,
clock: Res<Clock>,
) {
let mut stunned_player = false;

for mut state in &mut players {
for (mut state, combo, entity) in &mut players {
if let Some(unstun_frame) = state.unstun_frame() {
if unstun_frame <= clock.frame {
state.recover(clock.frame);
Expand All @@ -22,10 +21,10 @@ pub fn stun_recovery(
if state.stunned() {
stunned_player = true;
}
}

if combo.is_some() && !stunned_player {
commands.remove_resource::<Combo>();
if combo.is_some() && !stunned_player {
// TODO: Combo popup
commands.entity(entity).remove::<Combo>();
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions client/wag_core/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct Stats {
// Movement
pub walk_speed: f32,
pub gravity: f32,
pub gravity_scaling: f32,
pub jump_force_multiplier: f32,

// Opener
Expand Down Expand Up @@ -59,6 +60,7 @@ impl Stats {

walk_speed: 0.0,
gravity: 0.0,
gravity_scaling: 0.0,
jump_force_multiplier: 1.0,

opener_damage_multiplier: 1.0,
Expand Down Expand Up @@ -86,6 +88,7 @@ impl Stats {

self.walk_speed += rhs.walk_speed;
self.gravity += rhs.gravity;
self.gravity_scaling += rhs.gravity_scaling;
self.jump_force_multiplier *= rhs.jump_force_multiplier;

self.opener_damage_multiplier *= rhs.opener_damage_multiplier;
Expand Down

0 comments on commit ced19b9

Please sign in to comment.