diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-05-23 23:45:28 +0200 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-05-23 23:45:52 +0200 |
commit | 7b11b1c2d8552b99f3e615a79621a2db769d9f5d (patch) | |
tree | 2a885d0835352ba961508921ffc872dcd46e905d /Overworld.gd |
initial commit
Diffstat (limited to 'Overworld.gd')
-rw-r--r-- | Overworld.gd | 47 |
1 files changed, 47 insertions, 0 deletions
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 |