build_towers
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
<valuemap type="QVariantMap">
|
<valuemap type="QVariantMap">
|
||||||
<value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Настольный компьютер</value>
|
<value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Настольный компьютер</value>
|
||||||
<value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Target.DesktopTarget</value>
|
<value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Target.DesktopTarget</value>
|
||||||
<value key="ProjectExplorer.Target.ActiveBuildConfiguration" type="int">0</value>
|
<value key="ProjectExplorer.Target.ActiveBuildConfiguration" type="int">1</value>
|
||||||
<value key="ProjectExplorer.Target.ActiveRunConfiguration" type="int">0</value>
|
<value key="ProjectExplorer.Target.ActiveRunConfiguration" type="int">0</value>
|
||||||
<valuemap key="ProjectExplorer.Target.BuildConfiguration.0" type="QVariantMap">
|
<valuemap key="ProjectExplorer.Target.BuildConfiguration.0" type="QVariantMap">
|
||||||
<valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
|
<valuemap key="ProjectExplorer.BuildConfiguration.BuildStep.0" type="QVariantMap">
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
<value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Release</value>
|
<value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Release</value>
|
||||||
<value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
|
<value key="ProjectExplorer.ProjectConfiguration.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</value>
|
||||||
<value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">0</value>
|
<value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration" type="int">0</value>
|
||||||
<value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">C:/Users/Andrey/Desktop/aliendefender/ADeditor-build-desktop</value>
|
<value key="Qt4ProjectManager.Qt4BuildConfiguration.BuildDirectory" type="QString">C:/Users/Andrey/Desktop/build-AD</value>
|
||||||
<value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">9</value>
|
<value key="Qt4ProjectManager.Qt4BuildConfiguration.QtVersionId" type="int">9</value>
|
||||||
<value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">2</value>
|
<value key="Qt4ProjectManager.Qt4BuildConfiguration.ToolChain" type="int">2</value>
|
||||||
<value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
|
<value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>
|
||||||
|
|||||||
@@ -28,12 +28,24 @@ AD_Graphics::~AD_Graphics()
|
|||||||
delete scene;
|
delete scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AD_Graphics::mouseDoubleClickEvent(QMouseEvent *)
|
void AD_Graphics::mouseDoubleClickEvent(QMouseEvent *)
|
||||||
{
|
{
|
||||||
core->nextWave();
|
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 * )
|
void AD_Graphics::timerEvent(QTimerEvent * )
|
||||||
{
|
{
|
||||||
//qDebug() << data->curAliens.size();
|
//qDebug() << data->curAliens.size();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ private:
|
|||||||
void drawBackground(QPainter * p, const QRectF &);
|
void drawBackground(QPainter * p, const QRectF &);
|
||||||
void loadImages();
|
void loadImages();
|
||||||
void mouseDoubleClickEvent(QMouseEvent *);
|
void mouseDoubleClickEvent(QMouseEvent *);
|
||||||
|
void mousePressEvent(QMouseEvent *event);
|
||||||
|
|
||||||
QGraphicsScene * scene;
|
QGraphicsScene * scene;
|
||||||
Game_Data * data;
|
Game_Data * data;
|
||||||
@@ -32,7 +33,7 @@ private:
|
|||||||
//QGraphicsWidget * gsw;
|
//QGraphicsWidget * gsw;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void timerEvent(QTimerEvent * );
|
void timerEvent(QTimerEvent * );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // AD_GRAPHICS_H
|
#endif // AD_GRAPHICS_H
|
||||||
|
|||||||
10
adcore.cpp
10
adcore.cpp
@@ -26,11 +26,11 @@ AD_Core::AD_Core(QObject *parent) :
|
|||||||
// adaliens->AddAlien(0);
|
// adaliens->AddAlien(0);
|
||||||
adtowers->addTower(0,2,QPoint(22,7));
|
adtowers->addTower(0,2,QPoint(22,7));
|
||||||
for (int i=0; i<20;i++)
|
for (int i=0; i<20;i++)
|
||||||
adtowers->addTower(0,1,QPoint(8,20-i));
|
// adtowers->addTower(0,1,QPoint(8,20-i));
|
||||||
for (int i=0; i<20; i++)
|
// for (int i=0; i<20; i++)
|
||||||
adtowers->addTower(0,0,QPoint(12,i));
|
// adtowers->addTower(0,0,QPoint(12,i));
|
||||||
for (int i=0; i<20;i++)
|
// for (int i=0; i<20;i++)
|
||||||
adtowers->addTower(0,1,QPoint(16,20-i));
|
// adtowers->addTower(0,1,QPoint(16,20-i));
|
||||||
waveInProgress = false;
|
waveInProgress = false;
|
||||||
startTimer(20);
|
startTimer(20);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,11 @@ void Aliens::addAlien(int srcId)
|
|||||||
al.pathIndex = 1;
|
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.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;
|
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;
|
//qDebug() << al.path;
|
||||||
al.health = gameData->srcAliens.at(srcId).health;
|
al.health = gameData->srcAliens.at(srcId).health;
|
||||||
al.speed = gameData->srcAliens.at(srcId).speed;
|
al.speed = gameData->srcAliens.at(srcId).speed;
|
||||||
|
|||||||
55
map.cpp
55
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)
|
bool Map::addTowerOnMap(int playerId, QPoint pos)
|
||||||
{
|
{
|
||||||
//qDebug() << pos;
|
//qDebug() << pos;
|
||||||
@@ -109,15 +122,26 @@ bool Map::addTowerOnMap(int playerId, QPoint pos)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (Cells[pos.x()][pos.y()]==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+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+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+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()][pos.y()]=PlayerTower-playerId;
|
||||||
Cells[pos.x()+1][pos.y()]=PlayerTower-playerId;
|
Cells[pos.x()+1][pos.y()]=PlayerTower-playerId;
|
||||||
Cells[pos.x()][pos.y()+1]=PlayerTower-playerId;
|
Cells[pos.x()][pos.y()+1]=PlayerTower-playerId;
|
||||||
Cells[pos.x()+1][pos.y()+1]=PlayerTower-playerId;
|
Cells[pos.x()+1][pos.y()+1]=PlayerTower-playerId;
|
||||||
|
for (int i=0; i<Starts.size(); i++) {
|
||||||
|
for (int j=0; j<Finishs.size(); j++) {
|
||||||
|
if (waveTrace(Starts.at(i),Finishs.at(j))<0) {
|
||||||
|
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;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// bool ok=true;
|
// bool ok=true;
|
||||||
// for (int i=0; i<Starts.size(); i++)
|
// for (int i=0; i<Starts.size(); i++)
|
||||||
// for (int j=0; j<Finishs.size(); j++)
|
// for (int j=0; j<Finishs.size(); j++)
|
||||||
@@ -137,14 +161,17 @@ bool Map::addTowerOnMap(int playerId, QPoint pos)
|
|||||||
qDebug() << *pathOK;
|
qDebug() << *pathOK;
|
||||||
if (!pathOK)
|
if (!pathOK)
|
||||||
{
|
{
|
||||||
Cells[pos.x()][pos.y()]=AlienPath+playerId;
|
Cells[pos.x()][pos.y()]=Player+playerId;
|
||||||
Cells[pos.x()+1][pos.y()]=AlienPath+playerId;
|
Cells[pos.x()+1][pos.y()]=Player+playerId;
|
||||||
Cells[pos.x()][pos.y()+1]=AlienPath+playerId;
|
Cells[pos.x()][pos.y()+1]=Player+playerId;
|
||||||
Cells[pos.x()+1][pos.y()+1]=AlienPath+playerId;
|
Cells[pos.x()+1][pos.y()+1]=Player+playerId;
|
||||||
emit recreateAlienPath(pathOK);
|
emit recreateAlienPath(pathOK);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
qDebug() << Cells[pos.x()][pos.y()] << Cells[pos.x()+1][pos.y()] << Cells[pos.x()][pos.y()+1] << Cells[pos.x()+1][pos.y()+1];
|
||||||
|
qDebug() << playerId;
|
||||||
}
|
}
|
||||||
qDebug()<<"Dont buid here" << pos;
|
qDebug()<<"Dont buid here" << pos;
|
||||||
return false;
|
return false;
|
||||||
@@ -204,8 +231,16 @@ QVector<QPointF> Map::createPath(QPoint start, QPoint finish)
|
|||||||
QVector<QPointF> tmpPath;
|
QVector<QPointF> tmpPath;
|
||||||
QVector<QPointF> path;
|
QVector<QPointF> path;
|
||||||
//PathIndex = 1;
|
//PathIndex = 1;
|
||||||
if (Cells[start.x()][start.y()] < 0) qDebug("ERROR invalid start"),exit(-1);
|
if (Cells[start.x()][start.y()] < 0)
|
||||||
if (Cells[finish.x()][finish.y()] < 0) qDebug("ERROR invalid finish"),exit(-1);
|
{
|
||||||
|
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));
|
srcPath = invWaveTrace(finish,waveTrace(start,finish));
|
||||||
for (int i=0; i<srcPath.size();i++)
|
for (int i=0; i<srcPath.size();i++)
|
||||||
{
|
{
|
||||||
|
|||||||
2
map.h
2
map.h
@@ -34,7 +34,7 @@ public:
|
|||||||
explicit Map(QByteArray data, QSize size, QString name, int maxPlayers, int image, QObject *parent = 0);
|
explicit Map(QByteArray data, QSize size, QString name, int maxPlayers, int image, QObject *parent = 0);
|
||||||
bool addTowerOnMap(int playerId, QPoint pos);
|
bool addTowerOnMap(int playerId, QPoint pos);
|
||||||
bool isFreePlace(QPoint pos);
|
bool isFreePlace(QPoint pos);
|
||||||
void delTowerOnMap(QPoint pos);
|
void delTowerOnMap(int playerId, QPoint pos);
|
||||||
void removeAliensPath();
|
void removeAliensPath();
|
||||||
QVector <QPointF> createPath(QPoint start, QPoint finish);
|
QVector <QPointF> createPath(QPoint start, QPoint finish);
|
||||||
QRect rect() const {return QRect(QPoint(),mapSize);}
|
QRect rect() const {return QRect(QPoint(),mapSize);}
|
||||||
|
|||||||
11
towers.cpp
11
towers.cpp
@@ -22,6 +22,11 @@ bool Towers::addTower(int playerId, int srcId, QPoint pos)
|
|||||||
qCritical("ERROR out of towers range");
|
qCritical("ERROR out of towers range");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
QRect alrec(pos,QSize(1,1));
|
||||||
|
for (QHash<int, AlienType>::iterator i = gameData->curAliens.begin(); i != gameData->curAliens.end(); ++i)
|
||||||
|
{
|
||||||
|
if (alrec.contains((*i).pos.toPoint())) return false;
|
||||||
|
}
|
||||||
TowerType tw;
|
TowerType tw;
|
||||||
tw.src = srcId;
|
tw.src = srcId;
|
||||||
tw.imgType = gameData->players.at(playerId)->srcTowers.at(srcId).imgType;
|
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)
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user