-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
AIworld3.gd
140 lines (75 loc) · 2.21 KB
/
AIworld3.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
extends KinematicBody2D
onready var Player = get_parent().get_parent().get_node("Player2/Player")
'''defining var and const'''
var UP = Vector2(0, -1)
var motion = Vector2()
var score = 0
var health = 4
var timer : float = 0
var is_dead = false
var react_time = 400
var next_direction = 0
var direction = 0
var next_dir_time = 0
var next_jump_time = -1
var eye_reach = 10
var vision = 1
var EnemySpeed = 1420
'''function for the game'''
func _ready():
set_physics_process(true)
set_process(true)
func dead():
is_dead = true
EnemySpeed = 0
motion = Vector2(0, 0)
$Area2D/CollisionShape2D.disabled = true
$CollisionShape2D.disabled = true
var female = get_parent().get_parent().get_node("EnemyHolder/AI/AnimatedSprite")
female.hide()
#
func set_dir(target_dir):
if next_direction != target_dir:
next_direction = target_dir
next_dir_time = OS.get_ticks_msec() + react_time
func _physics_process(delta):
motion.y += 50
var move = false
var friction = false
#
if Player.position.x < position.x + EnemySpeed:
set_dir(-1)
$AnimatedSprite.flip_h = true
$AnimatedSprite.play("Run")
elif Player.position.x > position.x - EnemySpeed:
set_dir(1)
$AnimatedSprite.flip_h = false
$AnimatedSprite.play("Run")
else:
set_dir(0)
#
friction = true
motion.x = 0
if OS.get_ticks_msec() > next_dir_time:
direction = next_direction
if OS.get_ticks_msec() > next_jump_time and next_jump_time != -1 and is_on_floor():
if Player.position.y < position.y - 64:
motion.y = -1000
next_jump_time = -1
motion.x = direction * 500
if Player.position.y < position.y - 64 and next_jump_time == -1:
next_jump_time = OS.get_ticks_msec() + react_time
if is_on_floor() and motion.y > 0:
motion.y = 0
if Input.is_action_pressed("ui_down") and $RayCast2D.is_colliding() and $RayCast2D2.is_colliding() and is_dead == false:
dead()
var AI = get_parent().get_parent().get_node("AI/Particles2D3")
AI.show()
var score = get_parent().get_parent().get_node("Player2/Player")
score.score1()
var kill = get_parent().get_parent().get_node("Sound/enemykill")
kill.play()
var timer = get_parent().get_node("Timerking")
timer.start()
motion = move_and_slide(motion, UP)
#