-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenemy.gd
78 lines (62 loc) · 1.71 KB
/
enemy.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
73
74
75
76
77
78
extends CharacterBody2D
var speed = 60.0
@onready var animations = $AnimatedSprite2D
@onready var nav = $NavigationAgent2D as NavigationAgent2D
@export var pl : Node2D
var dead = false
var player_in_area = false
var player
var health = 100
var player_inattack_zone = false
var can_take_damage = true
func _ready():
dead = false
func _physics_process(delta):
deal_with_damage()
update_health()
if !dead:
$detection_area/CollisionShape2D.disabled = false
if player_in_area:
var dir = to_local(nav.get_next_path_position()).normalized()
velocity = dir * speed
animations.play("jump")
move_and_slide()
else:
animations.play("jump")
if dead:
$detection_area/CollisionShape2D.disabled = true
func _on_timer_timeout():
nav.target_position = pl.global_position
func _on_detection_area_body_entered(body):
if body.has_method("player"):
player = body
player_in_area = true
func _on_detection_area_body_exited(body):
if body.has_method("player"):
player_in_area = false
func enemy():
pass
func _on_enemy_hitbox_body_entered(body):
if body.has_method("player"):
player_inattack_zone = true
func _on_enemy_hitbox_body_exited(body):
if body.has_method("player"):
player_inattack_zone = false
func deal_with_damage():
if player_inattack_zone and World.player_current_attack == true :
if can_take_damage == true:
health = health - 20
$take_damage_cooldown.start()
can_take_damage = false
print("slime health + ", health)
if health == 0:
self.queue_free()
func _on_take_damage_cooldown_timeout():
can_take_damage = true
func update_health():
var healthBar = $healthBar
healthBar.value = health
if health >= 100:
healthBar.visible = false
else:
healthBar.visible = true