tochie-kit/nodes/singletons/InputUtils.gd

26 lines
1004 B
GDScript3
Raw Permalink Normal View History

extends Node
func input_event_to_8way_direction(p_event: InputEvent) -> Vector2:
var result := Vector2.ZERO
if p_event.is_action_pressed("move_down"):
result.y += 1
if p_event.is_action_pressed("move_right"):
result.x += 1
if p_event.is_action_pressed("move_up"):
result.y -= 1
if p_event.is_action_pressed("move_left"):
result.x -= 1
return result
func input_event_to_4way_direction(p_event: InputEvent) -> Vector2:
if p_event.is_action_pressed("move_down") and not p_event.is_action_pressed("move_up"):
return Vector2.DOWN
elif p_event.is_action_pressed("move_up") and not p_event.is_action_pressed("move_down"):
return Vector2.UP
elif p_event.is_action_pressed("move_left") and not p_event.is_action_pressed("move_right"):
return Vector2.LEFT
elif p_event.is_action_pressed("move_right") and not p_event.is_action_pressed("move_left"):
return Vector2.RIGHT
else:
return Vector2.ZERO