-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenemy.gd
More file actions
82 lines (57 loc) · 1.42 KB
/
enemy.gd
File metadata and controls
82 lines (57 loc) · 1.42 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
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
79
80
81
82
extends CharacterBody2D
var speed = 300
var player_chase = false
var player = null
var direction = 0
var attack = 0
var hit = 0
var hp = 100 - hit
#var player_hp_singleton = preload("res://singleton.gd")
func set_hp(new_hp):
hp = new_hp
func get_hp():
return hp
func _physics_process(delta):
# print(attack)
if hp == 0 or hp < 1:
$AnimatedSprite2D.play("death")
await get_tree().create_timer(3).timeout
get_tree().change_scene_to_file("res://game_win.tscn")
# get_tree().change_scene_to_file("res://game_win.tscn")
else:
# print(attack)
if player_chase:
if attack == 1:
$AnimatedSprite2D.play("Attack")
else:
position += (player.position - position)/speed
if direction == 0:
$AnimatedSprite2D.play("Right")
else:
$AnimatedSprite2D.play("Left")
else:
$AnimatedSprite2D.play("Idle")
#func _on_detection_area_body_entered(body):
# player = body
# player_chase = true
func _on_detection_area_body_exited(body):
player = null
player_chase = false
$AnimatedSprite2D.play("Idle")
func _on_right_side_body_entered(body):
direction = 0
player = body
player_chase = true
func _on_left_side_body_entered(body):
direction = 1
player = body
player_chase = true
func _on_attack_range_body_entered(body):
attack = 1
func _on_attack_range_body_exited(body):
attack = 0
func _on_hitbox_body_entered(body):
$hpbar.value = hp
hit += 1
hp = 10 - hit
print("real hp is", hp)