Added more sound effeects. Added audio manager.
This commit is contained in:
25
AlientAttack.MonoGame/Audio/RateLimiter.cs
Normal file
25
AlientAttack.MonoGame/Audio/RateLimiter.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace AlienAttack.MonoGame.Audio;
|
||||
|
||||
public sealed class RateLimiter(float cooldownSeconds)
|
||||
{
|
||||
private readonly float _cooldownSeconds = cooldownSeconds <= 0 ? 0.0001f : cooldownSeconds;
|
||||
private float _timer = 0f;
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
_timer -= deltaTime;
|
||||
|
||||
if (_timer < 0f)
|
||||
_timer = 0f;
|
||||
}
|
||||
|
||||
public bool TryConsume()
|
||||
{
|
||||
if (_timer > 0f)
|
||||
return false;
|
||||
|
||||
_timer = _cooldownSeconds;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user