2023-11-25 13:27:41 +00:00
|
|
|
extends TK_Context
|
2023-11-23 23:02:18 +00:00
|
|
|
class_name TK_GridContext
|
|
|
|
|
|
|
|
## todo: Cell visualization.
|
|
|
|
## todo: Integration of TileMap.
|
|
|
|
|
|
|
|
export var cell_size: Vector2 = Vector2(64, 64)
|
|
|
|
|
2023-11-25 13:27:41 +00:00
|
|
|
func local_position_to_context_position(p_position: Vector2) -> Vector2:
|
2023-11-24 10:11:00 +00:00
|
|
|
return p_position / cell_size
|
2023-11-23 23:02:18 +00:00
|
|
|
|
2023-11-25 13:27:41 +00:00
|
|
|
func is_path_traversible(p_from: Vector2, p_to: Vector2) -> bool:
|
|
|
|
# todo:
|
2023-11-23 23:02:18 +00:00
|
|
|
return true
|
2023-11-24 10:11:00 +00:00
|
|
|
|
2023-11-25 13:27:41 +00:00
|
|
|
func try_moving(p_game_object: Node2D, p_from: Vector2, p_to: Vector2) -> bool:
|
|
|
|
if not is_path_traversible(p_from, p_to):
|
2023-11-24 10:11:00 +00:00
|
|
|
return false
|
|
|
|
|
2023-11-25 13:27:41 +00:00
|
|
|
p_game_object.position = cell_size * p_to
|
2023-11-24 10:11:00 +00:00
|
|
|
return true
|