-
Notifications
You must be signed in to change notification settings - Fork 1
/
midas.gd
437 lines (334 loc) · 10.9 KB
/
midas.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
extends CharacterBody3D
signal hpchange(hpvalue)
@onready var player = $"."
@onready var camera = $Camera3D
@export var SPEED = 8.4
@export var JUMP_VELOCITY = 15
var rp = true
@onready var clicktimer = $ClickTimer
# Get the gravity from the project settings to be synced with RigidBody nodes.
@export var gravity = 15
var canclick = true
var hp = 150
var max_hp = 150
@onready var ray = $Camera3D/ShapeCast3D
var dashes = 2
@onready var hitdelaytimer = $Hitdelaytimer
@onready var envir = "res://environment.tscn"
@onready var gray = $Camera3D/Grapcast
var collision_point = null
var grappling
var cangrapple = true
@onready var coinshot = $Camera3D/coinshot
var hookpoint
@onready var graptimer = $GrapTimer
@onready var righthand = $Armature/Skeleton3D/Sphere_008/rightHand
@onready var grappart = $grappart
@onready var coincast = $Camera3D/coincast
var candash = true
@onready var dashpartic = $dashpart
var grapcd = 0
var direction = Vector3.ZERO
@export var friction = 2
@onready var cdbar = $Control/GrapCooldownabar
@onready var textlabel = $Control/RichTextLabel
var canregen = true
@onready var regenstar = $reganstart
var supermaxhp = 150
var midasmat = load("res://midas.tres")
var midasmatblood = load("res://midasblood.tres")
var running = false
func _enter_tree():
set_multiplayer_authority(str(name).to_int())
func _ready():
if not is_multiplayer_authority(): return
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
cdbar.show()
textlabel.show()
camera.current = true
$Control/ProgressBar.show()
$Control/ProgressBar2.show()
func _unhandled_input(event):
if not is_multiplayer_authority(): return
if event is InputEventMouseMotion:
rotate_y(-event.relative.x * .005)
camera.rotate_x(-event.relative.y * .005)
camera.rotation.x = clamp(camera.rotation.x, -PI/2, PI/2)
func _physics_process(delta):
if not is_multiplayer_authority(): return
# Add the gravity.
grapcd = max(0, grapcd - delta)
$Control/GrapCooldownabar.value = grapcd
if not is_on_floor():
velocity.y -= gravity * delta * 5
velocity = velocity.lerp(direction * SPEED, friction * delta)
# Handle Jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
if Input.is_action_just_pressed("altclick"):
if canclick == true:
if running == false:
$Punchanim.play("Armature")
else:
$Punchanim.play("midarunpunchu")
canclick = false
clicktimer.start()
hitdelaytimer.start()
if Input.is_action_just_pressed("click"):
midshoot.rpc()
if Input.get_action_strength("grap"):
if grapcd <= 0:
if gray.is_colliding():
find_point()
if not collision_point == null:
if not grappling == true:
grappling = true
if grappling == true:
grappart.visible = true
line.rpc(righthand.global_position, collision_point)
var dir = camera.global_position.direction_to(collision_point)
velocity = dir * 17
move_and_slide()
if dashes == 0 and $Dashtimer.is_stopped():
$Dashtimer.start()
if grappling == false:
hookpoint = false
collision_point = null
grappart.visible = false
if Input.is_action_just_released("grap"):
grappling = false
cangrapple = false
if grapcd <= 0:
grapcd = 10
$Control/ProgressBar2.value = dashes
if Input.is_action_just_pressed("shift"):
if dashes > 0:
gravity = 0
SPEED = 60
dashpartic.visible = true
await get_tree().create_timer(.1).timeout
SPEED = 8.4
gravity = 15
dashpartic.visible = false
dashes -= 1
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var h_rot = global_transform.basis.get_euler().y
var f_input = Input.get_action_strength("Backword") - Input.get_action_strength("Forward")
var h_input = Input.get_action_strength("Right") - Input.get_action_strength("Left")
direction = Vector3(h_input, 0, f_input).rotated(Vector3.UP, h_rot).normalized()
if direction:
if not $AnimationPlayer.is_playing():
$AnimationPlayer.play("midarun")
running = true
else:
if not $AnimationPlayer.is_playing():
$AnimationPlayer.play("midle")
running = false
if is_on_floor():
velocity = velocity.lerp(direction * SPEED, friction * delta)
move_and_slide()
func _on_click_timer_timeout():
canclick = true
@rpc("any_peer")
func daehs():
hp -= 80
max_hp -= 80
print(hp)
$Control/ProgressBar.value = hp
if hp <= 0:
die()
hpchange.emit(hp)
canregen = false
regenstar.start()
blood.rpc()
@rpc("any_peer")
func daebs():
hp -= 40
max_hp -= 40
print(hp)
$Control/ProgressBar.value = hp
if hp <= 0:
die()
hpchange.emit(hp)
canregen = false
regenstar.start()
blood.rpc()
@rpc("any_peer")
func midaspunchdamage():
hp -= 150
print(hp)
$Control/ProgressBar.value = hp
if hp <= 0:
die()
hpchange.emit(hp)
canregen = false
regenstar.start()
blood.rpc()
@rpc("any_peer")
func midasshotdamage():
hp -= 10
print(hp)
$Control/ProgressBar.value = hp
if hp <= 0:
die()
hpchange.emit(hp)
canregen = false
regenstar.start()
blood.rpc()
@rpc("any_peer")
func herarrow():
hp -= 25
print(hp)
$Control/ProgressBar.value = hp
if hp <= 0:
die()
hpchange.emit(hp)
canregen = false
regenstar.start()
blood.rpc()
@rpc("any_peer")
func herspear():
hp -= 50
print(hp)
$Control/ProgressBar.value = hp
if hp <= 0:
die()
hpchange.emit(hp)
canregen = false
regenstar.start()
blood.rpc()
@rpc("any_peer")
func icarushot():
hp -= 10
print(hp)
$Control/ProgressBar.value = hp
if hp <= 0:
die()
hpchange.emit(hp)
canregen = false
regenstar.start()
blood.rpc()
func _on_hitdelaytimer_timeout():
ray.force_shapecast_update()
if ray.is_colliding():
var hit_player = ray.get_collider(1)
if hit_player != null:
hit_player.midaspunchdamage.rpc_id(hit_player.get_multiplayer_authority())
$Camera3D/hitdetect.visible = true
$AudioStreamPlayer2.play()
await get_tree().create_timer(.1).timeout
$Camera3D/hitdetect.visible = false
func find_point():
if not hookpoint:
collision_point = gray.get_collision_point()
hookpoint = true
func die():
max_hp = supermaxhp
hp = max_hp
position = Vector3.ZERO
$Control/ProgressBar.value = hp
func _on_grap_timer_timeout():
print("u can shoot")
cangrapple = true
pass # Replace with function body.
@rpc("authority", "call_local", "reliable")
func blood():
$Armature/Skeleton3D/Sphere_001.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_002.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_003.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_004.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_005.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_006.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_007.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_008.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_009.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_010.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_011.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_012.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_013.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_014.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_015.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_016.set_surface_override_material(0, midasmatblood)
$Armature/Skeleton3D/Sphere_017.set_surface_override_material(0, midasmatblood)
await get_tree().create_timer(.1).timeout
$Armature/Skeleton3D/Sphere_001.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_002.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_003.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_004.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_005.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_006.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_007.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_008.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_009.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_010.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_011.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_012.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_013.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_014.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_015.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_016.set_surface_override_material(0, midasmat)
$Armature/Skeleton3D/Sphere_017.set_surface_override_material(0, midasmat)
pass
@rpc("call_local")
func line(pos1: Vector3, pos2: Vector3, color = Color.DARK_KHAKI) -> MeshInstance3D:
var mesh_instance := MeshInstance3D.new()
var immediate_mesh := ImmediateMesh.new()
var material := ORMMaterial3D.new()
mesh_instance.mesh = immediate_mesh
immediate_mesh.surface_begin(Mesh.PRIMITIVE_LINES, material)
immediate_mesh.surface_add_vertex(pos1)
immediate_mesh.surface_add_vertex(pos2)
immediate_mesh.surface_end()
material.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
material.albedo_color = color
get_tree().get_root().add_child(mesh_instance)
await get_tree().create_timer(.1).timeout
mesh_instance.queue_free()
return mesh_instance
func _on_hpchange(hpvalue):
$Control/ProgressBar.value = hpvalue
pass # Replace with function body.
func _on_reganstart_timeout():
print("timeout")
$Hpregentimer.start()
canregen = true
pass # Replace with function body.
func _on_hpregentimer_timeout():
if canregen == true:
if not hp == max_hp:
hp += 50
$Control/ProgressBar.value = hp
print(hp)
else:
return
if hp > max_hp:
hp = max_hp
$Control/ProgressBar.value = hp
print(hp)
$Hpregentimer.stop()
pass # Replace with function body.
func _on_dashtimer_timeout():
if dashes != 2:
dashes +=1
pass # Replace with function body.
@rpc("call_local")
func midshoot():
if canclick == true:
if coincast.is_colliding():
var hit_player = coincast.get_collider()
hit_player.midasshotdamage.rpc_id(hit_player.get_multiplayer_authority())
$Camera3D/hitdetect.visible = true
grapcd -= 2
coinshot.visible = true
canclick = false
$AudioStreamPlayer.play()
await get_tree().create_timer(.1).timeout
coinshot.visible = false
$Camera3D/hitdetect.visible = false
await get_tree().create_timer(.25).timeout
canclick = true
else:
coinshot.visible = true
await get_tree().create_timer(.1).timeout
coinshot.visible = false