Sound effects

This commit is contained in:
MaddoScientisto 2025-03-01 23:46:25 +01:00
commit 60ab375572
41 changed files with 504 additions and 15 deletions

View file

@ -4,6 +4,9 @@ namespace Cirno.Scripts;
public partial class AlarmManager : Node2D
{
[Export]
public AudioStream AlarmSound { get; private set; }
public static AlarmManager Instance { get; private set; }
public bool IsAlarmOn { get; private set; } = false;
@ -16,9 +19,20 @@ public partial class AlarmManager : Node2D
[Signal]
public delegate void AlarmDisabledEventHandler();
private AudioStreamPlayer2D _player;
public override void _Ready()
{
Instance = this;
if (AlarmSound is not null)
{
var player = new AudioStreamPlayer2D();
player.Stream = AlarmSound;
this.CallDeferred("add_child", player);
_player = player;
}
}
public void SoundAlarm(Vector2 location)
@ -29,11 +43,13 @@ public partial class AlarmManager : Node2D
EmitSignal(nameof(AlarmEnabled), location);
GD.Print($"Alarm sounded at {location}");
_player?.Play();
}
public void DisableAlarm()
{
IsAlarmOn = false;
EmitSignal(nameof(AlarmDisabled));
_player?.Stop();
}
}