tochie-kit/nodes/GridContext.gd

21 lines
538 B
GDScript

extends Node2D
class_name TK_GridContext
## todo: Cell visualization.
## todo: Integration of TileMap.
export var cell_size: Vector2 = Vector2(64, 64)
func position_to_cell_position(p_position: Vector2) -> Vector2:
return p_position / cell_size
func is_cell_traversible(p_cell_position: Vector2) -> bool:
return true
func try_moving(p_node: Node2D, p_cell_position: Vector2) -> bool:
if not is_cell_traversible(p_cell_position):
return false
p_node.position = cell_size * p_cell_position
return true