local_input.gd 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. class_name LocalInput
  2. extends Node
  3. # Sends commands from a local device
  4. signal dir_changed(new_dir: Vector2)
  5. signal main_action(pressed: bool)
  6. signal stop_action(pressed: bool)
  7. signal get_in_action(commander: LocalInput)
  8. signal analog_action(side: int, value: float)
  9. func _unhandled_input(event: InputEvent) -> void:
  10. if event.is_action("main"):
  11. main_action.emit(event.is_pressed())
  12. if event.is_action("stop"):
  13. stop_action.emit(event.is_pressed())
  14. elif event.is_action_pressed("get_in"):
  15. get_in_action.emit(self)
  16. elif event.is_action("move_left") or event.is_action("move_right") or event.is_action("move_back") or event.is_action("move_forward"):
  17. var dir: Vector2 = Input.get_vector("move_left", "move_right", "move_back", "move_forward")
  18. dir_changed.emit(dir)
  19. elif event.is_action("analog_main"):
  20. analog_action.emit(1, event.get_action_strength("analog_main"))
  21. elif event.is_action("analog_secondary"):
  22. analog_action.emit(-1, event.get_action_strength("analog_secondary"))
  23. func _on_title_screen_start_game() -> void:
  24. _enable()
  25. func _on_victory_menu_visibility_changed() -> void:
  26. queue_free()
  27. func _enable() -> void:
  28. set_process_mode(Node.PROCESS_MODE_PAUSABLE)