From 7b11b1c2d8552b99f3e615a79621a2db769d9f5d Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 23 May 2024 23:45:28 +0200 Subject: initial commit --- Overworld.gd | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Overworld.gd (limited to 'Overworld.gd') diff --git a/Overworld.gd b/Overworld.gd new file mode 100644 index 0000000..8031d56 --- /dev/null +++ b/Overworld.gd @@ -0,0 +1,47 @@ +extends Node2D + + +const FOLLOW_SPEED = 30 + +@onready var current_node: OverworldPath = $OverworldPath +var follows_next_path = false +var follows_previous_path = false + + +func _process(delta): + var path_direction = "" + if Input.is_action_just_pressed("ui_up"): + path_direction = "up" + if Input.is_action_just_pressed("ui_down"): + path_direction = "down" + if Input.is_action_just_pressed("ui_left"): + path_direction = "left" + if Input.is_action_just_pressed("ui_right"): + path_direction = "right" + + if current_node.next_direction.has(path_direction): + follows_next_path = true + follows_previous_path = false + if current_node.progress > 0.0 and current_node.previous_direction.has(path_direction): + follows_next_path = false + follows_previous_path = true + elif current_node.progress == 0.0 and current_node.previous_path and current_node.previous_path.previous_direction.has(path_direction): + current_node = current_node.previous_path + follows_next_path = false + follows_previous_path = true + + if follows_next_path: + if current_node.progress < 1.0: + current_node.progress += delta + $AnimatedSprite2D.position = current_node.current_position + else: + follows_next_path = false + if current_node.next_path: + current_node = current_node.next_path + + if follows_previous_path: + if current_node.progress > 0.0: + current_node.progress -= delta + $AnimatedSprite2D.position = current_node.current_position + else: + follows_previous_path = false -- cgit v1.2.3