A team game with an emphasis on movement (with no shooting), inspired by Overwatch and Zineth
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.5 KiB

  1. extends "res://scripts/player.gd"
  2. var merge_power = .75
  3. var merged = null
  4. var old_layer
  5. var old_mask
  6. var allow_merge_time = 0
  7. var allow_merge_threshold = 0.4
  8. var original_charge
  9. var boost_charge = 0
  10. func _ready():
  11. # Called every time the node is added to the scene.
  12. # Initialization here
  13. pass
  14. func _exit_tree():
  15. unmerge() # Checks if necessary automatically
  16. func _process(delta):
  17. if is_network_master():
  18. allow_merge_time += delta
  19. if not merged and allow_merge_time > allow_merge_threshold:
  20. var cols = get_colliding_bodies()
  21. for col in cols:
  22. if col.is_in_group("player"):
  23. var same_team = col.player_info.is_right_team == player_info.is_right_team
  24. if same_team:
  25. rpc("merge", col.get_name())
  26. if merged and Input.is_action_just_pressed("hero_3_unmerge"):
  27. rpc("unmerge")
  28. if merged:
  29. # Subtract and then add, so we can continously add this
  30. switch_charge -= boost_charge
  31. boost_charge = merged.switch_charge - original_charge
  32. switch_charge += boost_charge
  33. func control_player(state):
  34. if !merged:
  35. .control_player(state)
  36. func set_collisions(on):
  37. if on:
  38. collision_layer = old_layer
  39. collision_mask = old_mask
  40. gravity_scale = 1
  41. else:
  42. old_layer = collision_layer
  43. old_mask = collision_mask
  44. collision_layer = 0
  45. collision_mask = 0
  46. gravity_scale = 0
  47. func set_boosted_label(node, on):
  48. if on:
  49. var boosted_label = $Boosted.duplicate()
  50. boosted_label.show()
  51. node.add_child(boosted_label)
  52. else:
  53. var boosted_label = node.get_node("Boosted")
  54. boosted_label.queue_free()
  55. func set_boosting(is_boosting):
  56. set_collisions(!is_boosting)
  57. visible = !is_boosting
  58. if is_network_master():
  59. get_node("MasterOnly/Boosting").visible = is_boosting
  60. get_node(tp_camera).set_enabled(!is_boosting)
  61. func set_boosted(node, is_boosted):
  62. if is_network_master():
  63. # Assume their PoV, but no control
  64. node.get_node(node.tp_camera).set_enabled(is_boosted)
  65. if node.is_network_master():
  66. set_boosted_label(node, is_boosted)
  67. var ratio = (1 + merge_power)
  68. if !is_boosted:
  69. ratio = 1/ratio # Undo the effect
  70. node.walk_speed *= ratio
  71. node.air_accel *= ratio
  72. if is_boosted:
  73. original_charge = node.switch_charge
  74. boost_charge = 0
  75. sync func merge(node_name):
  76. set_boosting(true)
  77. var other = $"/root/Level/Players".get_node(node_name)
  78. set_boosted(other, true)
  79. merged = other
  80. sync func unmerge():
  81. if merged:
  82. set_boosted(merged, false)
  83. set_boosting(false)
  84. var pos = merged.get_translation()
  85. pos.z += 1
  86. set_translation(pos)
  87. merged = null