add zoom sound effect when zooming map
This commit is contained in:
parent
1f3f0eec7a
commit
89cd374d9e
|
@ -294,6 +294,7 @@ python -m http.server -d wasm
|
||||||
- https://pixabay.com/sound-effects/box-crash-106687
|
- https://pixabay.com/sound-effects/box-crash-106687
|
||||||
- https://pixabay.com/sound-effects/electric-fan-motor-blades-removed-13169
|
- 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/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)
|
- 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)
|
- 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:
|
- 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
BIN
assets/sounds/zoom.ogg
Normal file
Binary file not shown.
34
src/audio.rs
34
src/audio.rs
|
@ -12,11 +12,12 @@
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::audio::{PlaybackMode, Volume};
|
use bevy::audio::{PlaybackMode, Volume};
|
||||||
use crate::var;
|
use crate::{camera, var};
|
||||||
|
|
||||||
const ASSET_CLICK: &str = "sounds/click-button-140881-crop.ogg";
|
const ASSET_CLICK: &str = "sounds/click-button-140881-crop.ogg";
|
||||||
const ASSET_SWITCH: &str = "sounds/typosonic-typing-192811-crop.ogg";
|
const ASSET_SWITCH: &str = "sounds/typosonic-typing-192811-crop.ogg";
|
||||||
const ASSET_WOOSH: &str = "sounds/woosh.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_INCOMING_MESSAGE: &str = "sounds/connect.ogg";
|
||||||
const ASSET_PING: &str = "sounds/connect.ogg";
|
const ASSET_PING: &str = "sounds/connect.ogg";
|
||||||
const ASSET_CONNECT: &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) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Startup, setup);
|
app.add_systems(Startup, setup);
|
||||||
app.add_systems(Update, toggle_bgm);
|
app.add_systems(Update, toggle_bgm);
|
||||||
|
app.add_systems(Update, play_zoom_sfx);
|
||||||
app.add_systems(PostUpdate, play_sfx);
|
app.add_systems(PostUpdate, play_sfx);
|
||||||
app.add_systems(PostUpdate, update_music);
|
app.add_systems(PostUpdate, update_music);
|
||||||
app.add_event::<PlaySfxEvent>();
|
app.add_event::<PlaySfxEvent>();
|
||||||
app.add_event::<ToggleMusicEvent>();
|
app.add_event::<ToggleMusicEvent>();
|
||||||
|
app.insert_resource(ZoomTimer(
|
||||||
|
Timer::from_seconds(0.09, TimerMode::Repeating)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Resource)] pub struct ZoomTimer(Timer);
|
||||||
|
|
||||||
pub enum Sfx {
|
pub enum Sfx {
|
||||||
IncomingChatMessage,
|
IncomingChatMessage,
|
||||||
Click,
|
Click,
|
||||||
Switch,
|
Switch,
|
||||||
Woosh,
|
Woosh,
|
||||||
|
Zoom,
|
||||||
Ping,
|
Ping,
|
||||||
Connect,
|
Connect,
|
||||||
EnterVehicle,
|
EnterVehicle,
|
||||||
|
@ -65,6 +72,7 @@ pub enum Sfx {
|
||||||
#[derive(Resource)] pub struct SoundClick(Handle<AudioSource>);
|
#[derive(Resource)] pub struct SoundClick(Handle<AudioSource>);
|
||||||
#[derive(Resource)] pub struct SoundSwitch(Handle<AudioSource>);
|
#[derive(Resource)] pub struct SoundSwitch(Handle<AudioSource>);
|
||||||
#[derive(Resource)] pub struct SoundWoosh(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 SoundIncomingMessage(Handle<AudioSource>);
|
||||||
#[derive(Resource)] pub struct SoundPing(Handle<AudioSource>);
|
#[derive(Resource)] pub struct SoundPing(Handle<AudioSource>);
|
||||||
#[derive(Resource)] pub struct SoundConnect(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(SoundClick(asset_server.load(ASSET_CLICK)));
|
||||||
commands.insert_resource(SoundSwitch(asset_server.load(ASSET_SWITCH)));
|
commands.insert_resource(SoundSwitch(asset_server.load(ASSET_SWITCH)));
|
||||||
commands.insert_resource(SoundWoosh(asset_server.load(ASSET_WOOSH)));
|
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(SoundIncomingMessage(asset_server.load(ASSET_INCOMING_MESSAGE)));
|
||||||
commands.insert_resource(SoundPing(asset_server.load(ASSET_PING)));
|
commands.insert_resource(SoundPing(asset_server.load(ASSET_PING)));
|
||||||
commands.insert_resource(SoundConnect(asset_server.load(ASSET_CONNECT)));
|
commands.insert_resource(SoundConnect(asset_server.load(ASSET_CONNECT)));
|
||||||
|
@ -172,6 +181,7 @@ pub fn play_sfx(
|
||||||
sound_click: Res<SoundClick>,
|
sound_click: Res<SoundClick>,
|
||||||
sound_switch: Res<SoundSwitch>,
|
sound_switch: Res<SoundSwitch>,
|
||||||
sound_woosh: Res<SoundWoosh>,
|
sound_woosh: Res<SoundWoosh>,
|
||||||
|
sound_zoom: Res<SoundZoom>,
|
||||||
sound_incoming_message: Res<SoundIncomingMessage>,
|
sound_incoming_message: Res<SoundIncomingMessage>,
|
||||||
sound_ping: Res<SoundPing>,
|
sound_ping: Res<SoundPing>,
|
||||||
sound_connect: Res<SoundConnect>,
|
sound_connect: Res<SoundConnect>,
|
||||||
|
@ -192,6 +202,7 @@ pub fn play_sfx(
|
||||||
Sfx::Switch => sound_switch.0.clone(),
|
Sfx::Switch => sound_switch.0.clone(),
|
||||||
Sfx::Click => sound_click.0.clone(),
|
Sfx::Click => sound_click.0.clone(),
|
||||||
Sfx::Woosh => sound_woosh.0.clone(),
|
Sfx::Woosh => sound_woosh.0.clone(),
|
||||||
|
Sfx::Zoom => sound_zoom.0.clone(),
|
||||||
Sfx::IncomingChatMessage => sound_incoming_message.0.clone(),
|
Sfx::IncomingChatMessage => sound_incoming_message.0.clone(),
|
||||||
Sfx::Ping => sound_ping.0.clone(),
|
Sfx::Ping => sound_ping.0.clone(),
|
||||||
Sfx::Connect => sound_connect.0.clone(),
|
Sfx::Connect => sound_connect.0.clone(),
|
||||||
|
@ -209,6 +220,8 @@ pub fn str2sfx(sfx_label: &str) -> Sfx {
|
||||||
return match sfx_label {
|
return match sfx_label {
|
||||||
"switch" => Sfx::Switch,
|
"switch" => Sfx::Switch,
|
||||||
"click" => Sfx::Click,
|
"click" => Sfx::Click,
|
||||||
|
"woosh" => Sfx::Woosh,
|
||||||
|
"zoom" => Sfx::Zoom,
|
||||||
"chat" => Sfx::IncomingChatMessage,
|
"chat" => Sfx::IncomingChatMessage,
|
||||||
"ping" => Sfx::Ping,
|
"ping" => Sfx::Ping,
|
||||||
"connect" => Sfx::Connect,
|
"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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@ use std::f32::consts::PI;
|
||||||
use std::f64::consts::PI as PI64;
|
use std::f64::consts::PI as PI64;
|
||||||
use crate::{actor, audio, hud, var};
|
use crate::{actor, audio, hud, var};
|
||||||
|
|
||||||
|
pub const INITIAL_ZOOM_LEVEL: f64 = 10.0;
|
||||||
|
|
||||||
pub struct CameraPlugin;
|
pub struct CameraPlugin;
|
||||||
|
|
||||||
impl Plugin for CameraPlugin {
|
impl Plugin for CameraPlugin {
|
||||||
|
@ -68,7 +70,7 @@ impl Default for MapCam {
|
||||||
Self {
|
Self {
|
||||||
initialized: false,
|
initialized: false,
|
||||||
zoom_level: 2.0,
|
zoom_level: 2.0,
|
||||||
target_zoom_level: 10.0,
|
target_zoom_level: INITIAL_ZOOM_LEVEL,
|
||||||
pitch: PI64 * 0.3,
|
pitch: PI64 * 0.3,
|
||||||
yaw: 0.0,
|
yaw: 0.0,
|
||||||
offset_x: 0.0,
|
offset_x: 0.0,
|
||||||
|
@ -154,6 +156,7 @@ pub fn update_map_camera(
|
||||||
q_target_changed: Query<(), Changed<hud::IsTargeted>>,
|
q_target_changed: Query<(), Changed<hud::IsTargeted>>,
|
||||||
mut mouse_events: EventReader<MouseMotion>,
|
mut mouse_events: EventReader<MouseMotion>,
|
||||||
mut er_mousewheel: EventReader<MouseWheel>,
|
mut er_mousewheel: EventReader<MouseWheel>,
|
||||||
|
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
) {
|
) {
|
||||||
if !settings.map_active || q_camera.is_empty() || q_playercam.is_empty() {
|
if !settings.map_active || q_camera.is_empty() || q_playercam.is_empty() {
|
||||||
|
|
Loading…
Reference in a new issue