void Swarm::updateSwarm(real dt, SwarmNode* next, BaseObj& collision, std::vector<Bullet*> bulletList) { if (next->data.m_bAlive) { XMVECTOR pos = XMLoadFloat3(&next->data.m_vPos); XMVECTOR playerTarget = XMLoadFloat3(&m_pLead->data.m_vTarget); XMVECTOR distance = XMVector3Length(pos - playerTarget); if (XMVectorGetX(distance) < 120.0f || XMVectorGetY(distance) < 120.0f || false == m_pLead->data.m_bAlive) next->data.m_vTarget = m_pLead->data.m_vTarget; else next->data.m_vTarget = next->parent->data.m_vPos; // check if we hit the player next->data.update(dt); next->data.checkCollision(collision); if (next->data.m_bHit) next->data.reduceHealth(collision.getDamage()); if (next->data.m_fLife < 0.0f) { dynamic_cast<Player&>(collision).increasePoints(5.0f); collision.reduceHealth(next->data.m_fDamage); next->data.m_bAlive = false; //collision.increasePoints(20.0f); } // check if a bullet hit the alien for (unsigned int i = 0; i < bulletList.size(); ++i) { next->data.checkCollision(*bulletList[i]); if (next->data.m_bHit && next->data.m_bAlive) { next->data.reduceHealth(bulletList[i]->getDamage()); bulletList[i]->setState(Bullet::BState_Hit); } if (next->data.m_fLife < 0.0f) { dynamic_cast<Player&>(collision).increasePoints(25.0f); next->data.m_bAlive = false; } } } if (next->ltChild) updateSwarm(dt, next->ltChild, collision, bulletList); if (next->rtChild) updateSwarm(dt, next->rtChild, collision, bulletList); }
void Swarm::updateSwarm(Fugui::real dt, BaseObj& collision, std::vector<Bullet*> bulletList) { if (m_pLead) { if (m_pLead->data.m_bAlive) { m_pLead->data.update(dt); m_pLead->data.checkCollision(collision); if (m_pLead->data.m_bHit) m_pLead->data.m_fLife -= collision.getDamage(); if (m_pLead->data.m_fLife < 0.0f) { dynamic_cast<Player&>(collision).increasePoints(5.0f); m_pLead->data.m_bAlive = false; //collision.increasePoints(20.0f); } } // check if a bullet hit the alien for (unsigned int i = 0; i < bulletList.size(); ++i) { m_pLead->data.checkCollision(*bulletList[i]); if (m_pLead->data.m_bHit && m_pLead->data.m_bAlive) { m_pLead->data.reduceHealth(bulletList[i]->getDamage()); bulletList[i]->setState(Bullet::BState_Hit); } if (m_pLead->data.m_fLife < 0.0f) { dynamic_cast<Player&>(collision).increasePoints(25.0f); m_pLead->data.m_bAlive = false; } } if (m_pLead->ltChild) updateSwarm(dt, m_pLead->ltChild, collision, bulletList); if (m_pLead->rtChild) updateSwarm(dt, m_pLead->rtChild, collision, bulletList); } }