23 lines
619 B
GDScript
23 lines
619 B
GDScript
extends TK_Controller
|
|
class_name TK_4WayController
|
|
|
|
## Composable 4-way grid controller.
|
|
## Depends on placement below some Node2D below some GridContext.
|
|
|
|
# todo: Network player aware.
|
|
# todo: AI aware.
|
|
|
|
var _game_object: Node2D
|
|
|
|
func _enter_tree() -> void:
|
|
_game_object = get_parent()
|
|
|
|
func _input(p_event: InputEvent):
|
|
var direction := InputUtils.input_event_to_4way_direction(p_event)
|
|
if direction == Vector2.ZERO:
|
|
return
|
|
|
|
var cell = _context.local_position_to_context_position(_game_object.position)
|
|
var new_cell = cell + direction
|
|
_context.try_moving(_game_object, cell, new_cell)
|