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.

62 lines
1.9 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 = 3
  6. func _process(delta):
  7. if is_network_master():
  8. if Input.is_action_just_pressed("hero_1_place_wall"):
  9. # Press button twice to cancel
  10. if is_placing_wall:
  11. # We changed our mind, delete the placing wall
  12. placing_wall_node.queue_free()
  13. is_placing_wall = false
  14. else:
  15. # Make a floating placement wall
  16. placing_wall_node = add_wall()
  17. is_placing_wall = true
  18. if is_placing_wall:
  19. # Find the point we're looking at, and put the wall there
  20. var aim = get_node("Yaw/Pitch").get_global_transform().basis
  21. var look_ray = get_node("TPCamera/Camera/Ray")
  22. var pos = look_ray.get_collision_point()
  23. placing_wall_node.set_translation(pos)
  24. var towards = look_ray.get_collision_normal() + pos
  25. var up = -aim[2] # Wall should be horizontal to my view
  26. placing_wall_node.look_at(towards, up)
  27. if Input.is_action_just_pressed("hero_1_confirm_wall"):
  28. finalize_wall(placing_wall_node)
  29. rpc("slave_place_wall", placing_wall_node.get_transform())
  30. placing_wall_node = null
  31. is_placing_wall = false
  32. slave func slave_place_wall(tf):
  33. var wall = add_wall()
  34. finalize_wall(wall, tf)
  35. # Creates wall, adds to world, and returns the node
  36. func add_wall():
  37. var wall = preload("res://scenes/wall.tscn").instance()
  38. get_node("/root/Level").add_child(wall)
  39. return wall
  40. func finalize_wall(wall, tf=null):
  41. if tf:
  42. wall.set_transform(tf)
  43. # Originally, the wall is disabled to avoid weird physics
  44. wall.get_node("CollisionShape").disabled = false
  45. # Remember this wall, and return to non-placing state
  46. # We need to do this even as slave, because we keep track of the count
  47. walls.append(wall)
  48. check_wall_count()
  49. func check_wall_count():
  50. # If we've made max_walls, remove the first we made
  51. if walls.size() > max_walls:
  52. walls[0].queue_free()
  53. walls.pop_front()