blob: 8031d56949f4af73c5a9ae9376ef90f021447d0f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
|