summaryrefslogtreecommitdiffstats
path: root/scripts/PlayerCharacter.gd
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@valuemotive.com>2020-07-31 00:07:55 +0300
committerJan Tuomi <jan.tuomi@valuemotive.com>2020-07-31 00:07:55 +0300
commit5e45d3f7b24b022040f47a8ab2d6bf4bb4d9b8b6 (patch)
tree0f6df6c85826e7cb5bba3e7dd6c2aeb1c2e1575b /scripts/PlayerCharacter.gd
parent1c7db0e243d2a8a93d19d953ab656610aa4ea1b4 (diff)
Start building dialogue system
Diffstat (limited to 'scripts/PlayerCharacter.gd')
-rw-r--r--scripts/PlayerCharacter.gd25
1 files changed, 25 insertions, 0 deletions
diff --git a/scripts/PlayerCharacter.gd b/scripts/PlayerCharacter.gd
index 83fa8bd..9c95854 100644
--- a/scripts/PlayerCharacter.gd
+++ b/scripts/PlayerCharacter.gd
@@ -3,8 +3,10 @@ class_name PlayerCharacter
export (int) var speed = 8
export (float) var walk_wobble_coeff = 5
+
var velocity = Vector2()
var look_dir = 1 # right = 1, left = -1
+var dialogue_active_with: Node = null
func get_input():
velocity = Vector2()
@@ -35,10 +37,33 @@ func _process(_delta):
look_dir = -1
$Sprite.set_scale(Vector2(look_dir, 1))
+
+func run_dialogue(other):
+ dialogue_active_with = other
+ var dialogues: Array = other.get_dialogue()
+ for d in dialogues:
+ var name = d["name"]
+ var body = d["body"]
+ print("[%s] %s" % [name, body])
+
func _physics_process(_delta):
get_input()
velocity = move_and_slide(velocity)
+ 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 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)
+ break
func change_level(num: int):
var new_scene = "res://scenes/Scene" + String(num) + ".tscn"