now this work
but angle isn't slowly
This commit is contained in:
291
aliens.cpp
291
aliens.cpp
@@ -5,304 +5,17 @@
|
||||
Aliens::Aliens(GameData *dataAliens)
|
||||
{
|
||||
data = dataAliens;
|
||||
TmpCells = new int*[data->size.width()];
|
||||
for (int i = 0; i < data->size.width(); i++) TmpCells[i] = new int[data->size.height()];
|
||||
}
|
||||
|
||||
|
||||
/*int Aliens::loadAlienImages(int PicType)
|
||||
{
|
||||
int i = 1;
|
||||
QString str1,str2;
|
||||
QPixmap tmpAlPixmap;
|
||||
str1.setNum(i);
|
||||
str2.setNum(PicType);
|
||||
while (i != 0) {
|
||||
str1.setNum(i);
|
||||
tmpAlPixmap.load("./images/Aliens/Al_" + str2 + "_" + str1 + ".png");
|
||||
//qDebug() << tmpAlPixmap.isNull();
|
||||
if (!tmpAlPixmap.isNull()) {
|
||||
//AlienPix.push_back(tmpAlPixmap);
|
||||
tmpAlPixmap = 0;
|
||||
i++;
|
||||
}
|
||||
else i = 0;
|
||||
}
|
||||
//qDebug() << "pictures:" << AlienPix.size();
|
||||
return i;
|
||||
}*/
|
||||
|
||||
|
||||
bool Aliens::AddAlien()
|
||||
{
|
||||
//bool ok;
|
||||
Alien al;
|
||||
//AliensCnt++;
|
||||
//if (CurWave < 0) CurWave = 0;
|
||||
//if (AliensCnt > curAliens.size()) ReDim Preserve Aliens(AliensCnt) As Alien
|
||||
//Aliens(AliensCnt) = SrcAliens(CurWave)
|
||||
curAliens.push_back(al); //srcAliens[CurWave]);
|
||||
//curAliens[AliensCnt].Level = CurWave + 1;
|
||||
curAliens[0].Position.pnt = data->start*data->cellsize;
|
||||
; //(int)(fh/2+(1-0.58)*6);
|
||||
//DestPoint.setX(fw - 1);
|
||||
//DestPoint.setY(fh / 2); //curAliens[AliensCnt].Position.pnt.y();
|
||||
curAliens[0].DestPnt = data->finish;
|
||||
// curAliens[AliensCnt].MaxFrame = 0; //srcAliens[CurWave].MaxFrame;
|
||||
// curAliens[AliensCnt].PicFrame = 0;
|
||||
return CreatePath(&curAliens[0]);
|
||||
}
|
||||
|
||||
|
||||
bool Aliens::CreatePath(Alien * al)
|
||||
{
|
||||
QPointF tp;
|
||||
QVector<QPointF> tmpPnt;
|
||||
//tmpPnt.clear();
|
||||
// AliensTmpDestX = fw - 1;//al->Destpnt.x();
|
||||
// AliensTmpDestY = fh / 2;//al->Destpnt.y();
|
||||
// al->Position.pnt.x() = 0;
|
||||
// al->Position.pnt.y() = fh / 2;
|
||||
for (int i = 0; i < data->size.width(); i++) {
|
||||
for (int j = 0; j < data->size.height(); j++) TmpCells[i][j] = data->Cells[i][j];
|
||||
}
|
||||
|
||||
al->path.clear();
|
||||
al->PathIndex = 0;
|
||||
if (WaveTrace(al))
|
||||
{
|
||||
for (int j=0; j<4; j++)
|
||||
{
|
||||
tmpPnt.clear();
|
||||
tp = al->path[0];
|
||||
tmpPnt.push_back(tp);
|
||||
for (int i = 0; i < al->path.size() - 1; i++)
|
||||
{
|
||||
tp.setX((al->path[i].x() + al->path[i + 1].x()) / 2);
|
||||
tp.setY((al->path[i].y() + al->path[i + 1].y()) / 2);
|
||||
tmpPnt.push_back(tp);
|
||||
}
|
||||
tp = al->path[al->path.size() - 1];
|
||||
tmpPnt.push_back(tp);
|
||||
//qDebug() << tmpPnt.size();
|
||||
al->path = tmpPnt;
|
||||
//al->Position.pnt.setX(al->path[0].x()*data->cellsize);
|
||||
//al->Position.pnt.setY(al->path[0].y()*data->cellsize);
|
||||
}
|
||||
tmpPnt.clear();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
//return WaveTrace(al);
|
||||
}
|
||||
|
||||
|
||||
void Aliens::updateAlienPos(Alien * al)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*bool Aliens::PathIntersect(Alien* Al, Rectangle rect)
|
||||
{
|
||||
//PathIntersect = False
|
||||
for (int i = Al->PathIndex; i<=Al->path.size(); i++) // To UBound(Al.path(), 1)
|
||||
if (Al->path[i].x + 0.5 >= rect.x0 - 1 && Al->path[i].x + 0.5 <= rect.x1 + 1)
|
||||
if (Al->path[i].y + 0.5 >= rect.y0 - 1 && Al->path[i].y + 0.5 <= rect.y1 + 1)
|
||||
return true; //PathIntersect = True //Exit Function
|
||||
return false;
|
||||
}*/
|
||||
|
||||
|
||||
bool Aliens::WaveTrace(Alien * al) {
|
||||
bool stop = false;
|
||||
int step = 2;
|
||||
QPoint cp, tp;
|
||||
QRect fr(0, 0, data->size.width(), data->size.height());
|
||||
QVector<QPoint> tmpp, curp;
|
||||
cp = al->Position.pnt/data->cellsize;
|
||||
curp.push_back(cp);
|
||||
TmpCells[cp.x()][cp.y()] = 1;
|
||||
qDebug() << "trace";
|
||||
while (!stop) {
|
||||
tmpp = curp;
|
||||
curp.clear();
|
||||
//qDebug() << tmpp.size();
|
||||
stop = true;
|
||||
for (int i = 0; i < tmpp.size(); i++) {
|
||||
cp = tmpp[i];
|
||||
if (cp == al->DestPnt) {
|
||||
TmpCells[cp.x()][cp.y()] = step;
|
||||
InvWaveTrace(cp, step, al);
|
||||
qDebug() << "true";
|
||||
qDebug() << al->path.size();
|
||||
return true;
|
||||
}
|
||||
tp.setX(cp.x() - 1);
|
||||
tp.setY(cp.y());
|
||||
if (fr.contains(tp) && TmpCells[tp.x()][tp.y()] == 0) {
|
||||
TmpCells[tp.x()][tp.y()] = step;
|
||||
curp.push_back(tp);
|
||||
stop = false;
|
||||
}
|
||||
tp.setX(cp.x() + 1);
|
||||
if (fr.contains(tp) && TmpCells[tp.x()][tp.y()] == 0) {
|
||||
TmpCells[tp.x()][tp.y()] = step;
|
||||
curp.push_back(tp);
|
||||
stop = false;
|
||||
}
|
||||
tp.setX(cp.x());
|
||||
tp.setY(cp.y() - 1);
|
||||
if (fr.contains(tp) && TmpCells[tp.x()][tp.y()] == 0) {
|
||||
TmpCells[tp.x()][tp.y()] = step;
|
||||
curp.push_back(tp);
|
||||
stop = false;
|
||||
}
|
||||
tp.setY(cp.y() + 1);
|
||||
if (fr.contains(tp) && TmpCells[tp.x()][tp.y()] == 0) {
|
||||
TmpCells[tp.x()][tp.y()] = step;
|
||||
curp.push_back(tp);
|
||||
stop = false;
|
||||
}
|
||||
}
|
||||
step++;
|
||||
}
|
||||
qDebug() << "false";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Aliens::InvWaveTrace(QPoint cp, int cnt, Alien * al)
|
||||
{
|
||||
QPoint wp, Ppnt;
|
||||
int Ind, c, AliensTmpDestX, AliensTmpDestY, xpp, ypp, xnn, ynn;
|
||||
unsigned char chk;
|
||||
Ppnt = wp = cp;
|
||||
xnn=0;
|
||||
xpp=0;
|
||||
ynn=0;
|
||||
ypp=0;
|
||||
cnt--;
|
||||
al->path.push_front(Ppnt);
|
||||
AliensTmpDestX = al->Position.pnt.x();
|
||||
AliensTmpDestY = al->Position.pnt.y();
|
||||
while (cnt > 1)
|
||||
{
|
||||
cnt--;
|
||||
chk = 0;
|
||||
Ind = 0;
|
||||
c = 0;
|
||||
if (wp.x() - 1 >= 0 && TmpCells[wp.x()-1][wp.y()] == cnt)
|
||||
{
|
||||
chk = chk | 0x01;
|
||||
c++;
|
||||
}
|
||||
if (wp.x() + 1 < data->size.width() && TmpCells[wp.x()+1][wp.y()] == cnt)
|
||||
{
|
||||
chk = chk | 0x02;
|
||||
c++;
|
||||
}
|
||||
if (wp.y() - 1 >= 0 && TmpCells[wp.x()][wp.y()-1] == cnt)
|
||||
{
|
||||
chk = chk | 0x04;
|
||||
c++;
|
||||
}
|
||||
if (wp.y() + 1 < data->size.height() && TmpCells[wp.x()][wp.y()+1] == cnt)
|
||||
{
|
||||
chk = chk | 0x08;
|
||||
c++;
|
||||
}
|
||||
if (c == 0 || chk == 0) qDebug() << "ERROR!!!";
|
||||
if (c > 1)
|
||||
{
|
||||
if ((chk & 0x01)==0x01 && (chk & 0x04)==0x04)
|
||||
{
|
||||
if (xnn <= ynn && Ind == 0){
|
||||
wp.rx()--;
|
||||
xnn++;
|
||||
if (xnn == ynn) xnn++;
|
||||
Ind = 1;
|
||||
} else if (Ind == 0) {
|
||||
wp.ry()--;
|
||||
ynn++;
|
||||
ynn++;
|
||||
Ind = 1;
|
||||
}
|
||||
}
|
||||
if ((chk & 0x02)==0x02 && (chk & 0x04)==0x04)
|
||||
{
|
||||
if (xpp <= ynn && Ind == 0){
|
||||
wp.rx()++;
|
||||
xpp++;
|
||||
if (xpp == ynn) xpp++;
|
||||
Ind = 1;
|
||||
} else if (Ind == 0) {
|
||||
wp.ry()--;
|
||||
ynn++;
|
||||
ynn++;
|
||||
Ind = 1;
|
||||
}
|
||||
}
|
||||
if ((chk & 0x01)==0x01 && (chk & 0x08)==0x08)
|
||||
{
|
||||
if (xnn <= ypp && Ind == 0){
|
||||
wp.rx()--;
|
||||
xnn++;
|
||||
if (xnn == ypp) xnn++;
|
||||
Ind = 1;
|
||||
} else if (Ind == 0) {
|
||||
wp.ry()++;
|
||||
ypp++;
|
||||
ypp++;
|
||||
Ind = 1;
|
||||
}
|
||||
}
|
||||
if ((chk & 0x02)==0x02 && (chk & 0x08)==0x08)
|
||||
{
|
||||
if (xpp <= ypp && Ind == 0){
|
||||
wp.rx()++;
|
||||
xpp++;
|
||||
if (xpp == ypp) xpp++;
|
||||
Ind = 1;
|
||||
} else if (Ind == 0) {
|
||||
wp.ry()++;
|
||||
ypp++;
|
||||
ypp++;
|
||||
Ind = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (c == 1 || Ind == 0)
|
||||
{
|
||||
xnn=0;
|
||||
xpp=0;
|
||||
ynn=0;
|
||||
ypp=0;
|
||||
if ((chk & 0x01)==0x01) {
|
||||
wp.rx()--;
|
||||
xnn++;
|
||||
}
|
||||
else if ((chk & 0x02)==0x02) {
|
||||
wp.rx()++;
|
||||
xpp++;
|
||||
}
|
||||
else if ((chk & 0x04)==0x04) {
|
||||
wp.ry()--;
|
||||
ynn++;
|
||||
}
|
||||
else if ((chk & 0x08)==0x08) {
|
||||
wp.ry()++;
|
||||
ypp++;
|
||||
}
|
||||
}
|
||||
Ppnt = wp;
|
||||
al->path.push_front(Ppnt);
|
||||
}
|
||||
curAliens.push_back(new Alien(data,0.1));
|
||||
return !curAliens.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
void Aliens::clearAliens()
|
||||
{
|
||||
//AliensCnt = - 1;
|
||||
curAliens.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user