Save Zone Implementation in Asteroids
- by Moaz
I would like to implement a safe zone for asteroids so that when the ship gets destroyed, it shouldn't be there unless it is safe from other asteroids.
I tried to check the distance between each asteroid and the ship, and if it is above threshold, it sets a flag to the ship that's a safe zone, but sometimes it work and sometimes it doesn't
for (list<Asteroid>::iterator itr_astroid = asteroids.begin(); itr_astroid!=asteroids.end(); )
{
if(currentShip.m_state == Ship::Ship_Dead)
{
float distance = itr_astroid->getCenter().distance(Vec2f(getWindowWidth()/2,getWindowHeight()/2));
if( distance>200)
{
currentShip.m_saveField = true;
break;
}
else
{
currentShip.m_saveField = false;
itr_astroid++;
}
}
else
{
itr_astroid++;
}
}