goodnight_jellybean/godot/assets/audio/voice_lines/LineReader.gd

79 lines
1.7 KiB
GDScript

extends Node
var voice_script = [
["the_long", "book"],
["the_tall", "book"],
["the_door"],
["the_clock"],
["under_the_bed"],
["frog"],
["squirrel"],
["the_attic"],
["the_fridge"],
["the_tall", "book"],
["under_the_bed"],
["the_long", "book"],
["behind_the_bookshelf"],
]
export var impatience: float = 10.0
func stop_all():
for sound in $Sounds.get_children():
sound.stop()
func _ready():
yield(get_tree().create_timer(5.0), "timeout")
var _err = GlobalCursorState.connect("unchecked_goal", self, "check_goal")
script_loop()
var current_phrase = null
func read_line(line):
current_phrase = line
$Sounds/show_me.play()
yield($Sounds/show_me, "finished")
for phrase in line:
if completed:
break
var sound = get_node("Sounds/" + phrase)
sound.play()
yield(sound, "finished")
signal advance(did_time_out)
func script_loop():
for line in voice_script:
completed = false
$ImpatienceTimer.stop()
yield(read_line(line), "completed")
$ImpatienceTimer.start(impatience)
while not completed and yield(self, "advance"):
yield(read_line(line), "completed")
$ImpatienceTimer.start(impatience)
$ImpatienceTimer.stop()
yield(get_tree().create_timer(3), "timeout")
var _err = get_tree().change_scene("res://screens/finished.tscn")
var completed = false
func advance():
current_phrase = null
$ImpatienceTimer.stop()
completed = true
stop_all()
$Victory.play()
yield($Victory, "finished")
yield(get_tree().create_timer(3), "timeout")
emit_signal("advance", false)
func check_goal(phrase):
if current_phrase == phrase:
advance()
func _input(_event):
if Input.is_action_just_pressed("cheat"):
advance()
func _on_ImpatienceTimer_timeout():
emit_signal("advance", true)