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.

69 lines
2.0 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 = 7
  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. func _exit_tree():
  33. for wall in walls:
  34. wall.queue_free()
  35. slave func slave_place_wall(tf):
  36. var wall = add_wall()
  37. finalize_wall(wall, tf)
  38. # Creates wall, adds to world, and returns the node
  39. func add_wall():
  40. var wall = preload("res://scenes/wall.tscn").instance()
  41. var friendly = player_info.is_right_team == master_player.player_info.is_right_team
  42. var color = friend_color if friendly else enemy_color
  43. wall.init(self, color)
  44. get_node("/root/Level").add_child(wall)
  45. return wall
  46. func finalize_wall(wall, tf=null):
  47. if tf:
  48. wall.set_transform(tf)
  49. wall.place()
  50. # Remember this wall, and return to non-placing state
  51. # We need to do this even as slave, because we keep track of the count
  52. walls.append(wall)
  53. check_wall_count()
  54. func check_wall_count():
  55. # If we've made max_walls, remove the first we made
  56. if walls.size() > max_walls:
  57. walls[0].queue_free()
  58. walls.pop_front()