Checking collision of bullets and Asteroids
Posted
by
Moaz ELdeen
on Game Development
See other posts from Game Development
or by Moaz ELdeen
Published on 2012-09-01T01:11:32Z
Indexed on
2012/09/01
3:50 UTC
Read the original article
Hit count: 193
c++
|collision-detection
I'm trying to detect collision between two list of bullets and asteroids. The code works fine, but when the bullet intersects with an asteroid, and that bullet passes through another asteroid, the code gives an assertion, and it says about it can't increment the iterator. I'm sure there is a small bug in that code, but I can't find it.
for (list<Bullet>::iterator itr_bullet = ship.m_Bullets.begin();
itr_bullet!=ship.m_Bullets.end();)
{
for (list<Asteroid>::iterator itr_astroid = asteroids.begin();
itr_astroid!=asteroids.end();
itr_astroid++)
{
if(checkCollision(itr_bullet->getCenter(),itr_astroid->getCenter(),
itr_bullet->getRadius(), itr_astroid->getRadius()))
{
itr_astroid = asteroids.erase(itr_astroid);
}
}
itr_bullet++;
}
© Game Development or respective owner