Files

34 lines
1.3 KiB
GDScript

extends Node
const FILES := {"shot":"shoot", "invader":"invaderkilled", "death":"explosion", "march0":"fastinvader1", "march1":"fastinvader2", "march2":"fastinvader3", "march3":"fastinvader4", "ufo_hit":"ufo_highpitch"}
var tracks: Dictionary = {}
var voices: Array[AudioStreamPlayer] = []
var next_voice := 0
var saucer: AudioStreamPlayer
func _ready() -> void:
for key in FILES: tracks[key] = load("res://games/space_invaders/audio/%s.wav"%FILES[key])
for i in range(8):
var voice := AudioStreamPlayer.new()
voice.volume_db = -12
add_child(voice)
voices.append(voice)
saucer = AudioStreamPlayer.new()
saucer.stream = load("res://games/space_invaders/audio/ufo_lowpitch.wav")
saucer.volume_db = -16
add_child(saucer)
saucer.finished.connect(func():
if get_parent().saucer_active and not get_parent().demo and get_parent().phase=="play": saucer.play())
func effect(key: String) -> void:
if get_parent().demo or not get_parent().sound_enabled or not tracks.has(key): return
var voice := voices[next_voice]
next_voice = (next_voice+1)%voices.size()
voice.stream = tracks[key]
voice.play()
func ufo(active: bool) -> void:
if not active:
saucer.stop()
elif not get_parent().demo and get_parent().sound_enabled:
saucer.play()
func stop_all() -> void:
for voice in voices: voice.stop()
if saucer: saucer.stop()