calculate tower angle

switch autocontrol for splashes
This commit is contained in:
root
2010-08-30 16:40:40 +04:00
parent 13f8040f4e
commit 3e6460abd4
5 changed files with 272 additions and 141 deletions

View File

@@ -58,7 +58,7 @@ void Splashes::addSplash(srcSplashType src, int index, TowerType tw)
spl.AlienId = tw.aim;
else
spl.AlienId = -1;
spl.angle = tw.angle;
spl.angle = tw.angle; // FIXME: tower not rotate
spl.pos = tw.pos; // FIXME: pos not in center or left-angle of tower
spl.imgType = src.imgType;
spl.life = 0;
@@ -80,7 +80,7 @@ void Splashes::update()
QList <int> deadIndexes;
for (int i=0; i<gameData->curSplashes.size(); i++)
{
int curDead = -1;
//int curDead = -1;
float arctg,angl;
SplashType spl = gameData->curSplashes.values().at(i);
//bool isTowerSplash = false;
@@ -90,46 +90,39 @@ void Splashes::update()
src = gameData->players.at(tw.PlayerId)->srcTowers.at(tw.src).splashes.at(spl.src);
spl.life++;
if (spl.life > src.lifetime)
{
deadIndexes.append(spl.id);
curDead = spl.id;
}
//isTowerSplash = true;
//if (!isTowerSplash)
// src = gameData->srcSplashes.at(spl.src);
if (distance2(spl.pos, spl.destination) < src.speed*src.speed)
{
deadIndexes.push_back(spl.id);
curDead = spl.id;
}
if (curDead < 0)
{
if (src.autoControl)
{
if (distance2(spl.pos, spl.destination) < src.speed*src.speed)
deadIndexes.push_back(spl.id);
if (gameData->curAliens.contains(spl.AlienId))
spl.destination = gameData->curAliens.value(spl.AlienId).pos;
arctg = std::atan2(spl.pos.x() - spl.destination.x(),spl.pos.y() - spl.destination.y());
//if (tmpdy < 0) arctg=arctg+M_PI;
angl = 180.0f*(-arctg)/M_PI;
spl.angle = angl;
spl.pos.setX(spl.pos.x()
-src.speed*std::sin(arctg));
spl.pos.setY(spl.pos.y()
-src.speed*std::cos(arctg));
} else {
if (!gameData->map->rect().contains(spl.pos.toPoint()))
deadIndexes.push_back(spl.id);
spl.pos.setX(spl.pos.x()
-src.speed*std::sin(-spl.angle*M_PI/180.f));
spl.pos.setY(spl.pos.y()
-src.speed*std::cos(-spl.angle*M_PI/180.f));
}
arctg = std::atan2(spl.pos.x() - spl.destination.x(),spl.pos.y() - spl.destination.y());
//if (tmpdy < 0) arctg=arctg+M_PI;
angl = 180.0f*(-arctg)/M_PI;
spl.angle = angl;
spl.pos.setX(spl.pos.x()
-src.speed*std::sin(arctg));
spl.pos.setY(spl.pos.y()
-src.speed*std::cos(arctg));
}
// TODO: smooth splash rotate
// TODO: activate trigger and more...
gameData->curSplashes.insert(spl.id,spl);
}
for (int j=0; j<deadIndexes.size(); j++)
//delAlien(missIndex.at(j));
delSplash(deadIndexes.at(j));
}