hit sounds and general sound effects sys
This commit is contained in:
BIN
assets/sfx/hit/hit_00.ogg
Normal file
BIN
assets/sfx/hit/hit_00.ogg
Normal file
Binary file not shown.
BIN
assets/sfx/hit/hit_01.ogg
Normal file
BIN
assets/sfx/hit/hit_01.ogg
Normal file
Binary file not shown.
BIN
assets/sfx/hit/hit_02.ogg
Normal file
BIN
assets/sfx/hit/hit_02.ogg
Normal file
Binary file not shown.
@@ -1,5 +1,7 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
use crate::sounds::PlaySound;
|
||||||
|
|
||||||
#[derive(Component, Reflect, Default)]
|
#[derive(Component, Reflect, Default)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
#[require(Transform)]
|
#[require(Transform)]
|
||||||
@@ -28,9 +30,8 @@ fn on_collect(
|
|||||||
_trigger: Trigger<CashCollectEvent>,
|
_trigger: Trigger<CashCollectEvent>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut cash: ResMut<CashResource>,
|
mut cash: ResMut<CashResource>,
|
||||||
asset_server: Res<AssetServer>,
|
|
||||||
) {
|
) {
|
||||||
commands.spawn(AudioPlayer::new(asset_server.load("sfx/effects/cash.ogg")));
|
commands.trigger(PlaySound::CashCollect);
|
||||||
|
|
||||||
cash.cash += 100;
|
cash.cash += 100;
|
||||||
}
|
}
|
||||||
|
|||||||
20
src/gates.rs
20
src/gates.rs
@@ -1,42 +1,34 @@
|
|||||||
use crate::{cutscene::StartCutscene, keys::KeyCollected, movables::TriggerMovableEvent};
|
use crate::{
|
||||||
|
cutscene::StartCutscene, keys::KeyCollected, movables::TriggerMovableEvent, sounds::PlaySound,
|
||||||
|
};
|
||||||
use bevy::{prelude::*, utils::hashbrown::HashSet};
|
use bevy::{prelude::*, utils::hashbrown::HashSet};
|
||||||
|
|
||||||
pub fn plugin(app: &mut App) {
|
pub fn plugin(app: &mut App) {
|
||||||
app.add_observer(on_key);
|
app.add_observer(on_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_key(trigger: Trigger<KeyCollected>, mut commands: Commands, asset_server: Res<AssetServer>) {
|
fn on_key(trigger: Trigger<KeyCollected>, mut commands: Commands) {
|
||||||
match trigger.event().0.as_str() {
|
match trigger.event().0.as_str() {
|
||||||
"fence_gate" => {
|
"fence_gate" => {
|
||||||
commands.trigger(StartCutscene("fence_01".to_string()));
|
commands.trigger(StartCutscene("fence_01".to_string()));
|
||||||
|
|
||||||
//TODO: put into a sound effects system
|
|
||||||
commands.spawn((
|
|
||||||
AudioPlayer::new(asset_server.load("sfx/effects/gate.ogg")),
|
|
||||||
PlaybackSettings::DESPAWN,
|
|
||||||
));
|
|
||||||
|
|
||||||
let entities: HashSet<_> = vec!["fence_01", "fence_02"]
|
let entities: HashSet<_> = vec!["fence_01", "fence_02"]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| String::from(s))
|
.map(|s| String::from(s))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
commands.trigger(PlaySound::Gate);
|
||||||
commands.trigger(TriggerMovableEvent(entities));
|
commands.trigger(TriggerMovableEvent(entities));
|
||||||
}
|
}
|
||||||
"fence_shaft" => {
|
"fence_shaft" => {
|
||||||
commands.trigger(StartCutscene("cutscene_02".to_string()));
|
commands.trigger(StartCutscene("cutscene_02".to_string()));
|
||||||
|
|
||||||
//TODO: put into a sound effects system
|
|
||||||
commands.spawn((
|
|
||||||
AudioPlayer::new(asset_server.load("sfx/effects/gate.ogg")),
|
|
||||||
PlaybackSettings::DESPAWN,
|
|
||||||
));
|
|
||||||
|
|
||||||
let entities: HashSet<_> = vec!["fence_shaft"]
|
let entities: HashSet<_> = vec!["fence_shaft"]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| String::from(s))
|
.map(|s| String::from(s))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
commands.trigger(PlaySound::Gate);
|
||||||
commands.trigger(TriggerMovableEvent(entities));
|
commands.trigger(TriggerMovableEvent(entities));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|||||||
11
src/keys.rs
11
src/keys.rs
@@ -1,4 +1,6 @@
|
|||||||
use crate::{billboards::Billboard, player::Player, squish_animation::SquishAnimation};
|
use crate::{
|
||||||
|
billboards::Billboard, player::Player, sounds::PlaySound, squish_animation::SquishAnimation,
|
||||||
|
};
|
||||||
use avian3d::prelude::*;
|
use avian3d::prelude::*;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
@@ -46,7 +48,6 @@ fn collect_key(
|
|||||||
mut collision_event_reader: EventReader<CollisionStarted>,
|
mut collision_event_reader: EventReader<CollisionStarted>,
|
||||||
query_player: Query<&Player>,
|
query_player: Query<&Player>,
|
||||||
query_collectable: Query<&Key>,
|
query_collectable: Query<&Key>,
|
||||||
asset_server: Res<AssetServer>,
|
|
||||||
) {
|
) {
|
||||||
for CollisionStarted(e1, e2) in collision_event_reader.read() {
|
for CollisionStarted(e1, e2) in collision_event_reader.read() {
|
||||||
let collectable = if query_player.contains(*e1) && query_collectable.contains(*e2) {
|
let collectable = if query_player.contains(*e1) && query_collectable.contains(*e2) {
|
||||||
@@ -59,11 +60,7 @@ fn collect_key(
|
|||||||
|
|
||||||
let key = query_collectable.get(collectable).unwrap();
|
let key = query_collectable.get(collectable).unwrap();
|
||||||
|
|
||||||
commands.spawn((
|
commands.trigger(PlaySound::KeyCollect);
|
||||||
AudioPlayer::new(asset_server.load("sfx/effects/key_collect.ogg")),
|
|
||||||
PlaybackSettings::DESPAWN,
|
|
||||||
));
|
|
||||||
|
|
||||||
commands.trigger(KeyCollected(key.0.clone()));
|
commands.trigger(KeyCollected(key.0.clone()));
|
||||||
commands.entity(collectable).despawn_recursive();
|
commands.entity(collectable).despawn_recursive();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ mod npc;
|
|||||||
mod platforms;
|
mod platforms;
|
||||||
mod player;
|
mod player;
|
||||||
mod shooting;
|
mod shooting;
|
||||||
|
mod sounds;
|
||||||
mod squish_animation;
|
mod squish_animation;
|
||||||
mod tb_entities;
|
mod tb_entities;
|
||||||
|
|
||||||
@@ -89,6 +90,7 @@ fn main() {
|
|||||||
app.add_plugins(squish_animation::plugin);
|
app.add_plugins(squish_animation::plugin);
|
||||||
app.add_plugins(cutscene::plugin);
|
app.add_plugins(cutscene::plugin);
|
||||||
app.add_plugins(controls::plugin);
|
app.add_plugins(controls::plugin);
|
||||||
|
app.add_plugins(sounds::plugin);
|
||||||
|
|
||||||
app.insert_resource(AmbientLight {
|
app.insert_resource(AmbientLight {
|
||||||
color: Color::WHITE,
|
color: Color::WHITE,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{keys::KeySpawn, tb_entities::EnemySpawn};
|
use crate::{keys::KeySpawn, sounds::PlaySound, tb_entities::EnemySpawn};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
#[derive(Event, Reflect)]
|
#[derive(Event, Reflect)]
|
||||||
@@ -30,6 +30,8 @@ fn on_hit(
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
commands.trigger(PlaySound::Hit);
|
||||||
|
|
||||||
hp.0 = hp.0.saturating_sub(*damage as i32);
|
hp.0 = hp.0.saturating_sub(*damage as i32);
|
||||||
|
|
||||||
info!("npc hp changed: {} [{}]", hp.0, trigger.entity());
|
info!("npc hp changed: {} [{}]", hp.0, trigger.entity());
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{aim::AimState, npc::Hit};
|
use crate::{aim::AimState, npc::Hit, sounds::PlaySound};
|
||||||
|
|
||||||
#[derive(Event, Reflect)]
|
#[derive(Event, Reflect)]
|
||||||
pub enum TriggerState {
|
pub enum TriggerState {
|
||||||
@@ -12,17 +12,9 @@ pub fn plugin(app: &mut App) {
|
|||||||
app.add_observer(on_trigger_state);
|
app.add_observer(on_trigger_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_trigger_state(
|
fn on_trigger_state(trigger: Trigger<TriggerState>, mut commands: Commands, aim: Res<AimState>) {
|
||||||
trigger: Trigger<TriggerState>,
|
|
||||||
mut commands: Commands,
|
|
||||||
asset_server: Res<AssetServer>,
|
|
||||||
aim: Res<AimState>,
|
|
||||||
) {
|
|
||||||
if matches!(trigger.event(), TriggerState::Active) {
|
if matches!(trigger.event(), TriggerState::Active) {
|
||||||
commands.spawn((
|
commands.trigger(PlaySound::Gun);
|
||||||
AudioPlayer::new(asset_server.load("sfx/abilities/gun.ogg")),
|
|
||||||
PlaybackSettings::DESPAWN,
|
|
||||||
));
|
|
||||||
|
|
||||||
if let Some(target) = aim.target {
|
if let Some(target) = aim.target {
|
||||||
commands.entity(target).trigger(Hit { damage: 20 });
|
commands.entity(target).trigger(Hit { damage: 20 });
|
||||||
|
|||||||
47
src/sounds.rs
Normal file
47
src/sounds.rs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Event, Copy, Clone, Debug)]
|
||||||
|
pub enum PlaySound {
|
||||||
|
Hit,
|
||||||
|
KeyCollect,
|
||||||
|
Gun,
|
||||||
|
Gate,
|
||||||
|
CashCollect,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn plugin(app: &mut App) {
|
||||||
|
app.add_observer(spawn_sounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn_sounds(
|
||||||
|
trigger: Trigger<PlaySound>,
|
||||||
|
mut commands: Commands,
|
||||||
|
// sound_res: Res<AudioAssets>,
|
||||||
|
// settings: SettingsRead,
|
||||||
|
asset_server: Res<AssetServer>,
|
||||||
|
) {
|
||||||
|
let event = trigger.event();
|
||||||
|
|
||||||
|
// if !settings.is_sound_on() {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
let source = match event {
|
||||||
|
PlaySound::Hit => {
|
||||||
|
let version = rand::random::<u8>() % 3;
|
||||||
|
asset_server.load(format!("sfx/hit/hit_0{version}.ogg"))
|
||||||
|
}
|
||||||
|
PlaySound::KeyCollect => asset_server.load("sfx/effects/key_collect.ogg"),
|
||||||
|
PlaySound::Gun => asset_server.load("sfx/abilities/gun.ogg"),
|
||||||
|
PlaySound::Gate => asset_server.load("sfx/effects/gate.ogg"),
|
||||||
|
PlaySound::CashCollect => asset_server.load("sfx/effects/cash.ogg"),
|
||||||
|
};
|
||||||
|
|
||||||
|
commands.spawn((
|
||||||
|
AudioPlayer::new(source),
|
||||||
|
PlaybackSettings {
|
||||||
|
mode: bevy::audio::PlaybackMode::Despawn,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user