Save Zone Implementation in Asteroids

Posted by Moaz on Game Development See other posts from Game Development or by Moaz
Published on 2012-11-02T16:18:26Z Indexed on 2012/11/02 17:33 UTC
Read the original article Hit count: 218

Filed under:
|
|

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++;
            }
        }

© Game Development or respective owner

Related posts about c++

Related posts about opengl