first_anniversary_godot_jam/scripts/MusicSingleton.gd

42 lines
809 B
GDScript

extends Node
func _ready() -> void:
print("Loaded Music singleton")
var change_slow_actions : Array = []
var gameSpeed : float = 1;
var musicType: int = 0;
func setSlowMusic():
setMusicType( -1 )
func setFastMusic():
setMusicType( 1 )
func setNormalMusic():
setMusicType( 0 )
func setMusicType( type:int ):
musicType = type;
gameSpeed = 0
if type == 1:
gameSpeed = 2
if type == -1:
gameSpeed = 0.5
func register_change_action(change_action : Node) -> void:
print("Registered change action")
change_slow_actions.append(change_action)
func unregister_change_action(change_action : Node) -> void:
print("Unregistered change action")
change_slow_actions.erase(change_action)
func change_music() -> void:
for change_action in change_slow_actions:
change_action.execute()