-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.gd
49 lines (35 loc) · 904 Bytes
/
Player.gd
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
extends CharacterBody2D
var destination: Vector2
var listening = false
var moving = false
@onready var starting_position = global_position
signal died
signal restored
func _ready():
listening = true
func _physics_process(delta):
if position == destination:
moving = false
if listening and moving:
velocity = destination - position
var collision = move_and_collide(velocity * delta * 64)
if collision:
start_death()
func start_death():
listening = false
emit_signal("died")
$AnimationPlayer.play('die')
func move_in_direction(direction):
if listening:
destination = position + (direction*64)
moving=true
func go_home():
moving = false
destination = Vector2.ZERO
global_position=starting_position
$AnimationPlayer.play("appear")
func restore():
listening = true
emit_signal("restored")
func _on_visible_on_screen_notifier_2d_screen_exited():
start_death()