thinking about updatePos()
This commit is contained in:
60
aliens.cpp
60
aliens.cpp
@@ -90,7 +90,14 @@ bool Aliens::AddAlien()
|
||||
for (int i = 0; i < fw; i++) {
|
||||
for (int j = 0; j < fh; j++) TmpCells[i][j] = Cells[i][j];
|
||||
}
|
||||
return (CreatePath(&curAliens[curAliens.size()-1]));
|
||||
if (CreatePath(&curAliens[curAliens.size()-1])) {
|
||||
curAliens[curAliens.size()-1].Position.pnt.setX(
|
||||
curAliens[curAliens.size()-1].path[0].x()*cellsize);
|
||||
curAliens[curAliens.size()-1].Position.pnt.setY(
|
||||
curAliens[curAliens.size()-1].path[0].y()*cellsize);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,8 +125,6 @@ bool Aliens::CreatePath(Alien * al)
|
||||
al->path = tmpPnt;
|
||||
}
|
||||
tmpPnt.clear();
|
||||
al->Position.pnt.setX(al->path[0].x()*cellsize);
|
||||
al->Position.pnt.setY(al->path[0].y()*cellsize);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -128,22 +133,24 @@ bool Aliens::CreatePath(Alien * al)
|
||||
|
||||
void Aliens::updateAliens()
|
||||
{
|
||||
qDebug("=========");
|
||||
qDebug("*********************");
|
||||
//qDebug() << curAliens[0].path;
|
||||
for (int i = 0; i < curAliens.size(); i++) updateAlienPos(&curAliens[i]);
|
||||
qDebug("*********************");
|
||||
}
|
||||
|
||||
|
||||
void Aliens::updateAlienPos(Alien * al)
|
||||
{
|
||||
float arctg = 0;
|
||||
float px,py;
|
||||
float px,py,dk;
|
||||
float dx,dy,fdx,fdy;
|
||||
//qDebug() << cellsize;
|
||||
px = al->path[al->PathIndex].x() - al->path[al->PathIndex - 1].x();
|
||||
py = al->path[al->PathIndex].y() - al->path[al->PathIndex - 1].y();
|
||||
dx = al->Position.pnt.x() - al->path[al->PathIndex].x() * (cellsize);
|
||||
dy = al->Position.pnt.y() - al->path[al->PathIndex].y() * (cellsize);
|
||||
dx = al->Position.pnt.x() - al->path[al->PathIndex].x() * cellsize;
|
||||
dy = al->Position.pnt.y() - al->path[al->PathIndex].y() * cellsize;
|
||||
dk = cellsize / sqrtf(px * px + py * py);
|
||||
qDebug() << dx << ";" << dy;
|
||||
qDebug() << px << ";" << py;
|
||||
//qDebug() << al->path;//[al->PathIndex];
|
||||
@@ -162,7 +169,7 @@ void Aliens::updateAlienPos(Alien * al)
|
||||
if (fdy < 0) al->Position.angle = 180 + al->Position.angle;
|
||||
//qDebug() << al->Position.angle;
|
||||
qDebug() << al->Position.pnt;
|
||||
if (qAbs(dx) <= al->Speed && qAbs(dy) <= al->Speed) {
|
||||
if (qAbs(dx) <= al->Speed * dk && qAbs(dy) <= al->Speed * dk) {
|
||||
qDebug("next");
|
||||
al->Position.pnt.setX(al->path[al->PathIndex].x() * cellsize);
|
||||
al->Position.pnt.setY(al->path[al->PathIndex].y() * cellsize);
|
||||
@@ -170,17 +177,17 @@ void Aliens::updateAlienPos(Alien * al)
|
||||
}
|
||||
else {
|
||||
qDebug("go");
|
||||
al->Position.pnt.setX(al->Position.pnt.x()+px * al->Speed * cellsize);
|
||||
al->Position.pnt.setY(al->Position.pnt.y()+py * al->Speed * cellsize);
|
||||
al->Position.pnt.setX(al->Position.pnt.x()+px * al->Speed * dk);
|
||||
al->Position.pnt.setY(al->Position.pnt.y()+py * al->Speed * dk);
|
||||
}
|
||||
qDebug() << al->Position.pnt;
|
||||
al->PicIndex++;
|
||||
qDebug() << "PicIndex" << al->PicIndex;
|
||||
qDebug() << "PicType" << al->PicType;
|
||||
qDebug() << AliensPixmaps[al->PicType].size();
|
||||
//qDebug() << "PicIndex" << al->PicIndex;
|
||||
//qDebug() << "PicType" << al->PicType;
|
||||
//qDebug() << AliensPixmaps[al->PicType].size();
|
||||
if (al->PicIndex >= AliensPixmaps[al->PicType].size()) al->PicIndex = 0;
|
||||
if (al->PathIndex >= al->path.size()) {
|
||||
qDebug() << "run agan";
|
||||
//qDebug() << "run agan";
|
||||
al->PathIndex = 1;
|
||||
al->Position.pnt.setX(al->path.value(0).x()*cellsize);
|
||||
al->Position.pnt.setY(al->path.value(0).y()*cellsize);
|
||||
@@ -202,24 +209,41 @@ void Aliens::updateAlienPos(Alien * al)
|
||||
bool Aliens::recreatePath()
|
||||
{
|
||||
QVector <QPointF> tmpPath;
|
||||
bool trace;
|
||||
QPointF tmppnt;
|
||||
//bool trace;
|
||||
for (int i = 0; i < fw; i++)
|
||||
for (int j = 0; j < fh; j++) TmpCells[i][j] = Cells[i][j];
|
||||
for (int i = 0; i < curAliens.size(); i++) {
|
||||
qDebug() << "##############";
|
||||
qDebug() << "Alinen N" << i;
|
||||
qDebug() << curAliens[i].Position.pnt;
|
||||
qDebug() << curAliens[i].PathIndex;
|
||||
if (curAliens[i].Position.pnt.x() - curAliens[i].path[curAliens[i].PathIndex].x()*cellsize < cellsize/2
|
||||
&& curAliens[i].Position.pnt.y() - curAliens[i].path[curAliens[i].PathIndex].y()*cellsize < cellsize/2)
|
||||
qDebug() << "Yes!!";
|
||||
else qDebug() << "NO!!";
|
||||
tmppnt = curAliens[i].Position.pnt;
|
||||
curAliens[i].Position.pnt.setX(curAliens[i].path[curAliens[i].PathIndex - 1].x() * cellsize);
|
||||
curAliens[i].Position.pnt.setY(curAliens[i].path[curAliens[i].PathIndex - 1].y() * cellsize);
|
||||
curAliens[i].PathIndex = 1;
|
||||
qDebug() << curAliens[i].Position.pnt;
|
||||
tmpPath = curAliens[i].path;
|
||||
curAliens[i].path.clear();
|
||||
trace = CreatePath(&curAliens[i]);
|
||||
if (!trace) {
|
||||
//trace = CreatePath(&curAliens[i]);
|
||||
if (!CreatePath(&curAliens[i])) {
|
||||
curAliens[i].path = tmpPath;
|
||||
curAliens[i].Position.pnt = tmppnt;
|
||||
tmpPath.clear();
|
||||
//trace = false;
|
||||
qDebug() << "##############";
|
||||
return false;
|
||||
}
|
||||
curAliens[i].Position.pnt = tmppnt;
|
||||
qDebug() << curAliens[i].Position.pnt;
|
||||
qDebug() << "===============";
|
||||
}
|
||||
qDebug() << trace;
|
||||
tmpPath.clear();
|
||||
qDebug() << "Re-create path sucsess!";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user