-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEn1.gd
54 lines (42 loc) · 1.2 KB
/
En1.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
extends KinematicBody2D
var motion = Vector2(0, 200)
var desired
var movable = false #if you die you cant move
var hp = 0
func _ready():
attack()
func attack():
if $Damage.is_colliding():
$Damage.get_collider().get_parent().hp -= 1
yield(get_tree().create_timer(1.0), "timeout")
yield(get_tree().create_timer(0.01), "timeout")
attack()
func _physics_process(_delta): #the a
desired = find_node_by_name(get_tree().get_root(), "Player").position
if desired.x + 25 < position.x and motion.x > -100 and movable == true:
motion.x -= 10
elif desired.x - 25 > position.x and motion.x < 100 and movable == true:
motion.x += 10
elif motion.x > 0:
motion.x -= 10
elif motion.x < 0:
motion.x += 10
if desired.y < position.y and is_on_wall() and movable == true:
motion.y = -300
elif motion.y < 300:
motion.y += 12
elif is_on_wall():
motion.y = 0
if position.y > 100:
position.y = -500
move_and_slide(motion)
if hp < 1:
movable == false
func find_node_by_name(root, name):
if(root.get_name() == name): return root
for child in root.get_children():
if(child.get_name() == name):
return child
var found = find_node_by_name(child, name)
if(found): return found
return null