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 Input.is_action_just_pressed("hero_1_confirm_wall"):
  19. finalize_wall(placing_wall_node)
  20. rpc("place_wall", placing_wall_node.get_transform())
  21. placing_wall_node = null
  22. is_placing_wall = false
  23. if is_placing_wall:
  24. # Find the point we're looking at, and put the wall there
  25. var aim = get_node("Yaw/Pitch").get_global_transform().basis
  26. var look_ray = get_node("Yaw/Pitch/Ray")
  27. var pos = look_ray.get_collision_point()
  28. placing_wall_node.set_translation(pos)
  29. var towards = look_ray.get_collision_normal() + pos
  30. var up = -aim[2] # Wall should be horizontal to my view
  31. placing_wall_node.look_at(towards, up)
  32. slave func place_wall(tf):
  33. var wall = add_wall()
  34. finalize_wall(wall, tf)
  35. check_wall_count()
  36. # Creates wall, adds to world, and returns the node
  37. func add_wall():
  38. var wall = preload("res://scenes/wall.tscn").instance()
  39. get_node("/root/world").add_child(wall)
  40. return wall
  41. func finalize_wall(wall, tf=null):
  42. if tf:
  43. wall.set_transform(tf)
  44. # Originally, the wall is disabled to avoid weird physics
  45. wall.get_node("CollisionShape").disabled = false
  46. # Remember this wall, and return to non-placing state
  47. # We need to do this even as slave, because we keep track of the count
  48. walls.append(wall)
  49. check_wall_count()
  50. func check_wall_count():
  51. # If we've made max_walls, remove the first we made
  52. if walls.size() > max_walls:
  53. walls[0].queue_free()
  54. walls.pop_front()