picture loading and rotate alien and retrace
This commit is contained in:
84
aliens.cpp
84
aliens.cpp
@@ -10,7 +10,7 @@ Aliens::Aliens(int TmpDestx, int TmpDesty, int afw, int afh, int alcellsize)
|
||||
fw = afw;
|
||||
fh = afh;
|
||||
//AliensCnt = -1;
|
||||
//CurWave = 0;
|
||||
CurWave = -1;
|
||||
Cells = new int*[fw];
|
||||
TmpCells = new int*[fw];
|
||||
for (int i = 0; i < fw; i++) {
|
||||
@@ -18,29 +18,58 @@ Aliens::Aliens(int TmpDestx, int TmpDesty, int afw, int afh, int alcellsize)
|
||||
TmpCells[i] = new int[fh];
|
||||
}
|
||||
clearCells();
|
||||
Alien al;
|
||||
al.PicType = 0;
|
||||
al.PathIndex = 0;
|
||||
al.PicFrame = 0;
|
||||
al.Speed = 1;
|
||||
srcAliens.push_back(al);
|
||||
CurWave = 0;
|
||||
}
|
||||
|
||||
|
||||
int Aliens::loadAlienImages(int PicType)
|
||||
bool Aliens::loadPixmaps(Alien * al)
|
||||
{
|
||||
if (AliensPixmaps.size() != 0) {
|
||||
for (int i = 0; i < AliensPixmaps.size(); i++) {
|
||||
if (AliensPixmaps[i].type == al->PicType) {
|
||||
qDebug() << "Pictures exist!";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
AlienImages * pixmaps;
|
||||
pixmaps = new AlienImages;
|
||||
if (loadPixmap(al->PicType,pixmaps) > 0) AliensPixmaps.push_back(* pixmaps);
|
||||
else return false;
|
||||
qDebug() << "Pictures loaded!";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int Aliens::loadPixmap(int PicType, AlienImages * pixmaps)
|
||||
{
|
||||
int i = 1;
|
||||
QString str1,str2;
|
||||
QPixmap tmpAlPixmap;
|
||||
str1.setNum(i);
|
||||
str2.setNum(PicType);
|
||||
qDebug() << PicType;
|
||||
while (i != 0) {
|
||||
str1.setNum(i);
|
||||
tmpAlPixmap.load("./images/Aliens/Al_" + str2 + "_" + str1 + ".png");
|
||||
qDebug() << tmpAlPixmap.isNull();
|
||||
//qDebug() << tmpAlPixmap.isNull();
|
||||
if (!tmpAlPixmap.isNull()) {
|
||||
//AlienPix.push_back(tmpAlPixmap);
|
||||
pixmaps->pix.push_back(tmpAlPixmap);
|
||||
pixmaps->type = PicType;
|
||||
tmpAlPixmap = 0;
|
||||
i++;
|
||||
}
|
||||
else i = 0;
|
||||
}
|
||||
//qDebug() << "pictures:" << AlienPix.size();
|
||||
return i;
|
||||
qDebug() << "pictures:" << pixmaps->pix.size();
|
||||
return pixmaps->pix.size();
|
||||
}
|
||||
|
||||
|
||||
@@ -53,24 +82,24 @@ void Aliens::clearCells()
|
||||
bool Aliens::AddAlien()
|
||||
{
|
||||
//bool ok;
|
||||
Alien al;
|
||||
//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.push_back(srcAliens.at(CurWave));
|
||||
//curAliens[AliensCnt].Level = CurWave + 1;
|
||||
curAliens[0].Position.pnt.setX(0);
|
||||
curAliens[0].Position.pnt.setY(fh/2); //(int)(fh/2+(1-0.58)*6);
|
||||
curAliens[curAliens.size()-1].Position.pnt.setX(0);
|
||||
curAliens[curAliens.size()-1].Position.pnt.setY(fh/2); //(int)(fh/2+(1-0.58)*6);
|
||||
//DestPoint.setX(fw - 1);
|
||||
//DestPoint.setY(fh / 2); //curAliens[AliensCnt].Position.pnt.y();
|
||||
curAliens[0].DestPnt = DestPoint;
|
||||
curAliens[curAliens.size()-1].DestPnt = DestPoint;
|
||||
// curAliens[AliensCnt].MaxFrame = 0; //srcAliens[CurWave].MaxFrame;
|
||||
// curAliens[AliensCnt].PicFrame = 0;
|
||||
for (int i = 0; i < fw; i++) {
|
||||
for (int j = 0; j < fh; j++) TmpCells[i][j] = Cells[i][j];
|
||||
}
|
||||
return CreatePath(&curAliens[0]);
|
||||
return (CreatePath(&curAliens[curAliens.size()-1]) && loadPixmaps(&curAliens[curAliens.size()-1]));
|
||||
}
|
||||
|
||||
|
||||
@@ -89,6 +118,7 @@ bool Aliens::CreatePath(Alien * al)
|
||||
{
|
||||
tmpPnt.clear();
|
||||
tp = al->path[0];
|
||||
//qDebug() << al->path.at(0);
|
||||
tmpPnt.push_back(tp);
|
||||
for (int i = 0; i < al->path.size() - 1; i++)
|
||||
{
|
||||
@@ -98,7 +128,7 @@ bool Aliens::CreatePath(Alien * al)
|
||||
}
|
||||
tp = al->path[al->path.size() - 1];
|
||||
tmpPnt.push_back(tp);
|
||||
qDebug() << tmpPnt.size();
|
||||
//qDebug() << tmpPnt.size();
|
||||
al->path = tmpPnt;
|
||||
al->Position.pnt.setX(al->path.at(0).x()*cellsize);
|
||||
al->Position.pnt.setY(al->path.at(0).y()*cellsize);
|
||||
@@ -128,17 +158,38 @@ void Aliens::updateAlienPos(Alien * al)
|
||||
}*/
|
||||
|
||||
|
||||
bool Aliens::recreatePath()
|
||||
{
|
||||
QPointF ap;
|
||||
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++) {
|
||||
ap = curAliens[i].Position.pnt;
|
||||
curAliens[i].Position.pnt.setX(0);
|
||||
curAliens[i].Position.pnt.setY(fh/2);
|
||||
curAliens[i].path.clear();
|
||||
trace = CreatePath(&curAliens[i]);
|
||||
if (!trace) return false;
|
||||
curAliens[i].Position.pnt = ap;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Aliens::WaveTrace(Alien * al) {
|
||||
bool stop = false;
|
||||
int step = 2;
|
||||
QPoint cp, tp;
|
||||
QPoint cp, tp;
|
||||
QRect fr(0, 0, fw, fh);
|
||||
QVector<QPoint> tmpp, curp;
|
||||
cp = al->Position.pnt;
|
||||
curp.push_back(cp);
|
||||
cp.setX(al->Position.pnt.x());
|
||||
cp.setY(al->Position.pnt.y());
|
||||
curp.push_back(cp);
|
||||
TmpCells[cp.x()][cp.y()] = 1;
|
||||
while (!stop) {
|
||||
qDebug() << "trace";
|
||||
//qDebug() << "trace";
|
||||
tmpp = curp;
|
||||
curp.clear();
|
||||
qDebug() << tmpp.size();
|
||||
@@ -317,6 +368,5 @@ void Aliens::InvWaveTrace(QPoint cp, int cnt, Alien * al)
|
||||
|
||||
void Aliens::clearAliens()
|
||||
{
|
||||
//AliensCnt = - 1;
|
||||
curAliens.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user