From 3316f3f48ff12617b9f4a738bcc9c865d89e649c Mon Sep 17 00:00:00 2001 From: buull Date: Tue, 31 Aug 2010 23:37:02 +0400 Subject: [PATCH] now is enable build and delete towers in game and improve graphic perfomance find and correct many-many bugs --- ad_graphics.cpp | 67 ++++----- ad_graphics.h | 1 + adcore.cpp | 2 +- aliendefender.pro.user | 316 +++++++++++++++++++++++++++++------------ aliens.cpp | 8 +- data2.xml | 2 +- map.cpp | 92 ++++-------- map.h | 3 +- towers.cpp | 4 +- 9 files changed, 299 insertions(+), 196 deletions(-) diff --git a/ad_graphics.cpp b/ad_graphics.cpp index 834d502..5dc5f9e 100644 --- a/ad_graphics.cpp +++ b/ad_graphics.cpp @@ -11,11 +11,44 @@ AD_Graphics::AD_Graphics(AD_Core *adcore, QWidget *parent) : QGraphicsView(paren setAlignment(Qt::AlignLeft | Qt::AlignTop); scene = new QGraphicsScene(); setScene(scene); - setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); + //setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); setViewportUpdateMode(QGraphicsView::FullViewportUpdate); + mapimg = new QImage(data->map->rect().size()*cellSize,QImage::Format_ARGB32); //setDragMode(RubberBandDrag); //gsw = new QGraphicsWidget(); //scene->addWidget(new QPushButton()); + QPainter p(mapimg); + for (int i=0; imap->cells().size(); i++) { + for (int j=0; jmap->cells().at(i).size(); j++) { + QPen pen; + QBrush brush; + pen.setColor(Qt::white); + brush.setColor(Qt::white); + brush.setStyle(Qt::SolidPattern); + int cel = data->map->cells().at(i).at(j); + if (cel == Map::Wall) + { + pen.setColor(Qt::black); + brush.setColor(Qt::black); + } + // if (cel <= Map::PlayerTower && cel !=Map::Wall) { + // pen.setColor(QColor(cel%255,(cel*100)%255,(cel+100)%255)); + // brush.setColor(QColor(cel%255,(cel*100)%255,(cel+100)%255)); + // } + // if (cel >= Map::PlayerAlien) { + // pen.setColor(Qt::yellow); + // brush.setColor(Qt::yellow); + // } + if (cel >= Map::Player || (cel <= Map::PlayerTower && cel !=Map::Wall)) + { + pen.setColor(QColor(qAbs(cel)*345%255,(qAbs(cel)*721)%255,(qAbs(cel)*75)%255,50)); + brush.setColor(QColor(qAbs(cel)*345%255,(qAbs(cel)*721)%255,(qAbs(cel)*75)%255,50)); + } + p.setPen(pen); + p.setBrush(brush); + p.drawRect(i*cellSize,j*cellSize,cellSize,cellSize); + } + } startTimer(25); show(); @@ -55,37 +88,7 @@ void AD_Graphics::timerEvent(QTimerEvent * ) void AD_Graphics::drawBackground(QPainter * p, const QRectF & ) { - for (int i=0; imap->cells().size(); i++) { - for (int j=0; jmap->cells().at(i).size(); j++) { - QPen pen; - QBrush brush; - pen.setColor(Qt::white); - brush.setColor(Qt::white); - brush.setStyle(Qt::SolidPattern); - int cel = data->map->cells().at(i).at(j); - if (cel == Map::Wall) - { - pen.setColor(Qt::black); - brush.setColor(Qt::black); - } - // if (cel <= Map::PlayerTower && cel !=Map::Wall) { - // pen.setColor(QColor(cel%255,(cel*100)%255,(cel+100)%255)); - // brush.setColor(QColor(cel%255,(cel*100)%255,(cel+100)%255)); - // } - // if (cel >= Map::PlayerAlien) { - // pen.setColor(Qt::yellow); - // brush.setColor(Qt::yellow); - // } - if (cel >= Map::Player || (cel <= Map::PlayerTower && cel !=Map::Wall)) - { - pen.setColor(QColor(qAbs(cel)%255,(qAbs(cel)*100)%255,(qAbs(cel)+100)%255,50)); - brush.setColor(QColor(qAbs(cel)%255,(qAbs(cel)*100)%255,(qAbs(cel)+100)%255,50)); - } - p->setPen(pen); - p->setBrush(brush); - p->drawRect(i*cellSize,j*cellSize,cellSize,cellSize); - } - } + p->drawImage(0,0,*mapimg); //qDebug() << "t:" << data->curTowers.size(); for (QHash::iterator i = data->curTowers.begin(); i != data->curTowers.end(); ++i) { diff --git a/ad_graphics.h b/ad_graphics.h index 4d5b347..3a84331 100644 --- a/ad_graphics.h +++ b/ad_graphics.h @@ -29,6 +29,7 @@ private: QGraphicsScene * scene; Game_Data * data; AD_Core * core; + QImage * mapimg; QVector > images; //QGraphicsWidget * gsw; diff --git a/adcore.cpp b/adcore.cpp index bac16ad..0c970fe 100644 --- a/adcore.cpp +++ b/adcore.cpp @@ -24,7 +24,7 @@ AD_Core::AD_Core(QObject *parent) : // adaliens->addAlien(0); // adaliens->AddAlien(0); // adaliens->AddAlien(0); - adtowers->addTower(0,2,QPoint(22,7)); + adtowers->addTower(0,2,QPoint(15,1)); for (int i=0; i<20;i++) // adtowers->addTower(0,1,QPoint(8,20-i)); // for (int i=0; i<20; i++) diff --git a/aliendefender.pro.user b/aliendefender.pro.user index 4fd4af5..be6236a 100644 --- a/aliendefender.pro.user +++ b/aliendefender.pro.user @@ -1,111 +1,241 @@ - ProjectExplorer.Project.ActiveTarget + RunConfiguration0-BaseEnvironmentBase + 2 + + + RunConfiguration0-CommandLineArguments + + + + RunConfiguration0-ProFile + aliendefender.pro + + + RunConfiguration0-RunConfiguration.name + aliendefender + + + RunConfiguration0-UseDyldImageSuffix + false + + + RunConfiguration0-UseTerminal + false + + + RunConfiguration0-UserEnvironmentChanges + + + + RunConfiguration0-UserSetName + false + + + RunConfiguration0-UserSetWorkingDirectory + false + + + RunConfiguration0-UserWorkingDirectory + + + + RunConfiguration0-type + Qt4ProjectManager.Qt4RunConfiguration + + + activeRunConfiguration 0 - ProjectExplorer.Project.EditorSettings + activebuildconfiguration + Debug + + + buildConfiguration-Debug - System + Debug + 0 + 0 + 2 - ProjectExplorer.Project.Target.0 + buildConfiguration-Release - Настольный компьютер - Qt4ProjectManager.Target.DesktopTarget - 0 - 0 - - - - QtProjectManager.QMakeBuildStep - - - - - Qt4ProjectManager.MakeStep - false - - - - 2 - - - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 - false - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - C:/Users/Andrey/Desktop/build-AD - 9 - 2 - true - - - - - QtProjectManager.QMakeBuildStep - - - - - Qt4ProjectManager.MakeStep - false - - - - 2 - - - Qt4ProjectManager.MakeStep - true - - - - 1 - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - C:/Users/Andrey/Desktop/aliendefender-build-desktop - 9 - 2 - true - - 2 - - aliendefender - Qt4ProjectManager.Qt4RunConfiguration - 2 - - aliendefender.pro - false - false - - false - true - C:\Users\Andrey\Desktop\aliendefender - - 1 + Release + 0 + 0 - ProjectExplorer.Project.TargetCount - 1 + buildconfiguration-Debug-buildstep0 + + Debug + + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-wExeabp7q4,guid=18815993df3603fdc64a3f6d4c7b5822 + DEFAULTS_PATH=/usr/share/gconf/gnome.default.path + DESKTOP_SESSION=gnome + DISPLAY=:0.0 + GDMSESSION=gnome + GDM_KEYBOARD_LAYOUT=us + GDM_LANG=ru_RU.UTF-8 + GNOME_DESKTOP_SESSION_ID=this-is-deprecated + GNOME_KEYRING_CONTROL=/tmp/keyring-4vN5uf + GTK_MODULES=canberra-gtk-module + HOME=/home/andrey + LANG=ru_RU.UTF-8 + LD_LIBRARY_PATH=/usr/lib/qtcreator: + LOGNAME=andrey + MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path + ORBIT_SOCKETDIR=/tmp/orbit-andrey + PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games + PWD=/home/andrey + QTDIR=/usr/share/qt4 + SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/1205,unix/buull-eeePC:/tmp/.ICE-unix/1205 + SHELL=/bin/bash + SPEECHD_PORT=6561 + SSH_AGENT_PID=1239 + SSH_AUTH_SOCK=/tmp/keyring-4vN5uf/ssh + USER=andrey + USERNAME=andrey + XAUTHORITY=/var/run/gdm/auth-for-andrey-x9URui/database + XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg + XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ + XDG_SESSION_COOKIE=f0649decca52f2beb55c9ea74ad1d028-1283151906.338331-318132279 + + + /home/andrey/AD/aliendefender/aliendefender.pro + -spec + linux-g++ + -r + CONFIG+=debug + + /usr/bin/qmake-qt4 + false + /home/andrey/AD/aliendefender + - ProjectExplorer.Project.Updater.FileVersion - 4 + buildconfiguration-Debug-buildstep1 + + Debug + + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-wExeabp7q4,guid=18815993df3603fdc64a3f6d4c7b5822 + DEFAULTS_PATH=/usr/share/gconf/gnome.default.path + DESKTOP_SESSION=gnome + DISPLAY=:0.0 + GDMSESSION=gnome + GDM_KEYBOARD_LAYOUT=us + GDM_LANG=ru_RU.UTF-8 + GNOME_DESKTOP_SESSION_ID=this-is-deprecated + GNOME_KEYRING_CONTROL=/tmp/keyring-4vN5uf + GTK_MODULES=canberra-gtk-module + HOME=/home/andrey + LANG=ru_RU.UTF-8 + LD_LIBRARY_PATH=/usr/lib/qtcreator: + LOGNAME=andrey + MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path + ORBIT_SOCKETDIR=/tmp/orbit-andrey + PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games + PWD=/home/andrey + QTDIR=/usr/share/qt4 + SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/1205,unix/buull-eeePC:/tmp/.ICE-unix/1205 + SHELL=/bin/bash + SPEECHD_PORT=6561 + SSH_AGENT_PID=1239 + SSH_AUTH_SOCK=/tmp/keyring-4vN5uf/ssh + USER=andrey + USERNAME=andrey + XAUTHORITY=/var/run/gdm/auth-for-andrey-x9URui/database + XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg + XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ + XDG_SESSION_COOKIE=f0649decca52f2beb55c9ea74ad1d028-1283151906.338331-318132279 + + false + + -w + + /usr/bin/make + true + /home/andrey/AD/aliendefender + + + + buildconfiguration-Debug-cleanstep0 + + Debug + true + + clean + + + + + buildconfiguration-Release-buildstep0 + + Release + + + + buildconfiguration-Release-buildstep1 + + Release + + + + buildconfiguration-Release-cleanstep0 + + Release + + + + buildconfigurations + + Debug + Release + + + + buildstep0 + + + + + + + buildstep1 + + + + + + buildsteps + + trolltech.qt4projectmanager.qmake + trolltech.qt4projectmanager.make + + + + cleanstep0 + + + true + + + + cleansteps + + trolltech.qt4projectmanager.make + + + + defaultFileEncoding + System + + + project + diff --git a/aliens.cpp b/aliens.cpp index 1cd5075..29a4b0b 100644 --- a/aliens.cpp +++ b/aliens.cpp @@ -42,13 +42,17 @@ void Aliens::addAlien(int srcId) void Aliens::retrace(bool * OK) { - qDebug("re-trace!"); + //qDebug("re-trace!"); gameData->map->removeAliensPath(); for (QHash::iterator i = gameData->curAliens.begin(); i != gameData->curAliens.end(); ++i) { (*i).path = gameData->map->createPath((*i).pos.toPoint(),(*i).finish); (*i).pathIndex = 1; - if ((*i).path.isEmpty()) *OK = false; + if ((*i).path.isEmpty()) + { + *OK = false; + qDebug("Aliens retrace = false"); + } } } diff --git a/data2.xml b/data2.xml index 67a2b88..07075f0 100644 --- a/data2.xml +++ b/data2.xml @@ -71,7 +71,7 @@ - + diff --git a/map.cpp b/map.cpp index 6c61bee..95729c1 100644 --- a/map.cpp +++ b/map.cpp @@ -81,13 +81,32 @@ 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; + emit recreateAlienPath(new bool()); +} + + +bool Map::isReachable(int playerId, QPoint pos) +{ + 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 createPath(QPoint start, QPoint finish); @@ -62,6 +62,7 @@ private: QVector invWaveTrace(QPoint finish, int cnt); int waveTrace(QPoint start, QPoint finish); + bool isReachable(int playerId, QPoint pos); //void CreateMapExample(); //void ReadSettings(); }; diff --git a/towers.cpp b/towers.cpp index c4acecd..328a20e 100644 --- a/towers.cpp +++ b/towers.cpp @@ -22,11 +22,9 @@ bool Towers::addTower(int playerId, int srcId, QPoint pos) qCritical("ERROR out of towers range"); return false; } - QRect alrec(pos,QSize(1,1)); + QRect alrec(pos,QSize(2,2)); 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;