mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-13 18:45:53 +00:00
Sound effects
This commit is contained in:
parent
80a13d047d
commit
60ab375572
41 changed files with 504 additions and 15 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue