@@ -8,15 +8,26 @@ onready var fsm_animation = $AnimationTree.get("parameters/playback")
8
8
onready var sprite = $ cole_sprite
9
9
onready var navigation = $ Navigation
10
10
onready var talk_bubble = $ "Talk Bubble"
11
+ onready var talk_bubble_timer = get_node ("Talk Bubble/talk_bubble_timer" )
11
12
12
13
# Properties of our player
13
14
var current_velocity = Vector3 (0 , 0 , 0 ) # so we know its current speed
15
+ var current_destination # current position to which I am walking
16
+ var object_to_take
14
17
var speed = 5
18
+ var MINIMUM_DISTANCE = 0.5
15
19
16
20
# Variables for pathfinding -> The path our player has to follow
17
21
var path_idx = 0
18
22
var path = []
19
23
24
+ # Inventory
25
+ var inventory = []
26
+
27
+
28
+ func _ready ():
29
+ talk_bubble_timer .connect ("timeout" , self , "quiet" )
30
+
20
31
21
32
func key_input_velocity ():
22
33
# Function to control Cole using the keyboard
@@ -37,7 +48,9 @@ func key_input_velocity():
37
48
keyboard_input = true
38
49
39
50
if keyboard_input :
51
+ # Clear whatever we did with the mouse
40
52
path = []
53
+ object_to_take = null
41
54
42
55
# Modify current velocity
43
56
current_velocity = direction .normalized () * speed
@@ -60,10 +73,11 @@ func animate_player():
60
73
61
74
func walk_to (object ):
62
75
# Walk to an object
63
- var destination = object .position
76
+ current_destination = object .position
77
+ object_to_take = null
64
78
65
79
var begin = navigation .get_closest_point (self .transform .origin )
66
- var end = navigation .get_closest_point (destination )
80
+ var end = navigation .get_closest_point (current_destination )
67
81
68
82
path = navigation .get_simple_path (begin , end , true )
69
83
path_idx = 0
@@ -73,8 +87,35 @@ func walk_to(object):
73
87
74
88
75
89
func look (object ):
76
- talk_bubble .rect_position = Vector2 (40 , 40 )
77
- talk_bubble .text = object .description
90
+ say (object .description )
91
+
92
+
93
+ func quiet ():
94
+ talk_bubble .visible = false
95
+
96
+
97
+ func say (text ):
98
+ talk_bubble .text = text
99
+ talk_bubble .visible = true
100
+ talk_bubble_timer .start ()
101
+
102
+
103
+ func check_if_should_take_something ():
104
+ if object_to_take :
105
+ # Add object
106
+ inventory .append (object_to_take )
107
+
108
+ say ("I took the " + str (object_to_take .name ).to_lower ())
109
+
110
+ # Tell the object you took it
111
+ object_to_take .take ()
112
+
113
+
114
+ func take (object ):
115
+ if object .position != current_destination :
116
+ # First of all, walk to the object
117
+ walk_to (object )
118
+ object_to_take = object
78
119
79
120
80
121
func path_input_velocity ():
@@ -83,12 +124,18 @@ func path_input_velocity():
83
124
# There is still path to walk
84
125
var move_vec = (path [path_idx ] - transform .origin )
85
126
86
- if move_vec .length () < 1 :
127
+ if move_vec .length () < MINIMUM_DISTANCE :
87
128
# too short to walk
88
129
path_idx += 1
89
130
90
131
if path_idx < path .size ():
132
+ # So the animation doesn't stutter
91
133
move_vec = (path [path_idx ] - transform .origin )
134
+ else :
135
+ # We arrived
136
+ move_vec = Vector3 (0 , 0 , 0 )
137
+ current_destination = null
138
+ check_if_should_take_something ()
92
139
93
140
current_velocity = move_vec .normalized () * speed
94
141
0 commit comments