changes in arhitecture, some improvments, much optimising and simplify,
many bagfixes and new graphics engine
This commit is contained in:
109
map.cpp
109
map.cpp
@@ -39,28 +39,6 @@ Map::Map(QByteArray data, QSize size, QString name, int maxPlayers, int image, Q
|
||||
}
|
||||
|
||||
|
||||
//void Map::ReadSettings()
|
||||
//{
|
||||
// QString str;
|
||||
// SettingsReader * sreader = new SettingsReader("map.conf");
|
||||
// str = sreader->getValue("cells path");
|
||||
// maxPlayers = sreader->getValue("max players","1").toInt();
|
||||
// QFile * f = new QFile(str);
|
||||
// f->open(QIODevice::ReadOnly);
|
||||
// QDataStream s(f);
|
||||
// s >> Cells;
|
||||
// if (Cells.size()>0)
|
||||
// {
|
||||
// mapsize.setWidth(Cells.size());
|
||||
// mapsize.setHeight(Cells[0].size());
|
||||
// //qDebug() << "Map size" << mapsize;
|
||||
// //printMap();
|
||||
// } else qDebug("invalid size");
|
||||
// delete f;
|
||||
// delete sreader;
|
||||
//}
|
||||
|
||||
|
||||
void Map::printMap()
|
||||
{
|
||||
for (int i=0; i<Cells.size(); i++) qDebug()<<Cells.at(i);
|
||||
@@ -82,9 +60,9 @@ void Map::removeAliensPath()
|
||||
void Map::delTowerOnMap(int playerId, QPoint pos)
|
||||
{
|
||||
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;
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -92,16 +70,16 @@ void Map::delTowerOnMap(int playerId, QPoint pos)
|
||||
bool Map::isReachable(int playerId, QPoint pos)
|
||||
{
|
||||
Cells[pos.x()][pos.y()]=PlayerTower-Player-playerId;
|
||||
Cells[pos.x()+1][pos.y()]=PlayerTower-Player-playerId;
|
||||
Cells[pos.x()][pos.y()+1]=PlayerTower-Player-playerId;
|
||||
Cells[pos.x()+1][pos.y()+1]=PlayerTower-Player-playerId;
|
||||
Cells[pos.x()-1][pos.y()]=PlayerTower-Player-playerId;
|
||||
Cells[pos.x()][pos.y()-1]=PlayerTower-Player-playerId;
|
||||
Cells[pos.x()-1][pos.y()-1]=PlayerTower-Player-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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -112,22 +90,21 @@ bool Map::isReachable(int playerId, QPoint pos)
|
||||
|
||||
bool Map::addTowerOnMap(int playerId, QPoint pos)
|
||||
{
|
||||
//qDebug() << pos;
|
||||
if (playerId < 0 || playerId > players) return false;
|
||||
QRect r(QPoint(),mapSize);
|
||||
if (!r.contains(pos) ||
|
||||
!r.contains(pos+QPoint(1,0)) ||
|
||||
!r.contains(pos+QPoint(0,1)) ||
|
||||
!r.contains(pos+QPoint(1,1))) return false;
|
||||
!r.contains(pos-QPoint(1,0)) ||
|
||||
!r.contains(pos-QPoint(0,1)) ||
|
||||
!r.contains(pos-QPoint(1,1))) return false;
|
||||
if (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)
|
||||
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 isReachable(playerId,pos);
|
||||
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()-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))
|
||||
{
|
||||
if (!isReachable(playerId,pos)) return false;
|
||||
bool * pathOK;
|
||||
@@ -144,59 +121,12 @@ bool Map::addTowerOnMap(int playerId, QPoint pos)
|
||||
}
|
||||
|
||||
|
||||
//void Map::CreateMapExample()
|
||||
//{
|
||||
// Cells.resize(16);
|
||||
// for (int i=0; i<Cells.size(); i++)
|
||||
// {
|
||||
// Cells[i].resize(16);
|
||||
// Cells[i][0]=Wall;
|
||||
// Cells[i][Cells[i].size()-1]=Wall;
|
||||
// }
|
||||
// for (int i=0; i<Cells.size(); i++)
|
||||
// {
|
||||
// for (int j=0; j<Cells[i].size(); j++)
|
||||
// {
|
||||
// Cells[0][j]=Wall;
|
||||
// Cells[Cells.size()-1][j]=Wall;
|
||||
// }
|
||||
// }
|
||||
// for (int i=1; i<Cells.size()/2; i++)
|
||||
// for (int j=1; j<Cells[i].size()-1; j++)
|
||||
// Cells[i][j]=Player;
|
||||
// for (int i=Cells.size()/2; i<Cells.size()-1; i++)
|
||||
// for (int j=1; j<Cells[i].size()-1; j++)
|
||||
// Cells[i][j]=Player+1;
|
||||
// for (int i=2; i<Cells.size()-2; i++)
|
||||
// Cells[i][Cells[i].size()/2] = Wall;
|
||||
// Cells[Cells.size()/2][0]=Start;
|
||||
// Cells[Cells.size()/2-1][0]=Start;
|
||||
// Cells[Cells.size()/2][Cells[Cells.size()/2].size()-1]=Finish;
|
||||
// Cells[Cells.size()/2-1][Cells[Cells.size()/2].size()-1]=Finish;
|
||||
// QFile * f = new QFile("example16x16_64.map");
|
||||
// f->open(QIODevice::ReadWrite);
|
||||
// f->resize(0);
|
||||
// QByteArray ba;
|
||||
// QDataStream tmps(&ba,QIODevice::ReadWrite);
|
||||
// tmps << Cells;
|
||||
// ba = qCompress(ba);
|
||||
// ba = ba.toBase64();
|
||||
// QString str(ba);
|
||||
//// QDataStream s(f);
|
||||
//// s << ba;
|
||||
// f->write(str.toUtf8());
|
||||
// f->close();
|
||||
// delete f;
|
||||
//}
|
||||
|
||||
|
||||
QVector<QPointF> Map::createPath(QPoint start, QPoint finish)
|
||||
{
|
||||
QPointF tp;
|
||||
QVector<QPoint> srcPath;
|
||||
QVector<QPointF> tmpPath;
|
||||
QVector<QPointF> path;
|
||||
//PathIndex = 1;
|
||||
if (Cells[start.x()][start.y()] < 0)
|
||||
{
|
||||
qDebug("ERROR invalid start");
|
||||
@@ -216,7 +146,6 @@ QVector<QPointF> Map::createPath(QPoint start, QPoint finish)
|
||||
tmpPath.push_back(QPointF(srcPath.at(i)));
|
||||
}
|
||||
srcPath.clear();
|
||||
//qDebug() << tmpPath.size();
|
||||
if (!tmpPath.isEmpty())
|
||||
{
|
||||
for (int j=0; j<4; j++)
|
||||
@@ -226,7 +155,6 @@ QVector<QPointF> Map::createPath(QPoint start, QPoint finish)
|
||||
path.push_back(tp);
|
||||
for (int i = 0; i < tmpPath.size() - 1; i++)
|
||||
{
|
||||
//if (j > 1) path.push_back(tmpPath[i]);
|
||||
tp.setX((tmpPath.at(i).x() + tmpPath.at(i + 1).x()) / 2.0);
|
||||
tp.setY((tmpPath.at(i).y() + tmpPath.at(i + 1).y()) / 2.0);
|
||||
path.push_back(tp);
|
||||
@@ -319,7 +247,6 @@ int Map::waveTrace(QPoint start, QPoint finish)
|
||||
step++;
|
||||
}
|
||||
qDebug() << "trace false";
|
||||
//qDebug() << TmpCells;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user