diff --git a/ad_graphics.cpp b/ad_graphics.cpp index 36eecc9..e1e35e3 100644 --- a/ad_graphics.cpp +++ b/ad_graphics.cpp @@ -1,4 +1,5 @@ #include "ad_graphics.h" +#include AD_Graphics::AD_Graphics(AD_Core *adcore, QWidget *parent) : QGraphicsView(parent) @@ -10,7 +11,9 @@ AD_Graphics::AD_Graphics(AD_Core *adcore, QWidget *parent) : QGraphicsView(paren setAlignment(Qt::AlignLeft | Qt::AlignTop); scene = new QGraphicsScene(); setScene(scene); - setViewportUpdateMode(QGraphicsView::FullViewportUpdate); + //setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); + //setViewportUpdateMode(QGraphicsView::FullViewportUpdate); + //setDragMode(RubberBandDrag); //gsw = new QGraphicsWidget(); //scene->addWidget(new QPushButton()); diff --git a/aliendefender.pro b/aliendefender.pro index 0037ccf..9779b30 100644 --- a/aliendefender.pro +++ b/aliendefender.pro @@ -8,7 +8,8 @@ HEADERS += base_types.h \ player.h \ loader.h \ animation.h \ - ad_graphics.h + ad_graphics.h \ + graphicsalien.h SOURCES += map.cpp \ game_data.cpp \ aliens.cpp \ @@ -19,10 +20,10 @@ SOURCES += map.cpp \ player.cpp \ loader.cpp \ animation.cpp \ - ad_graphics.cpp + ad_graphics.cpp \ + graphicsalien.cpp RESOURCES += images.qrc -OTHER_FILES += \ - data.xml \ +OTHER_FILES += data.xml \ schema.xml \ data2.xml QT += core \ diff --git a/aliendefender.pro.user b/aliendefender.pro.user index 7122a0f..71a2fb1 100644 --- a/aliendefender.pro.user +++ b/aliendefender.pro.user @@ -1,113 +1,214 @@ - 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 + 2 + 0 + 2 - ProjectExplorer.Project.Target.0 + buildconfiguration-Debug-buildstep0 - Настольный компьютер - Qt4ProjectManager.Target.DesktopTarget - 0 - 0 - - - qmake - QtProjectManager.QMakeBuildStep - - - - Сборка - Qt4ProjectManager.MakeStep - false - - - - 2 - - Сборка - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 - false - - Отладка - Qt4ProjectManager.Qt4BuildConfiguration - 2 - C:/Users/Andrey/Desktop/build-AD - 9 - 2 - true - - - - qmake - QtProjectManager.QMakeBuildStep - - - - Сборка - Qt4ProjectManager.MakeStep - false - - - - 2 - - Сборка - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 - false - - Релиз - 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 + Debug + + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-7vJZaf9AwI,guid=f26a2301f932cefdec6dd3bc4c79669f + 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-U899U4 + 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/1236,unix/buull-eeePC:/tmp/.ICE-unix/1236 + SHELL=/bin/bash + SPEECHD_PORT=6561 + SSH_AGENT_PID=1270 + SSH_AUTH_SOCK=/tmp/keyring-U899U4/ssh + USER=andrey + USERNAME=andrey + XAUTHORITY=/var/run/gdm/auth-for-andrey-6T6AjI/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-1283024543.354844-1194058895 + + + /home/andrey/AD/aliendefender/aliendefender.pro + -spec + linux-g++ + -r + CONFIG+=debug + + /usr/bin/qmake-qt4 + false + /home/andrey/AD/aliendefender - ProjectExplorer.Project.TargetCount - 1 + buildconfiguration-Debug-buildstep1 + + Debug + + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-7vJZaf9AwI,guid=f26a2301f932cefdec6dd3bc4c79669f + 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-U899U4 + 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/1236,unix/buull-eeePC:/tmp/.ICE-unix/1236 + SHELL=/bin/bash + SPEECHD_PORT=6561 + SSH_AGENT_PID=1270 + SSH_AUTH_SOCK=/tmp/keyring-U899U4/ssh + USER=andrey + USERNAME=andrey + XAUTHORITY=/var/run/gdm/auth-for-andrey-6T6AjI/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-1283024543.354844-1194058895 + + false + + -w + + /usr/bin/make + true + /home/andrey/AD/aliendefender + - ProjectExplorer.Project.Updater.FileVersion - 4 + buildconfiguration-Debug-cleanstep0 + + Debug + true + + clean + + + + + buildconfigurations + + Debug + + + + 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 9aae780..63e1ed1 100644 --- a/aliens.cpp +++ b/aliens.cpp @@ -17,7 +17,7 @@ void Aliens::addAlien(int srcId) return; } AlienType al;// = gameData->srcAliens.at(srcId); - al.Id = nextId; + al.id = nextId; al.src = srcId; al.finish = gameData->map->finishs().at(qrand()%gameData->map->finishs().size()); al.pos = QPointF(gameData->map->starts().at(qrand()%gameData->map->starts().size())); @@ -30,7 +30,7 @@ void Aliens::addAlien(int srcId) al.speed = gameData->srcAliens.at(srcId).speed; al.imgType = gameData->srcAliens.at(srcId).imgType; //gameData->map->printMap(); - gameData->curAliens.insert(al.Id,al); + gameData->curAliens.insert(al.id,al); nextId++; } @@ -39,11 +39,11 @@ void Aliens::retrace(bool * OK) { qDebug("re-trace!"); gameData->map->removeAliensPath(); - for (int i=0; icurAliens.size(); i++) + for (QHash::iterator i = gameData->curAliens.begin(); i != gameData->curAliens.end(); ++i) { - gameData->curAliens.values()[i].path = gameData->map->createPath(gameData->curAliens.values()[i].pos.toPoint(),gameData->curAliens.values()[i].finish); - gameData->curAliens.values()[i].pathIndex = 1; - if (gameData->curAliens.values()[i].path.isEmpty()) *OK = false; + (*i).path = gameData->map->createPath((*i).pos.toPoint(),(*i).finish); + (*i).pathIndex = 1; + if ((*i).path.isEmpty()) *OK = false; } } @@ -57,33 +57,33 @@ void Aliens::delAlien(int Id) void Aliens::update() { QList missIndex; - for (int i=0; icurAliens.size(); i++) + for (QHash::iterator i = gameData->curAliens.begin(); i != gameData->curAliens.end(); ++i) { - AlienType al = gameData->curAliens.values().at(i); + AlienType al = (*i); //qDebug() << i; //if (al.health < 0) emit AlienKill(); float tmpdx,tmpdy,angl,arctg = 0; - tmpdx = al.pos.x() - al.path.at(al.pathIndex).x(); - tmpdy = al.pos.y() - al.path.at(al.pathIndex).y(); - while (std::sqrt(tmpdx*tmpdx +tmpdy*tmpdy) < 2*al.speed) + tmpdx = (*i).pos.x() - (*i).path.at((*i).pathIndex).x(); + tmpdy = (*i).pos.y() - (*i).path.at((*i).pathIndex).y(); + while (std::sqrt(tmpdx*tmpdx +tmpdy*tmpdy) < 2*(*i).speed) { - al.pathIndex++; - if (al.pathIndex >= al.path.size()) + (*i).pathIndex++; + if ((*i).pathIndex >= (*i).path.size()) { qDebug() << tr("Missing aliens = %1!").arg(gameData->missingAliens); - missIndex.push_back(al.Id); + missIndex.push_back((*i).id); break; } /*{ PathIndex = 0; position = game->start*game->cellsize; }*/ - tmpdx = al.pos.x() - al.path.at(al.pathIndex).x(); - tmpdy = al.pos.y() - al.path.at(al.pathIndex).y(); + tmpdx = (*i).pos.x() - (*i).path.at((*i).pathIndex).x(); + tmpdy = (*i).pos.y() - (*i).path.at((*i).pathIndex).y(); //qDebug() << "next"; } - arctg = std::atan(tmpdx/tmpdy); - if (tmpdy < 0) arctg=arctg+M_PI; + arctg = std::atan2(tmpdx,tmpdy); + //if (tmpdy < 0) arctg=arctg+M_PI; angl = 180.0f*(-arctg)/M_PI; /*if (PathIndex > 1) { @@ -95,14 +95,14 @@ void Aliens::update() else Position.angle = angl; } else*/ - al.angle = angl; + (*i).angle = angl; //qDebug() << "[" << PathIndex << ";" << PicIndex << "]" << "angle:" << Position.angle << "arctg:" << arctg << "Pos:" << Position.pnt; - al.pos.setX(al.pos.x() - -al.speed*std::sin(arctg)); - al.pos.setY(al.pos.y() - -al.speed*std::cos(arctg)); + (*i).pos.setX((*i).pos.x() + -(*i).speed*std::sin(arctg)); + (*i).pos.setY((*i).pos.y() + -(*i).speed*std::cos(arctg)); //return true; - gameData->curAliens.insert(al.Id,al); + //gameData->curAliens.insert(al.id,al); //qDebug() <<"alien"<< i << " path index=" << al.pathIndex << ", pos=" << al.pos; } for (int j=0; j + @@ -23,7 +24,7 @@ - + diff --git a/graphicsalien.cpp b/graphicsalien.cpp new file mode 100644 index 0000000..aa36339 --- /dev/null +++ b/graphicsalien.cpp @@ -0,0 +1,18 @@ +#include "graphicsalien.h" + +GraphicsAlien::GraphicsAlien(QGraphicsItem *grItem) : QGraphicsItem(grItem) +{ + +} + + +QRectF GraphicsAlien::boundingRect() +{ + return QRectF(0,0,10,10); +} + + +void GraphicsAlien::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + +} diff --git a/graphicsalien.h b/graphicsalien.h new file mode 100644 index 0000000..84c9efe --- /dev/null +++ b/graphicsalien.h @@ -0,0 +1,14 @@ +#ifndef GRAPHICSALIEN_H +#define GRAPHICSALIEN_H + +#include + +class GraphicsAlien : public QGraphicsItem +{ +public: + GraphicsAlien(QGraphicsItem * grItem= 0); + QRectF boundingRect(); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); +}; + +#endif // GRAPHICSALIEN_H diff --git a/loader.cpp b/loader.cpp index c073e85..89d01d3 100644 --- a/loader.cpp +++ b/loader.cpp @@ -5,6 +5,7 @@ Loader::Loader(QObject *parent) : { doc = new QDomDocument("data"); //create(); + qDebug() << createMapExample(); //load(); } @@ -391,10 +392,10 @@ void Loader::fillTowerChains(QList * chlist, QList * trigIds, sr QString Loader::createMapExample() { QVector < QVector < int > > Cells; - Cells.resize(16); + Cells.resize(30); for (int i=0; istart(100); diff --git a/map.cpp b/map.cpp index 0da1fae..6617504 100644 --- a/map.cpp +++ b/map.cpp @@ -88,7 +88,7 @@ bool Map::addTowerOnMap(int playerId, QPoint pos) Cells[pos.x()][pos.y()]=PlayerTower-playerId; return true; } - if (Cells[pos.x()][pos.y()]==PlayerAlien+playerId) + if (Cells[pos.x()][pos.y()]==AlienPath+playerId) { Cells[pos.x()][pos.y()]=PlayerTower-playerId; bool ok=true; @@ -98,7 +98,7 @@ bool Map::addTowerOnMap(int playerId, QPoint pos) qDebug()<<"ok="<srcSplashes.at(srcId); SplashType spl;// = gameData->srcAliens.at(srcId); - spl.Id = nextId; + spl.id = nextId; spl.src = srcId; spl.TowerId = QPoint(-1,-1); spl.life = 0; @@ -39,7 +39,7 @@ bool Splashes::addSplash(int srcId, QPointF pos) trig.src = src.triggerIndexes.at(i); spl.triggers.push_back(trig); } - gameData->curSplashes.insert(spl.Id,spl); + gameData->curSplashes.insert(spl.id,spl); nextId++; return true; } @@ -48,7 +48,7 @@ bool Splashes::addSplash(int srcId, QPointF pos) void Splashes::addSplash(srcSplashType src, int index, TowerType tw) { SplashType spl; - spl.Id = nextId; + spl.id = nextId; spl.TowerId = tw.pos; if (!gameData->curAliens.contains(tw.aim)) qFatal("Error finding splash aim! Tower has nvalid aim!"); @@ -69,7 +69,7 @@ void Splashes::addSplash(srcSplashType src, int index, TowerType tw) trig.src = src.triggerIndexes.at(i); spl.triggers.push_back(trig); } - gameData->curSplashes.insert(spl.Id,spl); + gameData->curSplashes.insert(spl.id,spl); nextId++; } diff --git a/towers.cpp b/towers.cpp index a9625e7..531fe21 100644 --- a/towers.cpp +++ b/towers.cpp @@ -1,7 +1,9 @@ #include "towers.h" +#include + Towers::Towers(Game_Data *gd, QObject *parent) : - QObject(parent) + QObject(parent) { gameData = gd; } @@ -28,7 +30,7 @@ bool Towers::addTower(int playerId, int srcId, QPoint pos) tw.build = 0; tw.reload = 0; tw.aim = -1; - tw .oldAim = -1; + //tw .oldAim = -1; if (gameData->map->addTowerOnMap(playerId,pos)) { tw.pos = pos; @@ -48,20 +50,35 @@ void Towers::delTower(QPoint pos) void Towers::update() { - for (int i=0; icurTowers.size(); i++) + for (QHash::iterator i = gameData->curTowers.begin(); i != gameData->curTowers.end(); ++i) { - TowerType tw = gameData->curTowers.values().at(i); - srcTowerType stw = gameData->players.at(tw.PlayerId)->srcTowers.at(tw.src); - if (tw.build < stw.buildTime) + srcTowerType stw = gameData->players.at((*i).PlayerId)->srcTowers.at((*i).src); + if ((*i).build < stw.buildTime) { - tw.build++; + (*i).build++; } else { - // TODO: finding aim alien in this place - if (tw.reload < stw.reload) + if (gameData->players.at((*i).PlayerId)->selectAlienId > 0) { - tw.reload++; - } else { - emit shot(stw.splashes.at(0), 0, tw); + AlienType al = gameData->curAliens.value(gameData->players.at((*i).PlayerId)->selectAlienId); + float dist = (al.pos.x() - (*i).pos.x())*(al.pos.x() - (*i).pos.x()) + (al.pos.y() - (*i).pos.y())*(al.pos.y() - (*i).pos.y()); + if (dist < stw.radius) (*i).aim = al.id; + } + if ((*i).aim < 0) + { + for (QHash::iterator j = gameData->curAliens.begin(); j != gameData->curAliens.end(); ++j) + { + float dist = ((*j).pos.x() - (*i).pos.x())*((*j).pos.x() - (*i).pos.x()) + ((*j).pos.y() - (*i).pos.y())*((*j).pos.y() - (*i).pos.y()); + if (dist < stw.radius) (*i).aim = (*j).id; + else (*i).aim = -1; + } + } + // TODO: rotate tower to aim + if ((*i).reload < stw.reload) + (*i).reload++; + else + { + if ((*i).aim > 0) + emit shot(stw.splashes.at(0), 0, (*i)); } } }