cocos 寻路 c++实现

tagData* HelloWorld::xunlu(Vec2 start, Vec2 endP)
{

int i = 0;

while (open.size() != 0)
{
open.sort(comp);
tagData* tempStart = *open.begin();
open.pop_front();
close.push_back(tempStart);
list<tagData*> sur = surroundCaneach(tempStart->point, endP);
for (auto began = sur.begin(); began != sur.end(); began++)
{
if (exists(open, (*began)->point))
{
float pg = (*began)->prent == NULL ? 0 : (*began)->g;
float g = (*began)->g + pg;
if (g < (*began)->g)
{
(*began)->g = g;
(*began)->f = (*began)->g + (*began)->h;
(*began)->prent = tempStart;
}
}
else
{
float pg = (*began)->prent == NULL ? 0 : (*began)->g;
float g = (*began)->g + pg;
(*began)->g = g;
(*began)->h = fabs(endP.x - (*began)->point.x) + fabs(endP.y - (*began)->point.y);
(*began)->f = (*began)->g + (*began)->h;
(*began)->prent = tempStart;
open.push_back(*began);
}
}


for (auto began = open.begin(); began != open.end(); began++)
{
if (fabs((*began)->point.x - endP.x) < 8 && fabs((*began)->point.y - endP.y) < 8)
{
CCLOG("xunlu wanbi");
return *began;
}
}
i++;
CCLOG("%d", i);
}


return NULL;
}

猜你喜欢

转载自blog.csdn.net/u014660247/article/details/72615122
今日推荐