Skip to content

Commit

Permalink
Play laser fire sound even for remote players (#771)
Browse files Browse the repository at this point in the history
Fixes #770.
  • Loading branch information
Indy2222 authored Oct 12, 2023
1 parent c5a5d96 commit 4b89fc3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
7 changes: 0 additions & 7 deletions crates/combat/src/laser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use bevy::prelude::*;
use de_audio::spatial::{PlaySpatialAudioEvent, Sound};
use de_core::gamestate::GameState;
use parry3d::query::Ray;

Expand Down Expand Up @@ -81,7 +80,6 @@ fn fire(
sightline: LineOfSight,
mut health: EventWriter<LocalUpdateHealthEvent>,
mut trail: EventWriter<LocalLaserTrailEvent>,
mut start_sound: EventWriter<PlaySpatialAudioEvent>,
) {
for fire in fires.iter() {
let observation = sightline.sight(fire.ray(), fire.max_toi(), fire.attacker());
Expand All @@ -94,10 +92,5 @@ fn fire(
if let Some(entity) = observation.entity() {
health.send(LocalUpdateHealthEvent::new(entity, -fire.damage()));
}

start_sound.send(PlaySpatialAudioEvent::new(
Sound::LaserFire,
fire.ray().origin.into(),
));
}
}
25 changes: 22 additions & 3 deletions crates/combat/src/trail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use bevy::{
},
},
};
use de_audio::spatial::{PlaySpatialAudioEvent, Sound};
use de_core::{
cleanup::DespawnOnGameExit, gamestate::GameState, gconfig::GameConfig, state::AppState,
};
Expand All @@ -35,16 +36,22 @@ impl Plugin for TrailPlugin {
(
local_laser_trail
.before(MessagesSet::SendMessages)
.before(laser_trail),
remote_laser_trail.before(laser_trail),
laser_trail,
.before(TrailSet::Trail),
remote_laser_trail.before(TrailSet::Trail),
laser_trail.in_set(TrailSet::Trail),
laser_sound.in_set(TrailSet::Trail),
update,
)
.run_if(in_state(GameState::Playing)),
);
}
}

#[derive(Copy, Clone, Hash, Debug, PartialEq, Eq, SystemSet)]
enum TrailSet {
Trail,
}

#[derive(Event)]
pub(crate) struct LocalLaserTrailEvent(Ray);

Expand Down Expand Up @@ -178,6 +185,18 @@ fn laser_trail(
}
}

fn laser_sound(
mut events: EventReader<LaserTrailEvent>,
mut sound_events: EventWriter<PlaySpatialAudioEvent>,
) {
for event in events.iter() {
sound_events.send(PlaySpatialAudioEvent::new(
Sound::LaserFire,
event.0.origin.into(),
));
}
}

fn update(mut commands: Commands, time: Res<Time>, mut query: Query<(Entity, &mut Trail)>) {
for (entity, mut trail) in query.iter_mut() {
trail.tick(time.delta());
Expand Down

0 comments on commit 4b89fc3

Please sign in to comment.