X-Git-Url: http://git.purplebirdman.com/frog-ninja.git/blobdiff_plain/e290448c2414d818fc183725d32150218218b7a3..refs/heads/state-machine:/player/input/InputHandler.gd diff --git a/player/input/InputHandler.gd b/player/input/InputHandler.gd index 9d0e7de..797aa77 100644 --- a/player/input/InputHandler.gd +++ b/player/input/InputHandler.gd @@ -2,28 +2,51 @@ extends Node class_name InputHandler -func get_camera_input_direction() -> Vector2: - return Input.get_vector( - "camera-left", "camera-right", "camera-up", "camera-down" - ) +var camera_input_method := CameraInput.MOUSE +var camera_input_direction := Vector2.ZERO + + +func _unhandled_input(event: InputEvent) -> void: + # If user clicks on the window, capture the mouse and direct the camera with it + if Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED: + return + + if event is InputEventMouseMotion: + camera_input_method = CameraInput.MOUSE + camera_input_direction = event.screen_relative + elif event is InputEventJoypadMotion: + # TODO: add these settings! + camera_input_method = CameraInput.JOYSTICK + camera_input_direction = Input.get_vector( + "camera-left", "camera-right", "camera-up", "camera-down" + ) func get_player_input() -> InputPacket: var p: InputPacket = InputPacket.new() - - p.movement_direction = Input.get_vector( + + p.camera_input_method = camera_input_method + if camera_input_method == CameraInput.MOUSE: + # TODO: clumsy handling of last relative mouse event! + if Input.get_last_mouse_velocity().length() > 0.05: + p.camera_input_direction = camera_input_direction + + p.player_movement_direction = Input.get_vector( "player-left", "player-right", "player-forward", "player-backward" ) - if p.movement_direction != Vector2.ZERO: - p.actions.append("walk") + if p.player_movement_direction != Vector2.ZERO: + p.player_actions.append("walk") if Input.is_action_just_pressed("player-dash"): - p.actions.append("dash") + p.player_actions.append("dash") if Input.is_action_just_pressed("player-slash"): - p.actions.append("slash") + p.player_actions.append("slash") + + if Input.is_action_just_pressed("player-shoot"): + p.player_actions.append("shoot") - if p.actions.is_empty(): - p.actions.append("idle") + if p.player_actions.is_empty(): + p.player_actions.append("idle") return p