-
Notifications
You must be signed in to change notification settings - Fork 1
/
character.gd
177 lines (147 loc) · 2.96 KB
/
character.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
extends RigidBody2D
var ammo = 10
var input = Vector2.ZERO
var max_speed = 40
var health = 100
var agro = []
func task_heal(task):
health += 2
task.succeed()
return
func task_is_health_not_full(task):
if health < 100:
task.succeed()
else:
task.failed()
return
func task_destroy(task):
queue_free()
task.succeed()
return
func task_is_died(task):
if health <= 0:
task.succeed()
else:
task.failed()
return
func task_is_alive(task):
if health > 0:
task.succeed()
else:
task.failed()
return
func task_is_reload(task):
if Input.is_key_pressed(KEY_R) and ammo < 10:
task.succeed()
else:
task.failed()
return
var start_reload = false
func task_start_reload(task):
start_reload = true
task.succeed()
return
func task_end_reload(task):
start_reload = false
task.succeed()
return
func task_is_reloading(task):
if start_reload:
task.succeed()
else:
task.failed()
return
func task_do_reload(task):
ammo = 10
task.succeed()
return
func _process(delta):
input = Vector2.ZERO
if Input.is_key_pressed(KEY_A):
input.x -= 1
if Input.is_key_pressed(KEY_D):
input.x += 1
if Input.is_key_pressed(KEY_W):
input.y -= 1
if Input.is_key_pressed(KEY_S):
input.y += 1
$ammo.text = str(ammo, "/10")
$hp.text = str("HP : ", health)
return
func task_speed(task):
max_speed = task.get_param(0)
task.succeed()
return
func task_is_input(task):
if input.length() > 0.1:
task.succeed()
else:
task.failed()
return
func task_do_move(task):
tspeed = input.normalized() * max_speed
task.succeed()
return
var speed = Vector2.ZERO
var tspeed = Vector2.ZERO
func _physics_process(delta):
speed = speed.linear_interpolate(tspeed, 0.5)
linear_velocity = speed
tspeed *= 0.8
return
func task_is_dash(task):
if Input.is_key_pressed(KEY_SHIFT):
task.succeed()
else:
task.failed()
return
func task_is_not__dash(task):
if not Input.is_key_pressed(KEY_SHIFT):
task.succeed()
else:
task.failed()
return
func task_look_at_mouse(task):
$AnimatedSprite.look_at(get_global_mouse_position())
task.succeed()
return
func task_is_firing(task):
if Input.is_mouse_button_pressed(BUTTON_LEFT):
task.succeed()
else:
task.failed()
return
var bs = preload("res://bullet.tscn")
func task_fire(task):
var bi = bs.instance()
var ang = Vector2(cos($AnimatedSprite.global_rotation), sin($AnimatedSprite.global_rotation))
bi.linear_velocity = ang * task.get_param(0)
bi.global_position = $AnimatedSprite/shoot.global_position
get_parent().add_child(bi)
ammo -= 1
task.succeed()
return
func task_say(task):
$say.text = task.get_param(0)
$Timer.stop()
$Timer.start()
task.succeed()
return
func task_anim(task):
$AnimatedSprite.play(task.get_param(0))
task.succeed()
return
func task_print(task):
# for i in range(task.get_param_count()):
# print(task.get_param(i))
task.succeed()
return
func task_is_out_of_ammo(task):
if ammo <= 0:
task.succeed()
else:
task.failed()
return
func _on_Timer_timeout():
$say.text = ""
return