22 lines
1.0 KiB
GDScript
22 lines
1.0 KiB
GDScript
extends Node
|
|
var tracks: Dictionary = {}
|
|
var voice := AudioStreamPlayer.new()
|
|
var gates: Dictionary = {}
|
|
func _ready() -> void:
|
|
for name in ["human-die","startup","electrode-explode","level-transition","spheroid-spawn","enforcer-fire","player-lazer","grunt-walk","human-save","robot-explode","player-death","game-start","tank-explode","tank-projectile-bounce","tank-fire","quark-spawn","brain-explode","prog-transformation","human-to-prog","extra-life","high-score-top","brain-wave-start","spheroid-pop"]:
|
|
tracks[name] = load("res://games/robotron/audio/"+name+".wav")
|
|
voice.volume_db = -15
|
|
add_child(voice)
|
|
func effect(name: String) -> void:
|
|
if get_parent().demo or not get_parent().sound_enabled or not tracks.has(name): return
|
|
var now := Time.get_ticks_msec()
|
|
if now<int(gates.get(name,0)): return
|
|
# Limit repeated triggers while allowing each accepted sound to replace the last.
|
|
gates[name] = now+(90 if name=="player-lazer" else 180)
|
|
voice.stop()
|
|
voice.stream = tracks[name]
|
|
voice.play()
|
|
func stop_all() -> void:
|
|
voice.stop()
|
|
gates.clear()
|