summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@valuemotive.com>2020-08-01 20:16:14 +0300
committerJan Tuomi <jan.tuomi@valuemotive.com>2020-08-01 20:16:14 +0300
commitf89994a8558ba59388c77b968ce5712bd709e15a (patch)
tree76d6c01b6812b441736c9706b9636e55a86dca36
parent3bcbdb538b69135907caf9e0ecc224a95c133155 (diff)
Improve stuff
-rw-r--r--scenes/GUI.tscn2
-rw-r--r--scripts/Game.gd23
-rw-r--r--scripts/PlayerCharacter.gd30
3 files changed, 32 insertions, 23 deletions
diff --git a/scenes/GUI.tscn b/scenes/GUI.tscn
index b9a55de..5ed79f1 100644
--- a/scenes/GUI.tscn
+++ b/scenes/GUI.tscn
@@ -33,7 +33,7 @@ margin_top = 520.0
margin_right = 984.0
margin_bottom = 560.0
rect_min_size = Vector2( 0, 40 )
-color = Color( 0.631373, 0.270588, 0.960784, 1 )
+color = Color( 0.403922, 0.360784, 0.54902, 1 )
[node name="Name" type="Label" parent="BottomRow/DialogueBox"]
anchor_top = -0.00774612
diff --git a/scripts/Game.gd b/scripts/Game.gd
index 087b5e1..09dd538 100644
--- a/scripts/Game.gd
+++ b/scripts/Game.gd
@@ -1,15 +1,14 @@
extends Node
class_name Game
-onready var gui: GUI = $CanvasLayer/GUI
-# Declare member variables here. Examples:
-# var a = 2
-# var b = "text"
+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():
update_debug_gui()
+ connect_signals()
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
@@ -18,10 +17,16 @@ func _ready():
func update_debug_gui():
var current_level = $Level.get_filename()
gui.set_debug_text("Level: %s" % current_level)
+
+func connect_signals():
+ var err = $Level/YSort/PlayerCharacter.connect("initiate_dialogue", self, "_on_PlayerCharacter_initiate_dialogue")
+ if err:
+ push_error(err)
func _on_Level_ready():
yield(get_tree(), "idle_frame")
update_debug_gui()
+ connect_signals()
func change_level(num: int):
var new_scene = "res://scenes/Level%s.tscn" % num
@@ -41,14 +46,18 @@ func change_level(num: int):
self.add_child(new_level)
new_level.set_name("Level")
-func run_dialogue(other: Node2D):
- var dialogues: Array = other.get_dialogue()
+func _on_PlayerCharacter_initiate_dialogue(other: Node):
+ in_dialogue_with = other
+ var dialogues = other.get_dialogue()
$CanvasLayer/GUI/BottomRow/DialogueBox.set_visible(true)
+
for d in dialogues:
var name = d["name"]
var body = d["body"]
$CanvasLayer/GUI/BottomRow/DialogueBox/Name.set_text(name)
$CanvasLayer/GUI/BottomRow/DialogueBox/Text.set_text(body)
print("[%s] %s" % [name, body])
- yield(get_tree().create_timer(1.0), "timeout")
+
+ yield($Level/YSort/PlayerCharacter, "end_dialogue")
+ in_dialogue_with = null
$CanvasLayer/GUI/BottomRow/DialogueBox.set_visible(false)
diff --git a/scripts/PlayerCharacter.gd b/scripts/PlayerCharacter.gd
index 4e194d0..a4c902d 100644
--- a/scripts/PlayerCharacter.gd
+++ b/scripts/PlayerCharacter.gd
@@ -5,11 +5,14 @@ export (int) var speed = 8
export (float) var walk_wobble_coeff = 5
export (NodePath) var gui_node
+signal initiate_dialogue(other)
+signal end_dialogue()
+
var velocity = Vector2()
var look_dir = 1 # right = 1, left = -1
-var dialogue_active_with: Node = null
+var in_dialogue: bool = false
-func get_input():
+func update_input_and_movement():
velocity = Vector2()
if Input.is_action_pressed('ui_right'):
velocity.x += 1
@@ -19,8 +22,10 @@ func get_input():
velocity.y += 1
if Input.is_action_pressed('ui_up'):
velocity.y -= 1
+
velocity = velocity.normalized() * speed
-
+ velocity = move_and_slide(velocity)
+
func _process(_delta):
# Update walking wobble
var is_moving = velocity.length_squared() > .0
@@ -38,26 +43,21 @@ func _process(_delta):
look_dir = -1
$Sprite.set_scale(Vector2(look_dir, 1))
-
-func run_dialogue(other: Node2D):
- dialogue_active_with = other
- var game: Game = get_tree().get_root().get_node("Game")
- game.run_dialogue(other)
func _physics_process(_delta):
- get_input()
- velocity = move_and_slide(velocity)
+ update_input_and_movement()
var slide_count = get_slide_count()
# If there are no collisions, player must have exited dialogue
- if slide_count == 0:
- dialogue_active_with = null
+ if slide_count == 0 and in_dialogue:
+ in_dialogue = false
+ emit_signal("end_dialogue")
# 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 dialogue_active_with == null:
- dialogue_active_with = coll.collider
- run_dialogue(coll.collider)
+ if coll.collider.is_in_group("Dialogue") and not in_dialogue:
+ in_dialogue = true
+ emit_signal("initiate_dialogue", coll.collider)
break