diff --git a/ADeditor/ADeditor.pro.user b/ADeditor/ADeditor.pro.user index 9d8fe6c..a9301bc 100644 --- a/ADeditor/ADeditor.pro.user +++ b/ADeditor/ADeditor.pro.user @@ -15,7 +15,7 @@ Настольный компьютер Qt4ProjectManager.Target.DesktopTarget - 0 + 1 0 @@ -78,7 +78,7 @@ Release Qt4ProjectManager.Qt4BuildConfiguration 0 - C:/Users/Andrey/Desktop/aliendefender/ADeditor-build-desktop + C:/Users/Andrey/Desktop/build-AD 9 2 true diff --git a/ad_graphics.cpp b/ad_graphics.cpp index a3f91f0..834d502 100644 --- a/ad_graphics.cpp +++ b/ad_graphics.cpp @@ -28,12 +28,24 @@ AD_Graphics::~AD_Graphics() delete scene; } + void AD_Graphics::mouseDoubleClickEvent(QMouseEvent *) { core->nextWave(); } +void AD_Graphics::mousePressEvent(QMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + core->adtowers->addTower(0,1,(QPointF(event->pos())/cellSize-QPointF(0.5,0.5)).toPoint()); + if (event->button() == Qt::RightButton) + core->adtowers->addTower(0,0,(QPointF(event->pos())/cellSize-QPointF(0.5,0.5)).toPoint()); + if (event->button() == Qt::MidButton) + core->adtowers->delTower((QPointF(event->pos())/cellSize-QPointF(0.5,0.5)).toPoint()); +} + + void AD_Graphics::timerEvent(QTimerEvent * ) { //qDebug() << data->curAliens.size(); diff --git a/ad_graphics.h b/ad_graphics.h index 4a6598d..4d5b347 100644 --- a/ad_graphics.h +++ b/ad_graphics.h @@ -24,6 +24,7 @@ private: void drawBackground(QPainter * p, const QRectF &); void loadImages(); void mouseDoubleClickEvent(QMouseEvent *); + void mousePressEvent(QMouseEvent *event); QGraphicsScene * scene; Game_Data * data; @@ -32,7 +33,7 @@ private: //QGraphicsWidget * gsw; protected: - void timerEvent(QTimerEvent * ); + void timerEvent(QTimerEvent * ); }; #endif // AD_GRAPHICS_H diff --git a/adcore.cpp b/adcore.cpp index 554ccf7..bac16ad 100644 --- a/adcore.cpp +++ b/adcore.cpp @@ -26,11 +26,11 @@ AD_Core::AD_Core(QObject *parent) : // adaliens->AddAlien(0); adtowers->addTower(0,2,QPoint(22,7)); for (int i=0; i<20;i++) - adtowers->addTower(0,1,QPoint(8,20-i)); - for (int i=0; i<20; i++) - adtowers->addTower(0,0,QPoint(12,i)); - for (int i=0; i<20;i++) - adtowers->addTower(0,1,QPoint(16,20-i)); +// adtowers->addTower(0,1,QPoint(8,20-i)); +// for (int i=0; i<20; i++) +// adtowers->addTower(0,0,QPoint(12,i)); +// for (int i=0; i<20;i++) +// adtowers->addTower(0,1,QPoint(16,20-i)); waveInProgress = false; startTimer(20); } diff --git a/aliens.cpp b/aliens.cpp index f5e4e7c..1cd5075 100644 --- a/aliens.cpp +++ b/aliens.cpp @@ -25,7 +25,11 @@ void Aliens::addAlien(int srcId) al.pathIndex = 1; al.angle = 180.0f*(- std::atan2( al.pos.x() - al.path.at(al.pathIndex).x(),al.pos.y() - al.path.at(al.pathIndex).y()))/M_PI; al.animIndex = 0.f; - if (al.path.isEmpty()) qFatal("ERROR create path"); + if (al.path.isEmpty()) + { + qCritical("ERROR create path"); + return; // FIXME: this + } //qDebug() << al.path; al.health = gameData->srcAliens.at(srcId).health; al.speed = gameData->srcAliens.at(srcId).speed; diff --git a/map.cpp b/map.cpp index d3b354a..6c61bee 100644 --- a/map.cpp +++ b/map.cpp @@ -78,6 +78,19 @@ void Map::removeAliensPath() } } + +void Map::delTowerOnMap(int playerId, QPoint pos) +{ + bool * pathOK; + pathOK = new bool(); + emit recreateAlienPath(pathOK); + Cells[pos.x()][pos.y()]=Player+playerId; + Cells[pos.x()+1][pos.y()]=Player+playerId; + Cells[pos.x()][pos.y()+1]=Player+playerId; + Cells[pos.x()+1][pos.y()+1]=Player+playerId; +} + + bool Map::addTowerOnMap(int playerId, QPoint pos) { //qDebug() << pos; @@ -109,15 +122,26 @@ bool Map::addTowerOnMap(int playerId, QPoint pos) } return true; } - if (Cells[pos.x()][pos.y()]==AlienPath+playerId && - Cells[pos.x()+1][pos.y()]==AlienPath+playerId && - Cells[pos.x()][pos.y()+1]==AlienPath+playerId && - Cells[pos.x()+1][pos.y()+1]==AlienPath+playerId) + if ((Cells[pos.x()][pos.y()]==AlienPath+Player+playerId || Cells[pos.x()][pos.y()]==Player+playerId) && + (Cells[pos.x()+1][pos.y()]==AlienPath+Player+playerId || Cells[pos.x()+1][pos.y()]==Player+playerId) && + (Cells[pos.x()][pos.y()+1]==AlienPath+Player+playerId || Cells[pos.x()][pos.y()+1]==Player+playerId) && + (Cells[pos.x()+1][pos.y()+1]==AlienPath+Player+playerId || Cells[pos.x()+1][pos.y()+1]==Player+playerId)) { Cells[pos.x()][pos.y()]=PlayerTower-playerId; Cells[pos.x()+1][pos.y()]=PlayerTower-playerId; Cells[pos.x()][pos.y()+1]=PlayerTower-playerId; Cells[pos.x()+1][pos.y()+1]=PlayerTower-playerId; + for (int i=0; i Map::createPath(QPoint start, QPoint finish) QVector tmpPath; QVector path; //PathIndex = 1; - if (Cells[start.x()][start.y()] < 0) qDebug("ERROR invalid start"),exit(-1); - if (Cells[finish.x()][finish.y()] < 0) qDebug("ERROR invalid finish"),exit(-1); + if (Cells[start.x()][start.y()] < 0) + { + qDebug("ERROR invalid start"); + return path; + } + if (Cells[finish.x()][finish.y()] < 0) + { + qDebug("ERROR invalid finish"); + return path; + } srcPath = invWaveTrace(finish,waveTrace(start,finish)); for (int i=0; i createPath(QPoint start, QPoint finish); QRect rect() const {return QRect(QPoint(),mapSize);} diff --git a/towers.cpp b/towers.cpp index c20feab..c4acecd 100644 --- a/towers.cpp +++ b/towers.cpp @@ -22,6 +22,11 @@ bool Towers::addTower(int playerId, int srcId, QPoint pos) qCritical("ERROR out of towers range"); return false; } + QRect alrec(pos,QSize(1,1)); + for (QHash::iterator i = gameData->curAliens.begin(); i != gameData->curAliens.end(); ++i) + { + if (alrec.contains((*i).pos.toPoint())) return false; + } TowerType tw; tw.src = srcId; tw.imgType = gameData->players.at(playerId)->srcTowers.at(srcId).imgType; @@ -46,7 +51,11 @@ bool Towers::addTower(int playerId, int srcId, QPoint pos) void Towers::delTower(QPoint pos) { - gameData->curTowers.remove(pos); + if (gameData->curTowers.contains(pos)) + { + gameData->map->delTowerOnMap(gameData->curTowers.value(pos).PlayerId,pos); + gameData->curTowers.remove(pos); + } }