I added collision detection and updated the code the script runs but it doesn't find a path yet. not sure why.
// start initializing varriables
tile_size = 55;
node = new Array(49);
bestnode=null;
/* VISUAL MAP OF THE 49 NODES
* entity is always in node 24
*
* 00, 01, 02, 03, 04, 05, 06,
* 07, 08, 09, 10, 11, 12, 13,
* 14, 15, 16, 17, 18, 19, 20,
* 21, 22, 23, 24, 25, 26, 27,
* 28, 29, 30, 31, 32, 33, 34,
* 35, 36, 37, 38, 39, 40, 41,
* 42, 43, 44, 45, 46, 47, 48,
*
*/
// set the center square to the first parent because all moves are from this square
// g is essentially how far the entity has traveled to get to the node
// h is how far is left straight line to the target
parent = 24;
thisnode = parent;
for (j=0;j<49;j++){
node[j]={"open":null}
}
node[parent]={
"parent":null,
"pos":{"x":this.pos.x,"y":this.pos.y},
"open":true,
"g":0,
"h":Math.max(Math.abs(this.pos.x-targets[i].pos.x), Math.abs(this.pos.y-targets[i].pos.y)),
"f":null
}
node[thisnode].f = node[thisnode].g+node[thisnode].h
// end of initializing varriables
//check if parent node is target
//while there are open nodes
repeat=true;
while (repeat==true){
for (y=-1;y<=1;y++){
for (x=-1;x<=1;x++){
thisnode = parent+(7*y)+x;
if (thisnode>=0&&thisnode<49){
console.log(parent);
res = ig.game.collisionMap.trace( node[parent].pos.x , node[parent].pos.y, x*tile_size, y*tile_size, 1,1);
if (res.collision.x == true || res.collision.y == true){
node[thisnode].open=false;
}
skip=false;
if (node[thisnode].open==true&&node[thisnode].g < node[parent].g+tile_size){
skip=true;
}
if (node[thisnode].open!=false&&skip==false){
node[thisnode] ={
"parent":parent,
"pos":{"x":node[parent].pos.x+(x*tile_size),"y":node[parent].pos.y+(y*tile_size)},
"open":true,
"g":node[parent].g+tile_size,
"h":null,
"f":null
};
node[thisnode].h =Math.max(Math.abs(node[thisnode].pos.x-targets[i].pos.x), Math.abs(node[thisnode].pos.y-targets[i].pos.y)),
node[thisnode].f = node[thisnode].g+node[thisnode].h
if (bestnode==null){
bestnode = thisnode;
}
if (node[thisnode].f < node[bestnode].f){
bestnode=thisnode
}
}
}
}
}
node[parent].open = false;
parent=bestnode //set best node as next parent
bestnode=null;
repeat=false;
for (j=0;j<49;j++){
if (node[j].open==true){
repeat=true;
parent=j;
}
}
}
debugger