diff --git a/Makefile b/Makefile index 5ea983a..ffcffad 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: aliendefender -# Generated by qmake (2.01a) (Qt 4.5.2) on: ?? ????. 3 23:47:46 2009 +# Generated by qmake (2.01a) (Qt 4.5.2) on: ?? ????. 5 00:15:00 2009 # Project: aliendefender.pro # Template: app # Command: /usr/bin/qmake -Wall -spec ../../share/qt4/mkspecs/linux-g++ -unix CONFIG+=debug -o Makefile aliendefender.pro diff --git a/adpainter.cpp b/adpainter.cpp index f093415..c49c1ad 100644 --- a/adpainter.cpp +++ b/adpainter.cpp @@ -56,10 +56,10 @@ void adpainter::drawgrid() } -void adpainter::drawAliens(QVector path, FPVector * position) +void adpainter::drawAliens(Alien * al,AlienImages * pixmaps) { - float tmpdx,tmpdy,arctg,tmpdx1,tmpdy1; - arctg = 0; + //float tmpdx,tmpdy,arctg,tmpdx1,tmpdy1; + //arctg = 0; painter.begin(buff); pen->setColor(QColor::fromRgb(qRgb(80,200,100))); brush->setColor(QColor::fromRgb(qRgb(230,10,10))); @@ -67,21 +67,21 @@ void adpainter::drawAliens(QVector path, FPVector * position) painter.setPen(*pen); painter.setBrush(*brush); painter.drawPixmap(0,0,*background); - for (int i = 0; i < path.size(); i++){ - painter.drawEllipse(path[i].x() * cellsize +1, path[i].y() * cellsize +1, cellsize - 2, cellsize - 2); + for (int i = 0; i < al->path.size(); i++){ + painter.drawEllipse(al->path[i].x() * cellsize +1, al->path[i].y() * cellsize +1, cellsize - 2, cellsize - 2); } - tmpdx = position->pnt.x() - path.at(StepAlien).x()*cellsize; - tmpdy = position->pnt.y() - path.at(StepAlien).y()*cellsize; - if (StepAlien + 1 < path.size()) { - tmpdx1 = position->pnt.x() - path.at(StepAlien+1).x()*cellsize; - tmpdy1 = position->pnt.y() - path.at(StepAlien+1).y()*cellsize; - } - arctg = atanf(tmpdx1/tmpdy1); - position->angle = 180*(-arctg)/3.1415; - if (tmpdy1 < 0) position->angle = 180 + position->angle; - if (AlienPix.size() > 0) { + //tmpdx = position->pnt.x() - path.at(StepAlien).x()*cellsize; + //tmpdy = position->pnt.y() - path.at(StepAlien).y()*cellsize; + //if (StepAlien + 1 < path.size()) { + // tmpdx1 = position->pnt.x() - path.at(StepAlien+1).x()*cellsize; + // tmpdy1 = position->pnt.y() - path.at(StepAlien+1).y()*cellsize; + //} + //arctg = atanf(tmpdx1/tmpdy1); + //position->angle = 180*(-arctg)/3.1415; + //if (tmpdy1 < 0) position->angle = 180 + position->angle; + //if (AlienPix.size() > 0) { //qDebug() << "angle:" << position->angle; - if (qAbs(tmpdx) < 1 && qAbs(tmpdy) < 1) StepAlien++; + /* if (qAbs(tmpdx) < 1 && qAbs(tmpdy) < 1) StepAlien++; else { if (qAbs(tmpdx) <= qAbs(tmpdy)) { if (tmpdy < 0) position->pnt.ry()++; @@ -91,18 +91,19 @@ void adpainter::drawAliens(QVector path, FPVector * position) if (tmpdx < 0) position->pnt.rx()++; else position->pnt.rx()--; } - } - painter.translate(position->pnt.x()+cellsize/2, position->pnt.y()+cellsize/2); - painter.rotate(position->angle); - painter.drawPixmap(-cellsize, -cellsize, cellsize*2, cellsize*2, AlienPix.at(AnimAlien)); - AnimAlien++; - if (AnimAlien >= AlienPix.size()) AnimAlien = 0; - if (StepAlien >= path.size()) { + }*/ + painter.translate(al->Position.pnt.x()+cellsize/2, al->Position.pnt.y()+cellsize/2); + painter.rotate(al->Position.angle); + painter.drawPixmap(-cellsize, -cellsize, cellsize*2, cellsize*2, pixmaps->pix.at(al->PicIndex)); + //AnimAlien++; + //if (AnimAlien >= AlienPix.size()) AnimAlien = 0; + /*if (StepAlien >= path.size()) { StepAlien = 0; - position->pnt = path.at(0); - } + position->pnt.setX(path.at(0).x()*cellsize); + position->pnt.setY(path.at(0).y()*cellsize); + }*/ //qDebug() << StepAlien; - } + //} painter.end(); } diff --git a/adpainter.h b/adpainter.h index b9f02de..991f1f4 100644 --- a/adpainter.h +++ b/adpainter.h @@ -3,9 +3,6 @@ #include "basestruct.h" -//#include -#include - #include #include #include @@ -18,10 +15,6 @@ #include #include -//using std::deque; -//using std::vector; -using std::atan; - class adpainter { public: @@ -31,7 +24,7 @@ public: void clearcell(QPoint pnt); void clear(); QPixmap * getPixmap(); - void drawAliens(QVector path, FPVector * position);//int xa, int ya); + void drawAliens(Alien * al, AlienImages * pixmaps);//int xa, int ya); int AnimAlien, StepAlien; private: QPixmap * buff; diff --git a/adpainter.o b/adpainter.o index 7d91785..bc0958c 100644 Binary files a/adpainter.o and b/adpainter.o differ diff --git a/aliendefender b/aliendefender index a35a100..a1d51db 100755 Binary files a/aliendefender and b/aliendefender differ diff --git a/aliens.cpp b/aliens.cpp index 1a14a98..fb3044a 100644 --- a/aliens.cpp +++ b/aliens.cpp @@ -20,9 +20,9 @@ Aliens::Aliens(int TmpDestx, int TmpDesty, int afw, int afh, int alcellsize) clearCells(); Alien al; al.PicType = 0; - al.PathIndex = 0; + al.PathIndex = 1; al.PicFrame = 0; - al.Speed = 1; + al.Speed = 0.1; srcAliens.push_back(al); CurWave = 0; } @@ -89,8 +89,8 @@ bool Aliens::AddAlien() //Aliens(AliensCnt) = SrcAliens(CurWave) curAliens.push_back(srcAliens.at(CurWave)); //curAliens[AliensCnt].Level = CurWave + 1; - curAliens[curAliens.size()-1].Position.pnt.setX(0); - curAliens[curAliens.size()-1].Position.pnt.setY(fh/2); //(int)(fh/2+(1-0.58)*6); + curAliens[curAliens.size()-1].Position.pnt.setX(0*cellsize); + curAliens[curAliens.size()-1].Position.pnt.setY(fh/2*cellsize); //(int)(fh/2+(1-0.58)*6); //DestPoint.setX(fw - 1); //DestPoint.setY(fh / 2); //curAliens[AliensCnt].Position.pnt.y(); curAliens[curAliens.size()-1].DestPnt = DestPoint; @@ -107,11 +107,6 @@ bool Aliens::CreatePath(Alien * al) { QPointF tp; QVector 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; if (WaveTrace(al)) { for (int j=0; j<4; j++) @@ -137,13 +132,51 @@ bool Aliens::CreatePath(Alien * al) return true; } return false; - //return WaveTrace(al); +} + + +void Aliens::updateAliens() +{ + for (int i = 0; i < curAliens.size(); i++) updateAlienPos(&curAliens[i]); } void Aliens::updateAlienPos(Alien * al) { + float arctg = 0; + qreal dx,dy,fdx,fdy; + dx = (al->path[al->PathIndex - 1].x() - al->path.at(al->PathIndex).x()); + dy = (al->path[al->PathIndex - 1].y() - al->path.at(al->PathIndex).y()); + qDebug("========="); + qDebug() << dx << ";" << dy; + qDebug() << al->path[al->PathIndex]; + qDebug() << al->path[al->PathIndex-1]; + if (al->PathIndex + 1 < al->path.size()) { + fdx = al->Position.pnt.x() - al->path.at(al->PathIndex+1).x()*cellsize; + fdy = al->Position.pnt.y() - al->path.at(al->PathIndex+1).y()*cellsize; + if (fdy != 0) arctg = atanf(fdx/fdy); + else if (fdx < 0) arctg = -3.1415/2; + else arctg = 3.1415/2; + } + //qDebug() << fdx << ";" << fdy; + al->Position.angle = 180*(-arctg)/3.1415; + if (fdy < 0) al->Position.angle = 180 + al->Position.angle; + qDebug() << al->Position.angle; + if (qAbs(dx) < 1 && qAbs(dy) < 1) al->PathIndex++; + else { + al->Position.pnt.setX(al->Position.pnt.x()-dx*al->Speed); + al->Position.pnt.setY(al->Position.pnt.y()-dy*al->Speed); + } + qDebug() << al->Position.pnt; + al->PicIndex++; + if (al->PicIndex >= AliensPixmaps[al->PicType].pix.size()) al->PicIndex = 0; + if (al->PathIndex >= al->path.size()) { + qDebug() << "run agan"; + al->PathIndex = 1; + al->Position.pnt.setX(al->path.at(0).x()*cellsize); + al->Position.pnt.setY(al->path.at(0).y()*cellsize); + } } @@ -160,32 +193,33 @@ void Aliens::updateAlienPos(Alien * al) bool Aliens::recreatePath() { - QPointF ap; + //QPointF ap; bool trace; - for (int i = 0; i < fw; i++) { + 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); + //ap = curAliens[i].Position.pnt; + //curAliens[i].Position.pnt.setX(0); + //curAliens[i].Position.pnt.setY(fh/2); + qDebug() << "Alinen N" << i; curAliens[i].path.clear(); trace = CreatePath(&curAliens[i]); if (!trace) return false; - curAliens[i].Position.pnt = ap; + //curAliens[i].Position.pnt = ap; } return true; } -bool Aliens::WaveTrace(Alien * al) { +bool Aliens::WaveTrace(Alien * al) +{ bool stop = false; int step = 2; QPoint cp, tp; QRect fr(0, 0, fw, fh); QVector tmpp, curp; - cp.setX(al->Position.pnt.x()); - cp.setY(al->Position.pnt.y()); + cp.setX(al->Position.pnt.x()/cellsize); + cp.setY(al->Position.pnt.y()/cellsize); curp.push_back(cp); TmpCells[cp.x()][cp.y()] = 1; while (!stop) { @@ -198,7 +232,7 @@ bool Aliens::WaveTrace(Alien * al) { cp = tmpp[i]; if (cp == al->DestPnt) { TmpCells[cp.x()][cp.y()] = step; - qDebug() << "true"; + qDebug() << "Wawe trace done"; InvWaveTrace(cp, step, al); qDebug() << al->path.size(); return true; @@ -232,7 +266,7 @@ bool Aliens::WaveTrace(Alien * al) { } step++; } - qDebug() << "false"; + qDebug() << "false wawetrace"; return false; } diff --git a/aliens.h b/aliens.h index 6b8ce96..0c3cefb 100644 --- a/aliens.h +++ b/aliens.h @@ -11,7 +11,6 @@ class Aliens QVector srcAliens; QVector curAliens; - //vector< vector > TmpCells; int ** Cells; int CurWave; //bool PathIntersect(Alien* Al, Rectangle rect); @@ -20,13 +19,13 @@ class Aliens void clearAliens(); void clearCells(); bool recreatePath(); + void updateAliens(); + QVector AliensPixmaps; private: int cellsize; int ** TmpCells; int fw, fh; QPoint DestPoint; - QVector AliensPixmaps; - //AlienImages AliensPixmaps[1]; bool WaveTrace(Alien* al); bool CreatePath(Alien* al); void InvWaveTrace(QPoint cp, int cnt, Alien* al); diff --git a/aliens.o b/aliens.o index e6122c7..9af07c4 100644 Binary files a/aliens.o and b/aliens.o differ diff --git a/basestruct.h b/basestruct.h index 80bc1c6..904f1f5 100644 --- a/basestruct.h +++ b/basestruct.h @@ -2,7 +2,6 @@ #define BASESTRUCT_H #include -//#include #include #include #include @@ -10,9 +9,11 @@ #include #include -//using std::vector; -//using std::deque; +#include +#include +using std::atan; +using std::deque; struct FPVector { @@ -58,7 +59,7 @@ struct Alien float PicFrame; //float PicI; //float Regeneration; - QVector path;//path() As Point + deque path;//path() As Point QPoint DestPnt; // Effect Effects; }; diff --git a/mainwindow.cpp b/mainwindow.cpp index c8520e5..906e501 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -30,7 +30,8 @@ MainWindow::MainWindow(QWidget *parent) void MainWindow::ADrender() { //aliens->AddAlien(); - adp->drawAliens(aliens->curAliens[0].path, &aliens->curAliens[0].Position); + aliens->updateAliens(); + adp->drawAliens(&aliens->curAliens[0], &aliens->AliensPixmaps[aliens->curAliens[0].PicType]); this->repaint(); } @@ -74,8 +75,9 @@ void MainWindow::SetCell(int x, int y) aliens->Cells[cp.x()][cp.y()] = - 1; adp->drawcell(cp); //aliens->recreatePath(); - //adp->StepAlien=0; + adp->StepAlien=0; //adp->AnimAlien=0; + //aliens->curAliens[aliens->CurWave].Position.pnt = aliens->curAliens[aliens->CurWave-1].path[adp->StepAlien]; if (!aliens->recreatePath()) ClearCell(x,y); } } @@ -91,6 +93,7 @@ void MainWindow::ClearCell(int x, int y) //qDebug() << "click: " << cp.x() << ";" << cp.y(); aliens->Cells[cp.x()][cp.y()] = 0; adp->clearcell(cp); + adp->StepAlien=0; qDebug() << aliens->recreatePath(); //aliens->clearAliens(); //aliens->AddAlien(); diff --git a/mainwindow.o b/mainwindow.o index 8eeaac5..3e2b4fa 100644 Binary files a/mainwindow.o and b/mainwindow.o differ diff --git a/moc_mainwindow.cpp b/moc_mainwindow.cpp index 9e955b9..419c51c 100644 --- a/moc_mainwindow.cpp +++ b/moc_mainwindow.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** Meta object code from reading C++ file 'mainwindow.h' ** -** Created: Fri Sep 4 20:48:45 2009 +** Created: Sat Sep 5 17:46:21 2009 ** by: The Qt Meta Object Compiler version 61 (Qt 4.5.2) ** ** WARNING! All changes made in this file will be lost! diff --git a/moc_mainwindow.o b/moc_mainwindow.o index ba641e7..c356eca 100644 Binary files a/moc_mainwindow.o and b/moc_mainwindow.o differ diff --git a/towers.o b/towers.o index 317f352..e323c0d 100644 Binary files a/towers.o and b/towers.o differ