Added more sound effects. Added initial weapon muzzle fire logic.
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using AlienAttack.MonoGame.Things.Items;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Audio;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Media;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AlienAttack.MonoGame.Audio;
|
||||
|
||||
@@ -19,6 +21,7 @@ public sealed class AudioManager
|
||||
private VariantSoundPool _enemyGunPool = default!;
|
||||
private VariantSoundPool _explosionPool = default!;
|
||||
private VariantSoundPool _impactPool = default!;
|
||||
private Dictionary<PickupKind, VariantSoundPool> _pickupPool = [];
|
||||
|
||||
// Rate limiters (global caps per category/event)
|
||||
private RateLimiter _playerGunLimiter = new(0.06f); // max ~16 plays/sec
|
||||
@@ -39,16 +42,9 @@ public sealed class AudioManager
|
||||
LoadImpactPool(content);
|
||||
LoadExplosionPool(content);
|
||||
|
||||
//var playerGun = content.Load<SoundEffect>("Audio/Sfx/player_fire");
|
||||
//var enemyGun = content.Load<SoundEffect>("Audio/Sfx/enemy_fire");
|
||||
//var explosion = content.Load<SoundEffect>("Audio/Sfx/explosion");
|
||||
//var impact = content.Load<SoundEffect>("Audio/Sfx/impact");
|
||||
|
||||
// Create pools with sane voice caps
|
||||
//_playerGunPool = new SoundPool(playerGun, maxVoices: 2);
|
||||
//_enemyGunPool = new SoundPool(enemyGun, maxVoices: 3);
|
||||
//_explosionPool = new SoundPool(explosion, maxVoices: 6);
|
||||
//_impactPool = new SoundPool(impact, maxVoices: 4);
|
||||
LoadShieldPickupPool(content);
|
||||
LoadAmmoPickupPool(content);
|
||||
LoadRocketsPickupPool(content);
|
||||
}
|
||||
|
||||
private void LoadPlayerGunPool(ContentManager content)
|
||||
@@ -111,6 +107,56 @@ public sealed class AudioManager
|
||||
_explosionPool = new VariantSoundPool(variants, voicesPerVariant: 1, rng: _random);
|
||||
}
|
||||
|
||||
private void LoadShieldPickupPool(ContentManager content)
|
||||
{
|
||||
var shieldVariants = new[]
|
||||
{
|
||||
content.Load<SoundEffect>("Sfx/Shield/SCIEnrg_Shield Activate_01_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Shield/SCIEnrg_Shield Activate_02_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Shield/SCIEnrg_Shield Activate_03_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Shield/SCIEnrg_Shield Activate_04_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Shield/SCIEnrg_Shield Activate_05_SFRMS_SCIWPNS")
|
||||
};
|
||||
|
||||
_pickupPool.Add(PickupKind.Shield, new VariantSoundPool(shieldVariants, voicesPerVariant: 1, rng: _random));
|
||||
}
|
||||
|
||||
private void LoadAmmoPickupPool(ContentManager content)
|
||||
{
|
||||
var variants = new[]
|
||||
{
|
||||
content.Load<SoundEffect>("Sfx/Reload/GUNMech_Insert Clip_01_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Reload/GUNMech_Insert Clip_02_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Reload/GUNMech_Insert Clip_03_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Reload/GUNMech_Insert Clip_04_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Reload/GUNMech_Insert Clip_05_SFRMS_SCIWPNS")
|
||||
};
|
||||
|
||||
_pickupPool.Add(PickupKind.Ammo, new VariantSoundPool(variants, voicesPerVariant: 1, rng: _random));
|
||||
}
|
||||
|
||||
private void LoadRocketsPickupPool(ContentManager content)
|
||||
{
|
||||
var variants = new[]
|
||||
{
|
||||
content.Load<SoundEffect>("Sfx/Rocket Launcher/GUNMech_Rocket Launcher Reload_01_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Rocket Launcher/GUNMech_Rocket Launcher Reload_02_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Rocket Launcher/GUNMech_Rocket Launcher Reload_03_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Rocket Launcher/GUNMech_Rocket Launcher Reload_04_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Rocket Launcher/GUNMech_Rocket Launcher Reload_05_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Rocket Launcher/GUNMech_Rocket Launcher Reload_06_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Rocket Launcher/GUNMech_Rocket Launcher Reload_07_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Rocket Launcher/GUNMech_Rocket Launcher Reload_08_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Rocket Launcher/GUNMech_Rocket Launcher Reload_09_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Rocket Launcher/GUNMech_Rocket Launcher Reload_10_SFRMS_SCIWPNS"),
|
||||
content.Load<SoundEffect>("Sfx/Rocket Launcher/GUNMech_Rocket Launcher Reload_11_SFRMS_SCIWPNS"),
|
||||
};
|
||||
|
||||
_pickupPool.Add(PickupKind.Rockets, new VariantSoundPool(variants, voicesPerVariant: 1, rng: _random));
|
||||
}
|
||||
|
||||
//GUNMech_Rocket Launcher Reload_01_SFRMS_SCIWPNS
|
||||
|
||||
// Call this once per frame
|
||||
public void Update(GameTime gameTime)
|
||||
{
|
||||
@@ -192,6 +238,21 @@ public sealed class AudioManager
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayPickup(PickupKind kind)
|
||||
{
|
||||
if (_pickupPool.TryGetValue(kind, out VariantSoundPool pool) == false)
|
||||
return;
|
||||
|
||||
float baseVol = 0.85f;
|
||||
float vol = baseVol * RandRange(0.95f, 1.05f);
|
||||
float pitch = RandRange(-0.04f, 0.04f);
|
||||
|
||||
pool.Play(
|
||||
volume: Clamp01(MasterVolume * SfxVolume * vol),
|
||||
pitch: pitch
|
||||
);
|
||||
}
|
||||
|
||||
// -----------------------
|
||||
// Music
|
||||
// -----------------------
|
||||
|
||||
Reference in New Issue
Block a user