towers_is_shot

This commit is contained in:
unknown
2010-08-29 14:41:27 +04:00
parent 8f9294c405
commit 26439849c8
18 changed files with 1767 additions and 2460 deletions

View File

@@ -23,6 +23,7 @@ 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;
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");
//qDebug() << al.path;
@@ -59,33 +60,35 @@ void Aliens::update()
QList <int> missIndex;
for (QHash<int, AlienType>::iterator i = gameData->curAliens.begin(); i != gameData->curAliens.end(); ++i)
{
AlienType al = (*i);
//AlienType al = (*i);
//qDebug() << i;
//if (al.health < 0) emit AlienKill();
float tmpdx,tmpdy,angl,arctg = 0;
tmpdx = (*i).pos.x() - (*i).path.at((*i).pathIndex).x();
tmpdy = (*i).pos.y() - (*i).path.at((*i).pathIndex).y();
while (std::sqrt(tmpdx*tmpdx +tmpdy*tmpdy) < 2*(*i).speed)
float angl,arctg = 0;
int curMiss = -1;
while (distance2((*i).pos, (*i).path.at((*i).pathIndex)) < (*i).speed*(*i).speed)
{
(*i).pathIndex++;
if ((*i).pathIndex >= (*i).path.size())
{
qDebug() << tr("Missing aliens = %1!").arg(gameData->missingAliens);
missIndex.push_back((*i).id);
curMiss = (*i).id;
break;
}
/*{
PathIndex = 0;
position = game->start*game->cellsize;
}*/
tmpdx = (*i).pos.x() - (*i).path.at((*i).pathIndex).x();
tmpdy = (*i).pos.y() - (*i).path.at((*i).pathIndex).y();
// tmpdx = (*i).pos.x() - (*i).path.at((*i).pathIndex).x();
// tmpdy = (*i).pos.y() - (*i).path.at((*i).pathIndex).y();
//qDebug() << "next";
}
arctg = std::atan2(tmpdx,tmpdy);
//if (tmpdy < 0) arctg=arctg+M_PI;
angl = 180.0f*(-arctg)/M_PI;
/*if (PathIndex > 1)
if (curMiss < 0)
{
arctg = std::atan2((*i).pos.x() - (*i).path.at((*i).pathIndex).x(),(*i).pos.y() - (*i).path.at((*i).pathIndex).y());
//if (tmpdy < 0) arctg=arctg+M_PI;
angl = 180.0f*(-arctg)/M_PI;
/*if (PathIndex > 1)
{
if ((Position.angle-angl < -5 || Position.angle-angl > 5) && angl < 175 && angl > -175)
{
@@ -95,15 +98,16 @@ void Aliens::update()
else Position.angle = angl;
}
else*/
(*i).angle = angl;
//qDebug() << "[" << PathIndex << ";" << PicIndex << "]" << "angle:" << Position.angle << "arctg:" << arctg << "Pos:" << Position.pnt;
(*i).pos.setX((*i).pos.x()
-(*i).speed*std::sin(arctg));
(*i).pos.setY((*i).pos.y()
-(*i).speed*std::cos(arctg));
//return true;
//gameData->curAliens.insert(al.id,al);
//qDebug() <<"alien"<< i << " path index=" << al.pathIndex << ", pos=" << al.pos;
(*i).angle = angl;
//qDebug() << "[" << PathIndex << ";" << PicIndex << "]" << "angle:" << Position.angle << "arctg:" << arctg << "Pos:" << Position.pnt;
(*i).pos.setX((*i).pos.x()
-(*i).speed*std::sin(arctg));
(*i).pos.setY((*i).pos.y()
-(*i).speed*std::cos(arctg));
//return true;
//gameData->curAliens.insert(al.id,al);
//qDebug() <<"alien"<< i << " path index=" << al.pathIndex << ", pos=" << al.pos;
}
}
for (int j=0; j<missIndex.size(); j++)
{