diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/GUI.gd | 8 | ||||
| -rw-r--r-- | scripts/Game.gd | 17 | ||||
| -rw-r--r-- | scripts/PlayerCharacter.gd | 34 | ||||
| -rw-r--r-- | scripts/Scene1.gd | 21 |
4 files changed, 40 insertions, 40 deletions
diff --git a/scripts/GUI.gd b/scripts/GUI.gd index de1106f..f885b10 100644 --- a/scripts/GUI.gd +++ b/scripts/GUI.gd @@ -12,10 +12,16 @@ func _ready(): # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(_delta): pass + +func _unhandled_input(event: InputEvent): + if event is InputEventKey: + if event.pressed and event.scancode == KEY_ESCAPE: + get_tree().quit() + if event.pressed and event.is_action_pressed("ui_accept"): + emit_signal("dialogue_next") func set_debug_text(text: String): debug_label.set_text(text) - func _on_NextButton_pressed(): emit_signal("dialogue_next") diff --git a/scripts/Game.gd b/scripts/Game.gd index bb74c44..25edde0 100644 --- a/scripts/Game.gd +++ b/scripts/Game.gd @@ -1,12 +1,16 @@ extends Node class_name Game +signal dialogue_begin() +signal dialogue_next() +signal dialogue_end() + onready var gui: GUI = $CanvasLayer/GUI var in_dialogue_with: Node = null # Called when the node enters the scene tree for the first time. -func _ready(): +func _ready(): update_debug_gui() connect_signals() @@ -50,6 +54,7 @@ func _on_PlayerCharacter_initiate_dialogue(other: Node): in_dialogue_with = other var dialogues = other.get_dialogue() $CanvasLayer/GUI/BottomRow/DialogueBox.set_visible(true) + emit_signal("dialogue_begin") for i in range(dialogues.size()): var d = dialogues[i] @@ -58,13 +63,9 @@ func _on_PlayerCharacter_initiate_dialogue(other: Node): $CanvasLayer/GUI/BottomRow/DialogueBox/Name.set_text(name) $CanvasLayer/GUI/BottomRow/DialogueBox/Text.set_text(body) print("[%s] %s" % [name, body]) - if dialogues.size() - i > 1: - yield($CanvasLayer/GUI, "dialogue_next") + yield($CanvasLayer/GUI, "dialogue_next") + emit_signal("dialogue_next") - yield($Level/YSort/PlayerCharacter, "end_dialogue") in_dialogue_with = null $CanvasLayer/GUI/BottomRow/DialogueBox.set_visible(false) - - -func _on_GUI_dialogue_next(): - pass # Replace with function body. + emit_signal("dialogue_end") diff --git a/scripts/PlayerCharacter.gd b/scripts/PlayerCharacter.gd index a4c902d..15b3421 100644 --- a/scripts/PlayerCharacter.gd +++ b/scripts/PlayerCharacter.gd @@ -3,14 +3,26 @@ class_name PlayerCharacter export (int) var speed = 8 export (float) var walk_wobble_coeff = 5 -export (NodePath) var gui_node +onready var gui: GUI = get_tree().get_root().get_node("Game/CanvasLayer/GUI") +onready var game: Game = get_tree().get_root().get_node("Game") signal initiate_dialogue(other) -signal end_dialogue() var velocity = Vector2() var look_dir = 1 # right = 1, left = -1 var in_dialogue: bool = false +enum DialogueState { + ACTIVE, # when dialogue in progress with a target + ENDED, # when dialogue exhausted via GUI + WALKED_OFF # when character moves out from dialogue target +} +var dialogue_state = DialogueState.WALKED_OFF + +func _ready(): + yield(get_tree(), "idle_frame") + var err = game.connect("dialogue_end", self, "_on_Game_dialogue_end") + if err: + push_error(err) func update_input_and_movement(): velocity = Vector2() @@ -45,19 +57,21 @@ func _process(_delta): $Sprite.set_scale(Vector2(look_dir, 1)) func _physics_process(_delta): - update_input_and_movement() - var slide_count = get_slide_count() + if dialogue_state != DialogueState.ACTIVE: + update_input_and_movement() - # If there are no collisions, player must have exited dialogue - if slide_count == 0 and in_dialogue: - in_dialogue = false - emit_signal("end_dialogue") + var slide_count = get_slide_count() + if slide_count == 0 and dialogue_state == DialogueState.ENDED: + dialogue_state = DialogueState.WALKED_OFF # If the player is colliding with a Dialogue group node and does not have an # active dialogue, run dialogue with the node for idx in slide_count: var coll = get_slide_collision(idx) - if coll.collider.is_in_group("Dialogue") and not in_dialogue: - in_dialogue = true + if coll.collider.is_in_group("Dialogue") and dialogue_state == DialogueState.WALKED_OFF: + dialogue_state = DialogueState.ACTIVE emit_signal("initiate_dialogue", coll.collider) break + +func _on_Game_dialogue_end(): + dialogue_state = DialogueState.ENDED diff --git a/scripts/Scene1.gd b/scripts/Scene1.gd deleted file mode 100644 index ce8376c..0000000 --- a/scripts/Scene1.gd +++ /dev/null @@ -1,21 +0,0 @@ -extends Node2D - - -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" - - -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(_delta): - pass - -func _unhandled_input(event): - if event is InputEventKey: - if event.pressed and event.scancode == KEY_ESCAPE: - get_tree().quit() |
