2020-08-16 08:50:04 +02:00
|
|
|
extends Node
|
|
|
|
class_name IntroScript
|
|
|
|
|
|
|
|
export (NodePath) var dialogue_box_path
|
|
|
|
onready var dialogue_box = get_node(dialogue_box_path)
|
|
|
|
|
2020-08-17 11:37:50 +02:00
|
|
|
export (NodePath) var ely_sprite_path
|
|
|
|
onready var ely_sprite = get_node(ely_sprite_path)
|
|
|
|
|
2020-08-16 10:25:32 +02:00
|
|
|
export (NodePath) var herbert_sprite_path
|
|
|
|
onready var herbert_sprite = get_node(herbert_sprite_path)
|
|
|
|
|
2020-08-17 11:37:50 +02:00
|
|
|
export (String, FILE, '*.json') var intro_dialogue : String
|
2020-08-16 08:50:04 +02:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
assert(dialogue_box != null)
|
2020-08-16 10:25:32 +02:00
|
|
|
assert(herbert_sprite != null)
|
2020-08-16 08:50:04 +02:00
|
|
|
|
2020-08-17 10:45:39 +02:00
|
|
|
dialogue_box.connect('update', self, 'update_camera')
|
|
|
|
|
2020-08-16 10:25:32 +02:00
|
|
|
yield(get_tree().create_timer(2.0), 'timeout')
|
2020-08-17 11:37:50 +02:00
|
|
|
yield(start_dialogue(intro_dialogue), 'end')
|
2020-08-18 12:02:36 +02:00
|
|
|
get_tree().change_scene("res://scenes/game1.tscn")
|
2020-08-17 10:45:39 +02:00
|
|
|
|
|
|
|
func update_camera():
|
2020-08-17 11:37:50 +02:00
|
|
|
var animation = dialogue_box.expression
|
|
|
|
if animation == "":
|
|
|
|
animation = "idle"
|
|
|
|
|
|
|
|
var sprite : AnimatedSprite
|
|
|
|
if dialogue_box.character_name == 'Crab' || dialogue_box.character_name == 'Herbert':
|
2020-08-17 10:45:39 +02:00
|
|
|
herbert_sprite.show()
|
2020-08-17 11:37:50 +02:00
|
|
|
sprite = herbert_sprite
|
2020-08-17 10:45:39 +02:00
|
|
|
else:
|
|
|
|
herbert_sprite.hide()
|
2020-08-17 11:37:50 +02:00
|
|
|
sprite = ely_sprite
|
|
|
|
|
|
|
|
var is_old_animation_loop = sprite.get_sprite_frames().get_animation_loop(sprite.get_animation())
|
|
|
|
var is_new_animation_loop = sprite.get_sprite_frames().get_animation_loop(animation)
|
|
|
|
if !is_old_animation_loop || !is_new_animation_loop:
|
|
|
|
sprite.frame = 0
|
|
|
|
|
|
|
|
sprite.play(animation)
|
|
|
|
|
|
|
|
if !is_new_animation_loop:
|
|
|
|
yield(sprite, 'animation_finished')
|
|
|
|
dialogue_box.stop_waiting()
|
2020-08-16 10:25:32 +02:00
|
|
|
|
|
|
|
func start_dialogue(dialog_path : String) -> DialogueAction:
|
2020-08-16 08:50:04 +02:00
|
|
|
var dialogue = DialogueAction.new()
|
2020-08-16 10:25:32 +02:00
|
|
|
dialogue.dialogue_file_path = dialog_path
|
2020-08-16 08:50:04 +02:00
|
|
|
dialogue.dialogue_box = dialogue_box
|
|
|
|
dialogue.start()
|
2020-08-16 10:25:32 +02:00
|
|
|
return dialogue
|
|
|
|
|
|
|
|
var crab_finished = false
|
|
|
|
var crab_step = 0
|
|
|
|
func do_crab_step():
|
|
|
|
crab_finished = false
|
|
|
|
herbert_sprite.frame = 0
|
|
|
|
if crab_step == 0:
|
|
|
|
herbert_sprite.connect('animation_finished', self, 'crab_animation_finished')
|
|
|
|
herbert_sprite.play('eyes')
|
|
|
|
herbert_sprite.show()
|
|
|
|
elif crab_step == 1:
|
|
|
|
herbert_sprite.play('first_step')
|
|
|
|
elif crab_step == 2:
|
|
|
|
herbert_sprite.play('second_step')
|
|
|
|
elif crab_step == 3:
|
2020-08-17 10:45:39 +02:00
|
|
|
herbert_sprite.disconnect('animation_finished', self, 'crab_animation_finished')
|
|
|
|
herbert_sprite.play('third_step')
|
|
|
|
yield(herbert_sprite, 'animation_finished')
|
|
|
|
herbert_sprite.play('idle')
|
|
|
|
emit_signal("end_step")
|
2020-08-16 10:25:32 +02:00
|
|
|
crab_step += 1
|
|
|
|
|
|
|
|
func crab_animation_finished():
|
|
|
|
crab_finished = true
|
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
if crab_finished && event.is_action_pressed('ui_accept'):
|
|
|
|
do_crab_step()
|