added morphs, fix some bugs, new images

added onAlienInRadius trigger
but it not work right((
This commit is contained in:
2011-08-21 22:22:02 +04:00
parent fa68b5a120
commit 894e55bb41
186 changed files with 4040 additions and 3022 deletions

View File

@@ -81,22 +81,24 @@ void Splashes::addSplash(SplashType * spl)
case srcTriggerType::onDestination :
tod.src = trig;
spl->trigsOnDest.append(tod);
break;
break;
case srcTriggerType::onAlienInRadius :
toa.src = trig;
spl->trigsOnAlien.append(toa);
break;
break;
case srcTriggerType::onTimer :
tot.src = trig;
tot.timer = 0;
spl->trigsOnTimer.append(tot);
break;
break;
}
}
spl->item = new ADItem(spl->id, ADItem::Splash, spl->src->images);
spl->item->setPos(spl->pos*cellSize);
spl->item->setRotation(spl->angle);
spl->item->setZValue(spl->src->ZValue);
spl->item->setCompositionMode(spl->src->compositionMode);
scene->addItem(spl->item);
gameData->curSplashes.insert(spl->id,*spl);
nextId++;
@@ -115,47 +117,60 @@ void Splashes::update()
deadIndexes.insert(spl->id,spl->id);
if (!spl->trigsOnTimer.isEmpty())
doTriggerOnTimer(spl,&deadIndexes);
if (!spl->trigsOnAlien.isEmpty())
doTriggerOnAlien(spl,&deadIndexes);
float arctg;
float speed = spl->src->speed;
float speed2 = speed*speed;
if (spl->src->autoControl && spl->AlienId != -1)
bool keep = spl->src->keepOnAlien;
if (spl->src->keepOnAlien)
{
bool badAl = false;
if (gameData->aliens->curAliens.contains(spl->AlienId))
spl->destination = gameData->aliens->curAliens.value(spl->AlienId).pos+QPointF(0.5,0.5);
else {
badAl = true;
spl->AlienId = -1;
}
if (distance2(spl->pos, spl->destination) < speed2)
{
if (badAl)
deadIndexes.insert(spl->id,spl->id);
spl->pos = spl->destination;
doTriggerOnDest(spl,&deadIndexes,badAl);
}
arctg = std::atan2(spl->pos.x() - spl->destination.x(),spl->pos.y() - spl->destination.y());
spl->angle = 180.0f*(-arctg)/M_PI;
spl->pos = gameData->aliens->curAliens[spl->AlienId].pos;
spl->angle = gameData->aliens->curAliens[spl->AlienId].angle;
} else deadIndexes.insert(spl->id,spl->id);
} else {
if (!gameData->map->rect().contains(spl->pos.toPoint()))
deadIndexes.insert(spl->id,spl->id);
if (!spl->trigsOnDest.isEmpty())
if (spl->src->autoControl && spl->AlienId != -1)
{
bool badAl = false;
if (gameData->aliens->curAliens.contains(spl->AlienId))
{
spl->destination = gameData->aliens->curAliens.value(spl->AlienId).pos+QPointF(0.5,0.5);
} else {
badAl = true;
spl->AlienId = -1;
keep = false;
}
if (distance2(spl->pos, spl->destination) < speed2)
{
if (badAl)
deadIndexes.insert(spl->id,spl->id);
spl->pos = spl->destination;
doTriggerOnDest(spl,&deadIndexes,true);
doTriggerOnDest(spl,&deadIndexes,badAl);
}
arctg = std::atan2(spl->pos.x() - spl->destination.x(), spl->pos.y() - spl->destination.y());
spl->angle = 180.0f*(-arctg)/M_PI;
} else {
if (!gameData->map->rect().contains(spl->pos.toPoint()))
deadIndexes.insert(spl->id,spl->id);
if (!spl->trigsOnDest.isEmpty())
{
if (distance2(spl->pos, spl->destination) < speed2)
{
spl->pos = spl->destination;
doTriggerOnDest(spl,&deadIndexes,true);
}
}
arctg = -spl->angle*M_PI/180.f;
}
arctg = -spl->angle*M_PI/180.f;
spl->pos.rx() -= speed*std::sin(arctg);
spl->pos.ry() -= speed*std::cos(arctg);
}
spl->pos.rx() -= speed*std::sin(arctg);
spl->pos.ry() -= speed*std::cos(arctg);
/// TODO: smooth splash rotate
spl->item->setPos(spl->pos*cellSize);
spl->item->setRotation(spl->angle);
if (speed == 0) spl->item->next(1.f);
else spl->item->next(speed*cellSize);
spl->item->next(spl->src->animSpeed);
}
for (QHash<int,int>::iterator j = deadIndexes.begin();
j != deadIndexes.end(); ++j)
@@ -187,6 +202,31 @@ void Splashes::doTriggerOnTimer(QHash<int, SplashType>::iterator
if (i->timer >= strig->timer)
{
/// TODO : add damage and other effects
float dmg = strig->damage;
float rad = strig->radius;
if (dmg > 0)
{
float hh;
if (!(rad > 0))
{
if (gameData->aliens->curAliens.contains(spl->AlienId))
{
hh = gameData->aliens->curAliens[spl->AlienId].health -= dmg;
if (hh <= 0) dead.insert(spl->AlienId, DeadAlienIndex(spl->AlienId, spl->PlayerId));
}
} else {
for (QHash<int, AlienType>::iterator
a = gameData->aliens->curAliens.begin();
a != gameData->aliens->curAliens.end(); ++a)
{
if (distance2(spl->pos, a->pos) < rad*rad)
{
hh = a->health -= dmg;
if (hh <= 0) dead.insert(a->id, DeadAlienIndex(a->id, spl->PlayerId));
}
}
}
}
i->timer = 0;
if (strig->delParent) deadIndexes->insert(spl->id,spl->id);
if (strig->count > 0 && strig->childId > 0)
@@ -221,9 +261,13 @@ void Splashes::doTriggerOnDest(QHash<int, SplashType>::iterator
int aim;
switch(t.src->childAim)
{
case srcTriggerType::parentAim : aim = spl->AlienId; break;
case srcTriggerType::parentAim :
aim = spl->AlienId;
break;
/// TODO : other aim types
case srcTriggerType::noAim : aim = -1; break;
case srcTriggerType::nearestAlien :
case srcTriggerType::noAim :
default : aim = -1;
}
if (t.src->count > 0 && t.src->childId > 0)
@@ -262,3 +306,42 @@ void Splashes::doTriggerOnDest(QHash<int, SplashType>::iterator
}
}
}
void Splashes::doTriggerOnAlien(QHash<int, SplashType>::iterator spl, QHash<int, int> *deadIndexes)
{
foreach(TriggerOnAlien t, spl->trigsOnAlien)
{
/// TODO: different aims for childs
if (t.src->delParent) deadIndexes->insert(spl->id,spl->id);
float dmg = t.src->damage;
float rad = t.src->radius;
if (dmg > 0 && rad > 0)
{
float hh;
for (QHash<int, AlienType>::iterator
i = gameData->aliens->curAliens.begin();
i != gameData->aliens->curAliens.end(); ++i)
{
if (distance2(spl->pos, i->pos) < rad*rad)
{
hh = i->health -= dmg;
if (hh <= 0) dead.insert(i->id, DeadAlienIndex(i->id, spl->PlayerId));
if (t.src->count > 0 && t.src->childId > 0)
{
if (!t.triggerAliens.contains(i->id))
{
for (int j=0; j<t.src->count; ++j)
{
/// TODO: randomRadiusPos
addSplash(spl->srcTow,t.src->childId,
spl->pos,i->pos,i->id,spl->towerId);
}
t.triggerAliens.append(i->id);
}
}
}
}
}
}
}