add loader
add schema new loader model using xml separated work and load data validation using schema map data in xml new core model... proecting
This commit is contained in:
48
aliens.cpp
48
aliens.cpp
@@ -7,17 +7,16 @@ Aliens::Aliens(Game_Data *gd, QObject *parent) :
|
||||
{
|
||||
gameData = gd;
|
||||
nextId = 0;
|
||||
Alien al;
|
||||
al.speed = 0.1f;
|
||||
al.health = 10;
|
||||
al.type = 0;
|
||||
gameData->srcAliens.push_back(al);
|
||||
}
|
||||
|
||||
|
||||
void Aliens::AddAlien(int srcId)
|
||||
{
|
||||
if (srcId < 0 || srcId >= gameData->srcAliens.size()) qDebug("ERROR out of aliens range"),exit(-1);
|
||||
if (srcId < 0 || srcId >= gameData->srcAliens.size())
|
||||
{
|
||||
qCritical("ERROR out of aliens range");
|
||||
return;
|
||||
}
|
||||
Alien al = gameData->srcAliens.at(srcId);
|
||||
al.Id = nextId;
|
||||
al.finish = gameData->map->finishs.at(qrand()%gameData->map->finishs.size());
|
||||
@@ -25,21 +24,21 @@ void Aliens::AddAlien(int srcId)
|
||||
al.pos = QPointF(gameData->map->starts.at(qrand()%gameData->map->starts.size()));
|
||||
al.path = gameData->map->CreatePath(al.pos.toPoint(),al.finish);
|
||||
al.pathIndex = 1;
|
||||
if (al.path.isEmpty()) qDebug("ERROR create path"),exit(-1);
|
||||
if (al.path.isEmpty()) qFatal("ERROR create path");
|
||||
qDebug() << al.path;
|
||||
gameData->map->printMap();
|
||||
//gameData->map->printMap();
|
||||
gameData->curAliens.insert(al.Id,al);
|
||||
nextId++;
|
||||
gameData->curAliens.push_back(al);
|
||||
}
|
||||
|
||||
|
||||
void Aliens::retrace(bool *OK)
|
||||
{
|
||||
qDebug("retarce!");
|
||||
qDebug("re-trace!");
|
||||
gameData->map->removeAliensPath();
|
||||
for (int i=0; i<gameData->curAliens.size(); i++)
|
||||
{
|
||||
Alien al = gameData->curAliens.at(i);
|
||||
Alien al = gameData->curAliens.take(i);
|
||||
al.path = gameData->map->CreatePath(al.pos.toPoint(),al.finish);
|
||||
al.pathIndex = 1;
|
||||
if (al.path.isEmpty()) *OK = false;
|
||||
@@ -47,33 +46,18 @@ void Aliens::retrace(bool *OK)
|
||||
}
|
||||
|
||||
|
||||
void Aliens::DelAlien(int index)
|
||||
void Aliens::DelAlien(int Id)
|
||||
{
|
||||
gameData->curAliens.remove(index);
|
||||
}
|
||||
|
||||
|
||||
void Aliens::DelAlienById(int Id)
|
||||
{
|
||||
DelAlien(AlienIndex(Id));
|
||||
}
|
||||
|
||||
|
||||
int Aliens::AlienIndex(int alienId)
|
||||
{
|
||||
int i=-1;
|
||||
for (i=0; i<gameData->curAliens.size(); i++)
|
||||
if (gameData->curAliens.at(i).Id==alienId) return i;
|
||||
return i;
|
||||
gameData->curAliens.remove(Id);
|
||||
}
|
||||
|
||||
|
||||
void Aliens::update()
|
||||
{
|
||||
QVector <int> missIndex;
|
||||
QList <int> missIndex;
|
||||
for (int i=0; i<gameData->curAliens.size(); i++)
|
||||
{
|
||||
Alien al = gameData->curAliens.at(i);
|
||||
Alien al = gameData->curAliens.values().at(i);
|
||||
//qDebug() << i;
|
||||
//if (al.health < 0) emit AlienKill();
|
||||
float tmpdx,tmpdy,angl,arctg = 0;
|
||||
@@ -117,11 +101,11 @@ void Aliens::update()
|
||||
al.pos.setY(al.pos.y()
|
||||
-al.speed*std::cos(arctg));
|
||||
//return true;
|
||||
gameData->curAliens[i] = al;
|
||||
gameData->curAliens[al.Id] = al;
|
||||
}
|
||||
for (int j=0; j<missIndex.size(); j++)
|
||||
{
|
||||
gameData->missingAliens++;
|
||||
DelAlienById(missIndex.at(j));
|
||||
DelAlien(missIndex.at(j));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user