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.

52 lines
1.2 KiB

  1. extends "res://scripts/player.gd"
  2. var time = 0
  3. func _ready():
  4. ._ready()
  5. read_recording()
  6. func _physics_process(delta):
  7. time += delta
  8. func _integrate_forces(state):
  9. play_keys(state)
  10. func read_recording():
  11. # Gather all existing recordings
  12. var possible = []
  13. var begin = "%d-%d" % [player_info.level, player_info.hero]
  14. var path = "res://recordings/"
  15. var dir = Directory.new()
  16. dir.open(path)
  17. dir.list_dir_begin()
  18. while true:
  19. var fname = dir.get_next()
  20. print(fname)
  21. if fname == "":
  22. # Indicates end of directory
  23. break
  24. if fname.begins_with(begin):
  25. possible.append(fname)
  26. dir.list_dir_end()
  27. # Now pick a random one
  28. var fname = possible[randi() % possible.size()]
  29. # Read the file into recording.events for later use
  30. var frec = File.new()
  31. frec.open(path + fname, File.READ)
  32. recording = parse_json(frec.get_as_text())
  33. frec.close()
  34. func play_keys(phys_state):
  35. # states[0] is first state
  36. # states[0][0] is first state's time
  37. while float(recording[0][0]) <= time:
  38. # states[0][1] is first state's STATE
  39. var state = recording.pop_front()[1]
  40. for i in range(state.size()):
  41. state[i] = str2var(state[i])
  42. set_status(state)
  43. phys_state.integrate_forces()