I think finished structures
and some changes in loading and changes in map class we have 2 TODO now
This commit is contained in:
22
aliens.cpp
22
aliens.cpp
@@ -17,15 +17,18 @@ void Aliens::AddAlien(int srcId)
|
|||||||
qCritical("ERROR out of aliens range");
|
qCritical("ERROR out of aliens range");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Alien al = gameData->srcAliens.at(srcId);
|
AlienType al;// = gameData->srcAliens.at(srcId);
|
||||||
al.Id = nextId;
|
al.Id = nextId;
|
||||||
al.finish = gameData->map->finishs.at(qrand()%gameData->map->finishs.size());
|
al.src = srcId;
|
||||||
qDebug()<<gameData->map->finishs.size()<<qrand()%gameData->map->finishs.size();
|
al.finish = gameData->map->Finishs().at(qrand()%gameData->map->Finishs().size());
|
||||||
al.pos = QPointF(gameData->map->starts.at(qrand()%gameData->map->starts.size()));
|
al.pos = QPointF(gameData->map->Starts().at(qrand()%gameData->map->Starts().size()));
|
||||||
al.path = gameData->map->CreatePath(al.pos.toPoint(),al.finish);
|
al.path = gameData->map->CreatePath(al.pos.toPoint(),al.finish);
|
||||||
al.pathIndex = 1;
|
al.pathIndex = 1;
|
||||||
if (al.path.isEmpty()) qFatal("ERROR create path");
|
if (al.path.isEmpty()) qFatal("ERROR create path");
|
||||||
qDebug() << al.path;
|
qDebug() << al.path;
|
||||||
|
al.health = gameData->srcAliens.at(srcId).health;
|
||||||
|
al.speed = gameData->srcAliens.at(srcId).speed;
|
||||||
|
al.imgType = gameData->srcAliens.at(srcId).imgType;
|
||||||
//gameData->map->printMap();
|
//gameData->map->printMap();
|
||||||
gameData->curAliens.insert(al.Id,al);
|
gameData->curAliens.insert(al.Id,al);
|
||||||
nextId++;
|
nextId++;
|
||||||
@@ -38,10 +41,9 @@ void Aliens::retrace(bool *OK)
|
|||||||
gameData->map->removeAliensPath();
|
gameData->map->removeAliensPath();
|
||||||
for (int i=0; i<gameData->curAliens.size(); i++)
|
for (int i=0; i<gameData->curAliens.size(); i++)
|
||||||
{
|
{
|
||||||
Alien al = gameData->curAliens.take(i);
|
gameData->curAliens.values()[i].path = gameData->map->CreatePath(gameData->curAliens.values()[i].pos.toPoint(),gameData->curAliens.values()[i].finish);
|
||||||
al.path = gameData->map->CreatePath(al.pos.toPoint(),al.finish);
|
gameData->curAliens.values()[i].pathIndex = 1;
|
||||||
al.pathIndex = 1;
|
if (gameData->curAliens.values()[i].path.isEmpty()) *OK = false;
|
||||||
if (al.path.isEmpty()) *OK = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +59,7 @@ void Aliens::update()
|
|||||||
QList <int> missIndex;
|
QList <int> missIndex;
|
||||||
for (int i=0; i<gameData->curAliens.size(); i++)
|
for (int i=0; i<gameData->curAliens.size(); i++)
|
||||||
{
|
{
|
||||||
Alien al = gameData->curAliens.values().at(i);
|
AlienType al = gameData->curAliens.values().at(i);
|
||||||
//qDebug() << i;
|
//qDebug() << i;
|
||||||
//if (al.health < 0) emit AlienKill();
|
//if (al.health < 0) emit AlienKill();
|
||||||
float tmpdx,tmpdy,angl,arctg = 0;
|
float tmpdx,tmpdy,angl,arctg = 0;
|
||||||
@@ -101,7 +103,7 @@ void Aliens::update()
|
|||||||
al.pos.setY(al.pos.y()
|
al.pos.setY(al.pos.y()
|
||||||
-al.speed*std::cos(arctg));
|
-al.speed*std::cos(arctg));
|
||||||
//return true;
|
//return true;
|
||||||
gameData->curAliens[al.Id] = al;
|
gameData->curAliens.insert(al.Id,al);
|
||||||
}
|
}
|
||||||
for (int j=0; j<missIndex.size(); j++)
|
for (int j=0; j<missIndex.size(); j++)
|
||||||
{
|
{
|
||||||
|
|||||||
10
base_types.h
10
base_types.h
@@ -37,7 +37,8 @@ struct srcAlienType
|
|||||||
struct TowerType
|
struct TowerType
|
||||||
{
|
{
|
||||||
int src;
|
int src;
|
||||||
int AlienId; // aim alien
|
int aim; // aim alien Id
|
||||||
|
int oldAim;
|
||||||
int PlayerId; // tower's owner
|
int PlayerId; // tower's owner
|
||||||
int imgType;
|
int imgType;
|
||||||
QPoint pos; // not QPointF because tower fixed on grid
|
QPoint pos; // not QPointF because tower fixed on grid
|
||||||
@@ -100,7 +101,6 @@ struct SplashType
|
|||||||
int imgType;
|
int imgType;
|
||||||
int src;
|
int src;
|
||||||
QPoint TowerId; // parent tower (-1;-1) for null parent
|
QPoint TowerId; // parent tower (-1;-1) for null parent
|
||||||
int PlayerId;
|
|
||||||
int AlienId; // aim alien (different from tower.AlienId)
|
int AlienId; // aim alien (different from tower.AlienId)
|
||||||
QPointF destination;
|
QPointF destination;
|
||||||
int life; // in ticks
|
int life; // in ticks
|
||||||
@@ -109,13 +109,13 @@ struct SplashType
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct Wave
|
struct WaveType
|
||||||
{
|
{
|
||||||
int Id;
|
int Id;
|
||||||
QList <int> types; // some types of aliens (e.g. 2 fly and 3 grount in one wave)
|
QList <int> types; // some types of aliens (e.g. 2 fly and 3 grount in one wave)
|
||||||
QList <int> counts; // count aliens of each type
|
QList <int> counts; // count aliens of each type
|
||||||
int wait_time; // time in ticks
|
unsigned int timeout; // time in ticks
|
||||||
unsigned int gold;
|
unsigned int prise;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
data.xml
2
data.xml
@@ -6,7 +6,7 @@
|
|||||||
<alien speed="0.0099" score="350" imageType="1" prise="1" id="12" name="MONSTR" health="200" armor="1.5" regeneration="3"/>
|
<alien speed="0.0099" score="350" imageType="1" prise="1" id="12" name="MONSTR" health="200" armor="1.5" regeneration="3"/>
|
||||||
</aliens>
|
</aliens>
|
||||||
<maps>
|
<maps>
|
||||||
<map imageType="1" id="1" data="AAAERHicY2BgEGAA4v///0hQgmFmAGlGcjCxZuCTHzUDuxkMDOr85JrBwKC0A8kMJlwYagYOeYgZ+NXgNwMtPEbNINIMIsynOO8DAG0r1Q0=" name="Map 16x16" maxPlayers="2"/>
|
<map imageType="1" id="1" data="AAAERHicY2BgEGAA4v///0hQgmFmAGlGcjCxZuCTHzUDuxkMDOr85JrBwKC0A8kMJlwYagYOeYgZ+NXgNwMtPEbNINIMIsynOO8DAG0r1Q0=" name="My Map" width="16" height="16" maxPlayers="2"/>
|
||||||
</maps>
|
</maps>
|
||||||
<waves>
|
<waves>
|
||||||
<wave id="1" timeout="20000" prise="100"/>
|
<wave id="1" timeout="20000" prise="100"/>
|
||||||
|
|||||||
11
game_data.h
11
game_data.h
@@ -11,12 +11,11 @@ class Game_Data : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Game_Data(Map * map, QObject *parent = 0);
|
explicit Game_Data(Map * map, QObject *parent = 0);
|
||||||
QList <Alien> srcAliens;
|
QList <srcAlienType> srcAliens;
|
||||||
QList <Tower> srcTowers;
|
QHash <int,AlienType> curAliens;
|
||||||
QHash <int,Alien> curAliens;
|
QHash <QPoint,TowerType> curTowers;
|
||||||
QHash <QPoint,Tower> curTowers;
|
QHash <int,SplashType> curSplashes;
|
||||||
QHash <int,Splash> curSplashes;
|
QList <WaveType> waves;
|
||||||
QList <Wave> waves;
|
|
||||||
QList <Player *> players;
|
QList <Player *> players;
|
||||||
Map * map;
|
Map * map;
|
||||||
int curWave;
|
int curWave;
|
||||||
|
|||||||
10
loader.cpp
10
loader.cpp
@@ -491,13 +491,11 @@ void Loader::readMaps()
|
|||||||
m.name = mn.namedItem("name").nodeValue();
|
m.name = mn.namedItem("name").nodeValue();
|
||||||
m.imgType = mn.namedItem("imageType").nodeValue().toInt();
|
m.imgType = mn.namedItem("imageType").nodeValue().toInt();
|
||||||
m.maxPlayers = mn.namedItem("maxPlayers").nodeValue().toInt();
|
m.maxPlayers = mn.namedItem("maxPlayers").nodeValue().toInt();
|
||||||
QByteArray ba = QByteArray::fromBase64(mn.namedItem("data").nodeValue().toUtf8());
|
m.data=mn.namedItem("data").nodeValue().toUtf8();
|
||||||
ba = qUncompress(ba);
|
m.size.setWidth(mn.namedItem("width").nodeValue().toInt());
|
||||||
QDataStream s(ba);
|
m.size.setHeight(mn.namedItem("height").nodeValue().toInt());
|
||||||
s >> m.cells;
|
|
||||||
maps.insert(m.id,m);
|
maps.insert(m.id,m);
|
||||||
qDebug() << tr("Map %1 id=%2 imgType=%3 maxPlayers=%5").arg(m.name).arg(m.id).arg(m.imgType).arg(m.maxPlayers);
|
qDebug() << tr("Map %1 id=%2 imgType=%3 maxPlayers=%5 data=%6 ").arg(m.name).arg(m.id).arg(m.imgType).arg(m.maxPlayers).arg(QString(m.data)) << m.size;
|
||||||
for (int k=0; k<m.cells.size(); k++) qDebug()<<m.cells.at(k);
|
|
||||||
}
|
}
|
||||||
qDebug("================");
|
qDebug("================");
|
||||||
qDebug() << tr("Found %1 maps").arg(maps.size());
|
qDebug() << tr("Found %1 maps").arg(maps.size());
|
||||||
|
|||||||
8
loader.h
8
loader.h
@@ -117,7 +117,7 @@ struct tbWave
|
|||||||
int id;
|
int id;
|
||||||
unsigned int timeout;
|
unsigned int timeout;
|
||||||
unsigned int prise;
|
unsigned int prise;
|
||||||
int type;
|
//int type;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tbWaveOnLevel
|
struct tbWaveOnLevel
|
||||||
@@ -131,7 +131,9 @@ struct tbMap
|
|||||||
int id;
|
int id;
|
||||||
QString name;
|
QString name;
|
||||||
unsigned int maxPlayers;
|
unsigned int maxPlayers;
|
||||||
QVector < QVector <int> > cells;
|
//QVector < QVector <int> > cells;
|
||||||
|
QByteArray data;
|
||||||
|
QSize size;
|
||||||
int imgType;
|
int imgType;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -158,7 +160,7 @@ public:
|
|||||||
explicit Loader(QObject *parent = 0);
|
explicit Loader(QObject *parent = 0);
|
||||||
void create();
|
void create();
|
||||||
void reload();
|
void reload();
|
||||||
void loadlevel(Game_Data * gd);
|
Game_Data * loadlevel();
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|||||||
172
map.cpp
172
map.cpp
@@ -1,18 +1,30 @@
|
|||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
|
||||||
Map::Map(int Id, QObject *parent) :
|
Map::Map(QByteArray data, QSize size, QString name, int maxPlayers, int image, QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
mapId=Id;
|
QByteArray ba = QByteArray::fromBase64(data);
|
||||||
}
|
ba = qUncompress(ba);
|
||||||
|
QDataStream s(ba);
|
||||||
|
mapName = name;
|
||||||
void Map::load()
|
s >> Cells;
|
||||||
{
|
int chei;
|
||||||
//ReadSettings();
|
if (Cells.size() <= 0)
|
||||||
//CreateMapExample();
|
qFatal("Map has invalid width");
|
||||||
|
if (Cells.size() != size.width())
|
||||||
|
qCritical("Map has wrong width");
|
||||||
|
mapSize.setWidth(Cells.size());
|
||||||
|
chei = Cells.at(0).size();
|
||||||
for (int i=0; i<Cells.size(); i++)
|
for (int i=0; i<Cells.size(); i++)
|
||||||
{
|
{
|
||||||
|
if (Cells[i].size() <= 0)
|
||||||
|
qFatal("Map has invalid height");
|
||||||
|
if (Cells[i].size() != size.height())
|
||||||
|
{
|
||||||
|
qCritical("Map has wrong height");
|
||||||
|
if (Cells[i].size() != chei)
|
||||||
|
qFatal("Corrupted map data");
|
||||||
|
}
|
||||||
for (int j=0; j<Cells[i].size(); j++)
|
for (int j=0; j<Cells[i].size(); j++)
|
||||||
{
|
{
|
||||||
if (Cells[i][j]==Start) starts.push_back(QPoint(i,j));
|
if (Cells[i][j]==Start) starts.push_back(QPoint(i,j));
|
||||||
@@ -20,29 +32,32 @@ void Map::load()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (starts.isEmpty() || finishs.isEmpty()) qFatal("invalid map, not found start/finish");
|
if (starts.isEmpty() || finishs.isEmpty()) qFatal("invalid map, not found start/finish");
|
||||||
|
// TODO: check for maxPlayers
|
||||||
|
players = maxPlayers;
|
||||||
|
imageType = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Map::ReadSettings()
|
//void Map::ReadSettings()
|
||||||
{
|
//{
|
||||||
QString str;
|
// QString str;
|
||||||
SettingsReader * sreader = new SettingsReader("map.conf");
|
// SettingsReader * sreader = new SettingsReader("map.conf");
|
||||||
str = sreader->getValue("cells path");
|
// str = sreader->getValue("cells path");
|
||||||
maxPlayers = sreader->getValue("max players","1").toInt();
|
// maxPlayers = sreader->getValue("max players","1").toInt();
|
||||||
QFile * f = new QFile(str);
|
// QFile * f = new QFile(str);
|
||||||
f->open(QIODevice::ReadOnly);
|
// f->open(QIODevice::ReadOnly);
|
||||||
QDataStream s(f);
|
// QDataStream s(f);
|
||||||
s >> Cells;
|
// s >> Cells;
|
||||||
if (Cells.size()>0)
|
// if (Cells.size()>0)
|
||||||
{
|
// {
|
||||||
mapsize.setWidth(Cells.size());
|
// mapsize.setWidth(Cells.size());
|
||||||
mapsize.setHeight(Cells[0].size());
|
// mapsize.setHeight(Cells[0].size());
|
||||||
//qDebug() << "Map size" << mapsize;
|
// //qDebug() << "Map size" << mapsize;
|
||||||
//printMap();
|
// //printMap();
|
||||||
} else qDebug("invalid size");
|
// } else qDebug("invalid size");
|
||||||
delete f;
|
// delete f;
|
||||||
delete sreader;
|
// delete sreader;
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
void Map::printMap()
|
void Map::printMap()
|
||||||
@@ -64,8 +79,8 @@ void Map::removeAliensPath()
|
|||||||
|
|
||||||
bool Map::addTowerOnMap(int playerId, QPoint pos)
|
bool Map::addTowerOnMap(int playerId, QPoint pos)
|
||||||
{
|
{
|
||||||
if (playerId < 0 || playerId > maxPlayers) return false;
|
if (playerId < 0 || playerId > players) return false;
|
||||||
QRect r(QPoint(),mapsize);
|
QRect r(QPoint(),mapSize);
|
||||||
if (!r.contains(pos)) return false;
|
if (!r.contains(pos)) return false;
|
||||||
if (Cells[pos.x()][pos.y()]==Player+playerId)
|
if (Cells[pos.x()][pos.y()]==Player+playerId)
|
||||||
{
|
{
|
||||||
@@ -95,6 +110,7 @@ bool Map::addTowerOnMap(int playerId, QPoint pos)
|
|||||||
if (!pathOK)
|
if (!pathOK)
|
||||||
{
|
{
|
||||||
Cells[pos.x()][pos.y()]=PlayerAlien+playerId;
|
Cells[pos.x()][pos.y()]=PlayerAlien+playerId;
|
||||||
|
emit RecreateAlienPath(pathOK);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -104,50 +120,50 @@ bool Map::addTowerOnMap(int playerId, QPoint pos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Map::CreateMapExample()
|
//void Map::CreateMapExample()
|
||||||
{
|
//{
|
||||||
Cells.resize(16);
|
// Cells.resize(16);
|
||||||
for (int i=0; i<Cells.size(); i++)
|
// for (int i=0; i<Cells.size(); i++)
|
||||||
{
|
// {
|
||||||
Cells[i].resize(16);
|
// Cells[i].resize(16);
|
||||||
Cells[i][0]=Wall;
|
// Cells[i][0]=Wall;
|
||||||
Cells[i][Cells[i].size()-1]=Wall;
|
// Cells[i][Cells[i].size()-1]=Wall;
|
||||||
}
|
// }
|
||||||
for (int i=0; i<Cells.size(); i++)
|
// for (int i=0; i<Cells.size(); i++)
|
||||||
{
|
// {
|
||||||
for (int j=0; j<Cells[i].size(); j++)
|
// for (int j=0; j<Cells[i].size(); j++)
|
||||||
{
|
// {
|
||||||
Cells[0][j]=Wall;
|
// Cells[0][j]=Wall;
|
||||||
Cells[Cells.size()-1][j]=Wall;
|
// Cells[Cells.size()-1][j]=Wall;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
for (int i=1; i<Cells.size()/2; i++)
|
// for (int i=1; i<Cells.size()/2; i++)
|
||||||
for (int j=1; j<Cells[i].size()-1; j++)
|
// for (int j=1; j<Cells[i].size()-1; j++)
|
||||||
Cells[i][j]=Player;
|
// Cells[i][j]=Player;
|
||||||
for (int i=Cells.size()/2; i<Cells.size()-1; i++)
|
// for (int i=Cells.size()/2; i<Cells.size()-1; i++)
|
||||||
for (int j=1; j<Cells[i].size()-1; j++)
|
// for (int j=1; j<Cells[i].size()-1; j++)
|
||||||
Cells[i][j]=Player+1;
|
// Cells[i][j]=Player+1;
|
||||||
for (int i=2; i<Cells.size()-2; i++)
|
// for (int i=2; i<Cells.size()-2; i++)
|
||||||
Cells[i][Cells[i].size()/2] = Wall;
|
// Cells[i][Cells[i].size()/2] = Wall;
|
||||||
Cells[Cells.size()/2][0]=Start;
|
// Cells[Cells.size()/2][0]=Start;
|
||||||
Cells[Cells.size()/2-1][0]=Start;
|
// Cells[Cells.size()/2-1][0]=Start;
|
||||||
Cells[Cells.size()/2][Cells[Cells.size()/2].size()-1]=Finish;
|
// Cells[Cells.size()/2][Cells[Cells.size()/2].size()-1]=Finish;
|
||||||
Cells[Cells.size()/2-1][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");
|
// QFile * f = new QFile("example16x16_64.map");
|
||||||
f->open(QIODevice::ReadWrite);
|
// f->open(QIODevice::ReadWrite);
|
||||||
f->resize(0);
|
// f->resize(0);
|
||||||
QByteArray ba;
|
// QByteArray ba;
|
||||||
QDataStream tmps(&ba,QIODevice::ReadWrite);
|
// QDataStream tmps(&ba,QIODevice::ReadWrite);
|
||||||
tmps << Cells;
|
// tmps << Cells;
|
||||||
ba = qCompress(ba);
|
// ba = qCompress(ba);
|
||||||
ba = ba.toBase64();
|
// ba = ba.toBase64();
|
||||||
QString str(ba);
|
// QString str(ba);
|
||||||
// QDataStream s(f);
|
//// QDataStream s(f);
|
||||||
// s << ba;
|
//// s << ba;
|
||||||
f->write(str.toUtf8());
|
// f->write(str.toUtf8());
|
||||||
f->close();
|
// f->close();
|
||||||
delete f;
|
// delete f;
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
QVector<QPointF> Map::CreatePath(QPoint start, QPoint finish)
|
QVector<QPointF> Map::CreatePath(QPoint start, QPoint finish)
|
||||||
@@ -207,7 +223,7 @@ int Map::WaveTrace(QPoint start, QPoint finish)
|
|||||||
bool stop = false;
|
bool stop = false;
|
||||||
int step = 2;
|
int step = 2;
|
||||||
QPoint cp, tp;
|
QPoint cp, tp;
|
||||||
QRect fr(QPoint(), mapsize);
|
QRect fr(QPoint(), mapSize);
|
||||||
QVector<QPoint> tmpp, curp;
|
QVector<QPoint> tmpp, curp;
|
||||||
TmpCells << Cells;
|
TmpCells << Cells;
|
||||||
for (int i = 0; i < Cells.size(); i++)
|
for (int i = 0; i < Cells.size(); i++)
|
||||||
@@ -293,7 +309,7 @@ QVector<QPoint> Map::InvWaveTrace(QPoint finish, int cnt)
|
|||||||
chk = chk | 0x01;
|
chk = chk | 0x01;
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
if (wp.x() + 1 < mapsize.width() && TmpCells[wp.x()+1][wp.y()] == cnt)
|
if (wp.x() + 1 < mapSize.width() && TmpCells[wp.x()+1][wp.y()] == cnt)
|
||||||
{
|
{
|
||||||
chk = chk | 0x02;
|
chk = chk | 0x02;
|
||||||
c++;
|
c++;
|
||||||
@@ -303,7 +319,7 @@ QVector<QPoint> Map::InvWaveTrace(QPoint finish, int cnt)
|
|||||||
chk = chk | 0x04;
|
chk = chk | 0x04;
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
if (wp.y() + 1 < mapsize.height() && TmpCells[wp.x()][wp.y()+1] == cnt)
|
if (wp.y() + 1 < mapSize.height() && TmpCells[wp.x()][wp.y()+1] == cnt)
|
||||||
{
|
{
|
||||||
chk = chk | 0x08;
|
chk = chk | 0x08;
|
||||||
c++;
|
c++;
|
||||||
|
|||||||
30
map.h
30
map.h
@@ -17,7 +17,6 @@ class Map : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum CellType
|
enum CellType
|
||||||
{
|
{
|
||||||
Player = 1,
|
Player = 1,
|
||||||
@@ -38,33 +37,38 @@ public:
|
|||||||
// -3 - -/-
|
// -3 - -/-
|
||||||
// -1000 - it is wall or some place where you can't build
|
// -1000 - it is wall or some place where you can't build
|
||||||
|
|
||||||
QVector < QVector <int> > Cells;
|
|
||||||
QList <QPoint> starts;
|
|
||||||
QList <QPoint> finishs;
|
|
||||||
int maxPlayers;
|
|
||||||
|
|
||||||
explicit Map(int Id, QObject *parent = 0);
|
explicit Map(QByteArray data, QSize size, QString name, int maxPlayers, int image, QObject *parent = 0);
|
||||||
int Id() const {return mapId;}
|
|
||||||
bool addTowerOnMap(int playerId, QPoint pos);
|
bool addTowerOnMap(int playerId, QPoint pos);
|
||||||
|
bool isFreePlace(QPoint pos);
|
||||||
void delTowerOnMap(QPoint pos);
|
void delTowerOnMap(QPoint pos);
|
||||||
void removeAliensPath();
|
void removeAliensPath();
|
||||||
QVector <QPointF> CreatePath(QPoint start, QPoint finish);
|
QVector <QPointF> CreatePath(QPoint start, QPoint finish);
|
||||||
QSize size() const {return mapsize;}
|
// QSize size() const {return mapsize;}
|
||||||
void load();
|
// QString name() const {return mapName;}
|
||||||
|
QList <QPoint> Starts() const {return starts;}
|
||||||
|
QList <QPoint> Finishs() const {return finishs;}
|
||||||
|
int Image() const {return imageType;}
|
||||||
signals:
|
signals:
|
||||||
void RecreateAlienPath(bool * pathOK);
|
void RecreateAlienPath(bool * pathOK);
|
||||||
public slots:
|
public slots:
|
||||||
void printMap();
|
void printMap();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int mapId;
|
QSize mapSize;
|
||||||
QSize mapsize;
|
QString mapName;
|
||||||
|
int players;
|
||||||
|
int imageType;
|
||||||
|
QVector < QVector <int> > Cells;
|
||||||
|
QList <QPoint> starts;
|
||||||
|
QList <QPoint> finishs;
|
||||||
|
|
||||||
QVector < QVector <int> > TmpCells;
|
QVector < QVector <int> > TmpCells;
|
||||||
|
|
||||||
QVector<QPoint> InvWaveTrace(QPoint finish, int cnt);
|
QVector<QPoint> InvWaveTrace(QPoint finish, int cnt);
|
||||||
int WaveTrace(QPoint start, QPoint finish);
|
int WaveTrace(QPoint start, QPoint finish);
|
||||||
void CreateMapExample();
|
//void CreateMapExample();
|
||||||
void ReadSettings();
|
//void ReadSettings();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAP_H
|
#endif // MAP_H
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ Player::Player(int Id, QObject *parent) :
|
|||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
playerId = Id;
|
playerId = Id;
|
||||||
adMoney = 100;
|
money = 100;
|
||||||
}
|
}
|
||||||
|
|||||||
6
player.h
6
player.h
@@ -10,10 +10,10 @@ class Player : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Player(int Id, QObject *parent = 0);
|
explicit Player(int Id, QObject *parent = 0);
|
||||||
unsigned long int adMoney;
|
unsigned long int money;
|
||||||
|
unsigned long int score;
|
||||||
int selectAlienId;
|
int selectAlienId;
|
||||||
QList <Tower> srcTowers;
|
QList <srcTowerType> srcTowers;
|
||||||
QList <Splash> srcSplashes;
|
|
||||||
int playerId;
|
int playerId;
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|||||||
@@ -155,6 +155,8 @@
|
|||||||
<xsd:attribute name="name" type="xsd:string" use="required"/>
|
<xsd:attribute name="name" type="xsd:string" use="required"/>
|
||||||
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
|
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
|
||||||
<xsd:attribute name="maxPlayers" type="xsd:positiveInteger" use="required"/>
|
<xsd:attribute name="maxPlayers" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="width" type="xsd:positiveInteger" use="required"/>
|
||||||
|
<xsd:attribute name="height" type="xsd:positiveInteger" use="required"/>
|
||||||
<xsd:attribute name="imageType" type="xsd:integer" use="required"/>
|
<xsd:attribute name="imageType" type="xsd:integer" use="required"/>
|
||||||
<xsd:attribute name="data" type="xsd:string" use="required"/>
|
<xsd:attribute name="data" type="xsd:string" use="required"/>
|
||||||
</xsd:complexType>
|
</xsd:complexType>
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ Q_OBJECT
|
|||||||
public:
|
public:
|
||||||
explicit Splashes(Game_Data * gd, QObject *parent = 0);
|
explicit Splashes(Game_Data * gd, QObject *parent = 0);
|
||||||
void AddSplash(int srcId);
|
void AddSplash(int srcId);
|
||||||
|
void AddSplash(srcSplashType src,TowerType tw);
|
||||||
void DelSplashById(int Id);
|
void DelSplashById(int Id);
|
||||||
void DelSplash(int index);
|
void DelSplash(int index);
|
||||||
void update();
|
void update();
|
||||||
|
|||||||
31
towers.cpp
31
towers.cpp
@@ -4,9 +4,6 @@ Towers::Towers(Game_Data *gd, QObject *parent) :
|
|||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
gameData = gd;
|
gameData = gd;
|
||||||
Tower tw;
|
|
||||||
for (int i=0; i<gameData->players.size(); i++)
|
|
||||||
gameData->players[i]->srcTowers.push_back(tw);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Towers::AddTower(int playerId, int srcId, QPoint pos)
|
bool Towers::AddTower(int playerId, int srcId, QPoint pos)
|
||||||
@@ -23,7 +20,15 @@ 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;
|
||||||
}
|
}
|
||||||
Tower tw = gameData->players.at(playerId)->srcTowers.at(srcId);
|
TowerType tw;
|
||||||
|
tw.src = srcId;
|
||||||
|
tw.imgType = gameData->players.at(playerId)->srcTowers.at(srcId).imgType;
|
||||||
|
tw.PlayerId = playerId;
|
||||||
|
tw.angle = 0;
|
||||||
|
tw.build = 0;
|
||||||
|
tw.reload = 0;
|
||||||
|
tw.aim = -1;
|
||||||
|
tw .oldAim = -1;
|
||||||
if (gameData->map->addTowerOnMap(playerId,pos))
|
if (gameData->map->addTowerOnMap(playerId,pos))
|
||||||
{
|
{
|
||||||
tw.pos = pos;
|
tw.pos = pos;
|
||||||
@@ -43,5 +48,21 @@ void Towers::DelTower(QPoint pos)
|
|||||||
|
|
||||||
void Towers::update()
|
void Towers::update()
|
||||||
{
|
{
|
||||||
|
for (int i; i<gameData->curTowers.size(); i++)
|
||||||
|
{
|
||||||
|
TowerType tw = gameData->curTowers.values().at(i);
|
||||||
|
srcTowerType stw = gameData->players.at(tw.PlayerId)->srcTowers.at(tw.src);
|
||||||
|
if (tw.build < stw.buildTime)
|
||||||
|
{
|
||||||
|
tw.build++;
|
||||||
|
} else {
|
||||||
|
// TODO: finding aim alien in this place
|
||||||
|
if (tw.reload < stw.reload)
|
||||||
|
{
|
||||||
|
tw.reload++;
|
||||||
|
} else {
|
||||||
|
emit shot(stw.splashes.at(0),tw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
towers.h
2
towers.h
@@ -15,7 +15,7 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
int size() const {return gameData->curTowers.size();}
|
int size() const {return gameData->curTowers.size();}
|
||||||
signals:
|
signals:
|
||||||
//void Shot();
|
void shot(srcSplashType src, TowerType tw);
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user