Hi All,
I'm doing space invadres clone game, and when I tried to record the game using camcoder, the collision detection between bullets and the invaders are droped and it's not behaving correctly i.e some bullets can hit invaders that shouldn't be hit, because there are in-front other invaders.
The collision detection is here:
void CheckBulletsInvadersCollision(Ship *ship)
{
for (vector<Invader*>::iterator invIter = g_Invaders.invaders->begin(); invIter != g_Invaders.invaders->end();)
{
if ((*invIter)->Alive)
{
bool isBulletsInvaderCollided = false;
for (list<Bullet*>::iterator it = ship->Bullets->begin(); it != ship->Bullets->end();)
{
float left = (*it)->Position.x - 5;
float top = (*it)->Position.y - 13;
if (CheckCollision(left, top, (*invIter)->AlienSprite->m_X, (*invIter)->AlienSprite->GetImage()->GetWidth() / 4
, (*invIter)->AlienSprite->m_Y, (*invIter)->AlienSprite->GetImage()->GetHeight() / 4))
{
isBulletsInvaderCollided = true;
Bullet *bullet = *it;
it = ship->Bullets->erase(it);
delete bullet;
ship->Canfire = true;
}
else
{
it++;
}
}
if (isBulletsInvaderCollided)
{
Invader *inv = *invIter;
g_Invaders.invaders->erase(invIter);
delete inv;
g_Invaders.killed++;
g_Invaders.alive = false;
}
else
{
invIter++;
}
}
}
}