summaryrefslogtreecommitdiffstats
path: root/scripts/PlayerCharacter.gd
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/PlayerCharacter.gd')
-rw-r--r--scripts/PlayerCharacter.gd30
1 files changed, 15 insertions, 15 deletions
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