the Alien going right!
This commit is contained in:
83
aliens.cpp
83
aliens.cpp
@@ -1,16 +1,16 @@
|
||||
#include "aliens.h"
|
||||
|
||||
using std::vector;
|
||||
//using std::vector;
|
||||
|
||||
Aliens::Aliens(int TmpDestx, int TmpDesty, int afw, int afh, int alcellsize)
|
||||
{
|
||||
cellsize = alcellsize;
|
||||
DestPoint.setX(TmpDestx);
|
||||
DestPoint.setX(TmpDestx - 1);
|
||||
DestPoint.setY(TmpDesty);
|
||||
fw = afw;
|
||||
fh = afh;
|
||||
AliensCnt = -1;
|
||||
CurWave = 0;
|
||||
//AliensCnt = -1;
|
||||
//CurWave = 0;
|
||||
Cells = new int*[fw];
|
||||
TmpCells = new int*[fw];
|
||||
for (int i = 0; i < fw; i++) {
|
||||
@@ -21,6 +21,29 @@ Aliens::Aliens(int TmpDestx, int TmpDesty, int afw, int afh, int alcellsize)
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
void Aliens::clearCells()
|
||||
{
|
||||
for (int i = 0; i < fw; i++) for (int j = 0; j < fh; j++) Cells[i][j] = 0;
|
||||
@@ -29,33 +52,32 @@ void Aliens::clearCells()
|
||||
|
||||
bool Aliens::AddAlien()
|
||||
{
|
||||
bool ok;
|
||||
//bool ok;
|
||||
Alien al;
|
||||
AliensCnt++;
|
||||
//AliensCnt++;
|
||||
//if (CurWave < 0) CurWave = 0;
|
||||
//if (AliensCnt > curAliens.size()) ReDim Preserve Aliens(AliensCnt) As Alien
|
||||
//Aliens(AliensCnt) = SrcAliens(CurWave)
|
||||
//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[AliensCnt].Position.pnt.setX(0);
|
||||
curAliens[AliensCnt].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[AliensCnt].DestPnt = DestPoint;
|
||||
//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);
|
||||
//DestPoint.setX(fw - 1);
|
||||
//DestPoint.setY(fh / 2); //curAliens[AliensCnt].Position.pnt.y();
|
||||
curAliens[0].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];
|
||||
}
|
||||
ok = CreatePath(&curAliens[AliensCnt]);
|
||||
return ok;
|
||||
return CreatePath(&curAliens[0]);
|
||||
}
|
||||
|
||||
|
||||
bool Aliens::CreatePath(Alien * al)
|
||||
{
|
||||
QPointF tp;
|
||||
deque<QPointF> tmpPnt;
|
||||
QVector<QPointF> tmpPnt;
|
||||
//tmpPnt.clear();
|
||||
// AliensTmpDestX = fw - 1;//al->Destpnt.x();
|
||||
// AliensTmpDestY = fh / 2;//al->Destpnt.y();
|
||||
@@ -68,7 +90,7 @@ bool Aliens::CreatePath(Alien * al)
|
||||
tmpPnt.clear();
|
||||
tp = al->path[0];
|
||||
tmpPnt.push_back(tp);
|
||||
for (unsigned int i = 0; i < al->path.size() - 1; i++)
|
||||
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);
|
||||
@@ -76,17 +98,12 @@ bool Aliens::CreatePath(Alien * al)
|
||||
}
|
||||
tp = al->path[al->path.size() - 1];
|
||||
tmpPnt.push_back(tp);
|
||||
al->path.swap(tmpPnt);
|
||||
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);
|
||||
}
|
||||
int i = 0;
|
||||
tmpPnt.clear();
|
||||
while(1)
|
||||
{
|
||||
tp = al->path[0];
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -94,6 +111,12 @@ bool Aliens::CreatePath(Alien * al)
|
||||
}
|
||||
|
||||
|
||||
void Aliens::updateAlienPos(Alien * al)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*bool Aliens::PathIntersect(Alien* Al, Rectangle rect)
|
||||
{
|
||||
//PathIntersect = False
|
||||
@@ -110,15 +133,17 @@ bool Aliens::WaveTrace(Alien * al) {
|
||||
int step = 2;
|
||||
QPoint cp, tp;
|
||||
QRect fr(0, 0, fw, fh);
|
||||
vector<QPoint> tmpp, curp;
|
||||
QVector<QPoint> tmpp, curp;
|
||||
cp = al->Position.pnt;
|
||||
curp.push_back(cp);
|
||||
TmpCells[cp.x()][cp.y()] = 1;
|
||||
while (!stop) {
|
||||
tmpp = curp;
|
||||
qDebug() << "trace";
|
||||
tmpp = curp;
|
||||
curp.clear();
|
||||
qDebug() << tmpp.size();
|
||||
stop = true;
|
||||
for (unsigned int i = 0; i < tmpp.size(); i++) {
|
||||
for (int i = 0; i < tmpp.size(); i++) {
|
||||
cp = tmpp[i];
|
||||
if (cp == al->DestPnt) {
|
||||
TmpCells[cp.x()][cp.y()] = step;
|
||||
@@ -292,6 +317,6 @@ void Aliens::InvWaveTrace(QPoint cp, int cnt, Alien * al)
|
||||
|
||||
void Aliens::clearAliens()
|
||||
{
|
||||
AliensCnt = - 1;
|
||||
//AliensCnt = - 1;
|
||||
curAliens.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user