Skip to content

Commit

Permalink
mute child projectiles
Browse files Browse the repository at this point in the history
  • Loading branch information
ramirezmike committed Jul 29, 2024
1 parent bbc1f5d commit 5391e01
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/game/actor/attack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub struct Attack {
pub color: Color,
/// The relative distance to spawn projectiles from.
pub offset: f32,
/// Whether the attack should play audio.
pub muted: bool,
/// The key of the projectile to attack with.
#[serde(rename = "projectile")]
pub projectile_key: Option<String>,
Expand Down Expand Up @@ -63,6 +65,7 @@ impl Default for Attack {
force: 1.0,
color: Color::WHITE,
offset: 5.0,
muted: false,
projectile_key: None,
multi_shot: None,
child_projectile: None,
Expand Down Expand Up @@ -122,6 +125,7 @@ fn apply_attack(
let facing_direction = controller.aim.rotate(Vec2::from_angle(primary * TAU));
let mut child_attack = attack.clone();
child_attack.child_projectile = None;
child_attack.muted = true; // Don't let child projectiles play audio
child_attack.multi_shot = Some(MultiShot((*multi_shots).into()));
child_attack.projectile_key = child.projectile_key.clone();

Expand All @@ -133,7 +137,7 @@ fn apply_attack(
None
};

for shot in shots.iter() {
for (i, shot) in shots.iter().enumerate() {
// Projectiles get a boost if the actor is moving in the same direction.
let aligned_speed = velocity
.filter(|v| v.0 != Vec2::ZERO)
Expand All @@ -149,6 +153,7 @@ fn apply_attack(
faction,
attack.power,
attack.force * *shot * speed_force,
attack.muted || i != 0, // play audio only for first projectile
attack.color,
child_projectiles.clone(),
))
Expand Down
3 changes: 2 additions & 1 deletion src/game/combat/projectile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub fn projectile(
faction: Faction,
power: f32,
force: Vec2,
mute: bool,
color: impl Into<Color>,
child_projectiles: Option<(Attack, Facing)>,
) -> impl EntityCommand {
Expand All @@ -125,7 +126,7 @@ pub fn projectile(
x
};

if let (Faction::Player, Some(spawn_sfx)) = (faction, projectile.spawn_sfx) {
if let (false, Faction::Player, Some(spawn_sfx)) = (mute, faction, projectile.spawn_sfx) {
audio
.play(spawn_sfx)
.with_volume(projectile.spawn_sfx_volume);
Expand Down

0 comments on commit 5391e01

Please sign in to comment.