action test_pather()
{
path_set(my, "path_000");
while(1)
{
var start_node = ll_pfind_getClosestNode(my, my.x, 1000, NULL);
var dest_node = ll_pfind_getClosestNode(my, target_pos.x, 1000, NULL);
LL_LIST *path = ll_pfind_getPathToTarget(my, start_node, dest_node, ll_pfind_astarCost);
LL_PFIND_PATH_NODE *node = (LL_PFIND_PATH_NODE *)path->first->data;
if (path) // path has been found
{
LL_PFIND_PATH_NODE *node;
// insert the start position as first node
node = ll_pfind_createPathNode(start_node);
ll_list_push(path, (void *)node);
// insert the destination as last node
node = ll_pfind_createPathNode(dest_node);
ll_list_add(path, (void *)node);
if (path->count > 0) // path is not empty yet
{
// get the next node of the path
LL_PFIND_PATH_NODE = (LL_PFIND_PATH_NODE *)path->first->data;
// move to the node
// [insert your movement code here]
// [the destination should be: node->pos]
// if the entity has reached the node
if (vec_dist(&my->x, &node) < 50)
{
// remove it from the path
ll_list_remove(path, path->first, ll_pfind_destroyPathNode);
}
}
else // path has been traversed completely
{
ll_list_destroy(path, NULL); // remove it
}
}
}
}