-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenemy_shield.gd
72 lines (50 loc) · 1.29 KB
/
enemy_shield.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
extends CharacterBody2D
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
@onready var anim = $AnimatedSprite2D
var speed = 100
var attack = false
var alive = true
var chase = false
func _physics_process(delta):
if not is_on_floor():
velocity.y += gravity * delta
var player = $"../../Player"
var direction = (player.position - self.position).normalized()
if chase == true:
velocity.x = direction.x * speed
if attack == false and alive == true:
anim.play("Run")
else:
velocity.x = 0
anim.play("Idle")
if direction.x < 0:
$AnimatedSprite2D.flip_h = false
else:
$AnimatedSprite2D.flip_h = true
if attack == true and alive == true:
anim.play("Attack")
move_and_slide()
func _on_detector_body_entered(body):
if body.name == "Player":
chase = true
func _on_detector_body_exited(body):
if body.name == "Player":
chase = false
func _on_attack_body_entered(body):
if body.name == "Player":
if body.dashing == false:
$Attack2.play()
body.health -= 35
attack = true
await anim.animation_finished
attack = false
func death():
pass
func _on_area_2d_body_entered(body):
if body.name == "Player":
$Death.play()
$"../../Player".health += 25
alive = false
anim.play("Death")
await anim.animation_finished
queue_free()