build_towers

This commit is contained in:
unknown
2010-08-31 21:29:47 +04:00
parent bbb6f9b366
commit 0e0f1cbfbb
8 changed files with 82 additions and 21 deletions

View File

@@ -15,7 +15,7 @@
<valuemap type="QVariantMap">
<value key="ProjectExplorer.ProjectConfiguration.DisplayName" type="QString">Настольный компьютер</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>
<valuemap key="ProjectExplorer.Target.BuildConfiguration.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.Id" type="QString">Qt4ProjectManager.Qt4BuildConfiguration</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.ToolChain" type="int">2</value>
<value key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild" type="bool">true</value>

View File

@@ -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();

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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;

55
map.cpp
View File

@@ -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<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;
// for (int i=0; i<Starts.size(); i++)
// for (int j=0; j<Finishs.size(); j++)
@@ -137,14 +161,17 @@ bool Map::addTowerOnMap(int playerId, QPoint pos)
qDebug() << *pathOK;
if (!pathOK)
{
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;
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(pathOK);
return false;
}
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;
return false;
@@ -204,8 +231,16 @@ QVector<QPointF> Map::createPath(QPoint start, QPoint finish)
QVector<QPointF> tmpPath;
QVector<QPointF> 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<srcPath.size();i++)
{

2
map.h
View File

@@ -34,7 +34,7 @@ public:
explicit Map(QByteArray data, QSize size, QString name, int maxPlayers, int image, QObject *parent = 0);
bool addTowerOnMap(int playerId, QPoint pos);
bool isFreePlace(QPoint pos);
void delTowerOnMap(QPoint pos);
void delTowerOnMap(int playerId, QPoint pos);
void removeAliensPath();
QVector <QPointF> createPath(QPoint start, QPoint finish);
QRect rect() const {return QRect(QPoint(),mapSize);}

View File

@@ -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<int, AlienType>::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);
}
}