add zoom sound effect when zooming map

This commit is contained in:
yuni 2024-04-25 04:15:57 +02:00
parent 1f3f0eec7a
commit 89cd374d9e
4 changed files with 38 additions and 2 deletions

View file

@ -294,6 +294,7 @@ python -m http.server -d wasm
- https://pixabay.com/sound-effects/box-crash-106687
- https://pixabay.com/sound-effects/electric-fan-motor-blades-removed-13169
- https://pixabay.com/sound-effects/whoosh-blow-flutter-shortwav-14678/
- https://pixabay.com/sound-effects/dslr-camera-sounds-26117/
- Music: [Cinematic Cello](https://pixabay.com/music/build-up-scenes-cinematic-cello-115667) by [Aleksey Chistilin](https://pixabay.com/users/lexin_music-28841948/), [Pixabay Content License](https://pixabay.com/service/license-summary)
- Star chart based on the [HYG Stellar database](https://github.com/astronexus/HYG-Database)
- Font Yupiter-Regular.ttf is placed under the SIL OPEN FONT LICENSE Version 1.1 and is based on:

BIN
assets/sounds/zoom.ogg Normal file

Binary file not shown.

View file

@ -12,11 +12,12 @@
use bevy::prelude::*;
use bevy::audio::{PlaybackMode, Volume};
use crate::var;
use crate::{camera, var};
const ASSET_CLICK: &str = "sounds/click-button-140881-crop.ogg";
const ASSET_SWITCH: &str = "sounds/typosonic-typing-192811-crop.ogg";
const ASSET_WOOSH: &str = "sounds/woosh.ogg";
const ASSET_ZOOM: &str = "sounds/zoom.ogg";
const ASSET_INCOMING_MESSAGE: &str = "sounds/connect.ogg";
const ASSET_PING: &str = "sounds/connect.ogg";
const ASSET_CONNECT: &str = "sounds/connect.ogg";
@ -34,18 +35,24 @@ impl Plugin for AudioPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup);
app.add_systems(Update, toggle_bgm);
app.add_systems(Update, play_zoom_sfx);
app.add_systems(PostUpdate, play_sfx);
app.add_systems(PostUpdate, update_music);
app.add_event::<PlaySfxEvent>();
app.add_event::<ToggleMusicEvent>();
app.insert_resource(ZoomTimer(
Timer::from_seconds(0.09, TimerMode::Repeating)));
}
}
#[derive(Resource)] pub struct ZoomTimer(Timer);
pub enum Sfx {
IncomingChatMessage,
Click,
Switch,
Woosh,
Zoom,
Ping,
Connect,
EnterVehicle,
@ -65,6 +72,7 @@ pub enum Sfx {
#[derive(Resource)] pub struct SoundClick(Handle<AudioSource>);
#[derive(Resource)] pub struct SoundSwitch(Handle<AudioSource>);
#[derive(Resource)] pub struct SoundWoosh(Handle<AudioSource>);
#[derive(Resource)] pub struct SoundZoom(Handle<AudioSource>);
#[derive(Resource)] pub struct SoundIncomingMessage(Handle<AudioSource>);
#[derive(Resource)] pub struct SoundPing(Handle<AudioSource>);
#[derive(Resource)] pub struct SoundConnect(Handle<AudioSource>);
@ -139,6 +147,7 @@ pub fn setup(
commands.insert_resource(SoundClick(asset_server.load(ASSET_CLICK)));
commands.insert_resource(SoundSwitch(asset_server.load(ASSET_SWITCH)));
commands.insert_resource(SoundWoosh(asset_server.load(ASSET_WOOSH)));
commands.insert_resource(SoundZoom(asset_server.load(ASSET_ZOOM)));
commands.insert_resource(SoundIncomingMessage(asset_server.load(ASSET_INCOMING_MESSAGE)));
commands.insert_resource(SoundPing(asset_server.load(ASSET_PING)));
commands.insert_resource(SoundConnect(asset_server.load(ASSET_CONNECT)));
@ -172,6 +181,7 @@ pub fn play_sfx(
sound_click: Res<SoundClick>,
sound_switch: Res<SoundSwitch>,
sound_woosh: Res<SoundWoosh>,
sound_zoom: Res<SoundZoom>,
sound_incoming_message: Res<SoundIncomingMessage>,
sound_ping: Res<SoundPing>,
sound_connect: Res<SoundConnect>,
@ -192,6 +202,7 @@ pub fn play_sfx(
Sfx::Switch => sound_switch.0.clone(),
Sfx::Click => sound_click.0.clone(),
Sfx::Woosh => sound_woosh.0.clone(),
Sfx::Zoom => sound_zoom.0.clone(),
Sfx::IncomingChatMessage => sound_incoming_message.0.clone(),
Sfx::Ping => sound_ping.0.clone(),
Sfx::Connect => sound_connect.0.clone(),
@ -209,6 +220,8 @@ pub fn str2sfx(sfx_label: &str) -> Sfx {
return match sfx_label {
"switch" => Sfx::Switch,
"click" => Sfx::Click,
"woosh" => Sfx::Woosh,
"zoom" => Sfx::Zoom,
"chat" => Sfx::IncomingChatMessage,
"ping" => Sfx::Ping,
"connect" => Sfx::Connect,
@ -235,3 +248,22 @@ pub fn update_music(
}
}
}
pub fn play_zoom_sfx(
time: Res<Time>,
mut timer: ResMut<ZoomTimer>,
mut last_zoom_level: Local<f64>,
mapcam: Res<camera::MapCam>,
mut ew_sfx: EventWriter<PlaySfxEvent>,
settings: Res<var::Settings>,
) {
if !timer.0.tick(time.delta()).just_finished() {
return;
}
if settings.map_active && (*last_zoom_level - mapcam.target_zoom_level).abs() > mapcam.target_zoom_level * 0.2 {
if *last_zoom_level != 0.0 && mapcam.target_zoom_level != camera::INITIAL_ZOOM_LEVEL {
ew_sfx.send(PlaySfxEvent(Sfx::Zoom));
}
*last_zoom_level = mapcam.target_zoom_level;
}
}

View file

@ -25,6 +25,8 @@ use std::f32::consts::PI;
use std::f64::consts::PI as PI64;
use crate::{actor, audio, hud, var};
pub const INITIAL_ZOOM_LEVEL: f64 = 10.0;
pub struct CameraPlugin;
impl Plugin for CameraPlugin {
@ -68,7 +70,7 @@ impl Default for MapCam {
Self {
initialized: false,
zoom_level: 2.0,
target_zoom_level: 10.0,
target_zoom_level: INITIAL_ZOOM_LEVEL,
pitch: PI64 * 0.3,
yaw: 0.0,
offset_x: 0.0,
@ -154,6 +156,7 @@ pub fn update_map_camera(
q_target_changed: Query<(), Changed<hud::IsTargeted>>,
mut mouse_events: EventReader<MouseMotion>,
mut er_mousewheel: EventReader<MouseWheel>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
keyboard_input: Res<ButtonInput<KeyCode>>,
) {
if !settings.map_active || q_camera.is_empty() || q_playercam.is_empty() {