-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWolf.gd
More file actions
50 lines (38 loc) · 1.09 KB
/
Wolf.gd
File metadata and controls
50 lines (38 loc) · 1.09 KB
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
48
49
50
extends KinematicBody2D
export (int) var pats_required = 5
export (int) var motion_speed = 300
export (int) var stop_following_distance = 70
export (int) var following_delay = 3
var pats = 0
var following_player = false
var player = null
func _ready():
EventBus.register_listener(self, EventBus.ON_DEATH)
func _process(delta):
if not following_player or player == null:
return
var player_pos = player.global_position
var current_pos = global_position
if player_pos.distance_to(current_pos) < stop_following_distance:
$AnimationPlayer.play("idle")
return
if $AnimationPlayer.is_playing():
$AnimationPlayer.stop()
var direction = (player_pos - current_pos).normalized()
move_and_slide(direction * motion_speed)
func interact(actor):
pats += 1
if pats < 2:
$Say.play_speech("Grrrrrr!")
elif pats < 3:
$Say.play_speech("Grrr")
elif pats < 5:
$Say.play_speech("Woof woof!")
elif pats > 5:
$Say.play_speech("Bark!")
if pats == pats_required:
actor.find_node("Say").play_speech("Follow me friend!")
following_player = true
player = actor
func handle_on_death(player):
pass