36 lines
1.1 KiB
GDScript
36 lines
1.1 KiB
GDScript
extends Node
|
|
var voices: Array[AudioStreamPlayer] = []
|
|
var tracks: Dictionary = {}
|
|
var tune: AudioStreamPlayer
|
|
var current := 0
|
|
func _ready() -> void:
|
|
for name in ["hop","plunk","squash","time","extra","coin-in"]:
|
|
tracks[name] = load("res://games/frogger/audio/sound-frogger-"+name+".wav")
|
|
for i in range(6):
|
|
var voice := AudioStreamPlayer.new()
|
|
voice.volume_db = -8
|
|
add_child(voice)
|
|
voices.append(voice)
|
|
tune = AudioStreamPlayer.new()
|
|
tune.stream = load("res://games/frogger/audio/frogger-music.mp3")
|
|
tune.volume_db = -12
|
|
add_child(tune)
|
|
tune.finished.connect(_music_finished)
|
|
func effect(name: String) -> void:
|
|
if get_parent().demo_active: return
|
|
if not tracks.has(name): return
|
|
var voice := voices[current]
|
|
current = (current+1)%voices.size()
|
|
voice.stream = tracks[name]
|
|
voice.play()
|
|
func music() -> void:
|
|
if get_parent().demo_active: return
|
|
if not tune.playing: tune.play()
|
|
func _music_finished() -> void:
|
|
if get_parent().phase in ["play","home"] and get_parent().music_enabled: tune.play()
|
|
func stop_music() -> void:
|
|
if tune: tune.stop()
|
|
func stop_all() -> void:
|
|
stop_music()
|
|
for voice in voices: voice.stop()
|