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.

127 lines
3.4 KiB

  1. extends "res://scripts/player.gd"
  2. var walls = []
  3. var placing_wall_node
  4. var is_placing_wall = false
  5. const max_walls = 100
  6. # --- Godot overrides ---
  7. func _process(delta):
  8. if is_network_master():
  9. # We allow you to just click to place, without needing to press E
  10. var place_wall = Input.is_action_just_pressed("hero_1_confirm_wall")
  11. if Input.is_action_just_pressed("hero_1_place_wall") or (place_wall and not is_placing_wall):
  12. # Press button twice to cancel
  13. if is_placing_wall:
  14. # We changed our mind, delete the placing wall
  15. placing_wall_node.queue_free()
  16. is_placing_wall = false
  17. else:
  18. # Make a floating placement wall
  19. placing_wall_node = add_wall()
  20. is_placing_wall = true
  21. if Input.is_action_just_pressed("hero_1_remove_wall"):
  22. var look_ray = get_node("TPCamera/Camera/Ray")
  23. var removing = look_ray.get_collider()
  24. var wall = walls.find(removing)
  25. if wall != -1:
  26. rpc("remove_wall", wall)
  27. if is_placing_wall or place_wall:
  28. position_wall(placing_wall_node)
  29. if place_wall:
  30. finalize_wall(placing_wall_node)
  31. rpc("slave_place_wall", placing_wall_node.get_transform())
  32. placing_wall_node = null
  33. is_placing_wall = false
  34. func _exit_tree():
  35. clear_walls()
  36. # --- Player overrides ---
  37. func spawn():
  38. .spawn()
  39. clear_walls()
  40. # --- Own ---
  41. # Find the point we're looking at, and put the wall there
  42. func position_wall(wall):
  43. var aim = get_node("Yaw/Pitch").get_global_transform().basis
  44. var look_ray = get_node("TPCamera/Camera/Ray")
  45. var pos = look_ray.get_collision_point()
  46. wall.set_translation(pos)
  47. var normal = look_ray.get_collision_normal()
  48. var towards = normal + pos
  49. var up = aim[2] # Wall should be horizontal to my view
  50. # This helps nearly horizontal walls be easier to make flat
  51. # We have two methods I'm deciding between
  52. var use_method_two = true
  53. if not use_method_two:
  54. # Method one: only allow horizontal or vertical, based on whether the surface faces you
  55. var wall_wall_margin = 0.75
  56. if normal.dot(Vector3(0,1,0)) < wall_wall_margin:
  57. var margin = 0.8
  58. if up.dot(normal) > margin: # The wall is facing us
  59. # We want flat
  60. up = Vector3(0,1,0)
  61. else:
  62. # We want straight
  63. up.y = 0
  64. else:
  65. # Method two: Make y more aggressive than other dimensions
  66. up.y = 3 * tanh(up.y)
  67. up = up.normalized()
  68. wall.look_at(towards, up)
  69. func clear_walls():
  70. for wall in walls:
  71. wall.queue_free()
  72. walls = []
  73. slave func slave_place_wall(tf):
  74. var wall = add_wall()
  75. finalize_wall(wall, tf)
  76. sync func remove_wall(index):
  77. walls[index].queue_free()
  78. walls.remove(index)
  79. # Creates wall, adds to world, and returns the node
  80. func add_wall():
  81. var wall = preload("res://scenes/wall.tscn").instance()
  82. var friendly = player_info.is_right_team == master_player.player_info.is_right_team
  83. var color = friend_color if friendly else enemy_color
  84. wall.init(self, color)
  85. get_node("/root/Level").add_child(wall)
  86. return wall
  87. func finalize_wall(wall, tf=null):
  88. if tf:
  89. wall.set_transform(tf)
  90. wall.place()
  91. # Remember this wall, and return to non-placing state
  92. # We need to do this even as slave, because we keep track of the count
  93. walls.append(wall)
  94. check_wall_count()
  95. func check_wall_count():
  96. # If we've made max_walls, remove the first we made
  97. if walls.size() > max_walls:
  98. walls[0].queue_free()
  99. walls.pop_front()
  100. # When placing, make the about-to-disappear wall translucent
  101. if walls.size() >= max_walls:
  102. walls[0].make_last()
  103. func sigmoid(x):
  104. var margin = 0.2
  105. return 0 if abs(x) < margin else x