void GameEngine::UpdateSprites()
{
  // Update the sprites in the sprite vector
  RECT          rcOldSpritePos;
  SPRITEACTION  saSpriteAction;
  vector<Sprite*>::iterator siSprite;
  for (siSprite = m_vSprites.begin(); siSprite != m_vSprites.end();)
  {
    // Save the old sprite position in case we need to restore it
    rcOldSpritePos = (*siSprite)->GetPosition();

    // Update the sprite
    saSpriteAction = (*siSprite)->Update();

	// See if the sprite collided with any others
    if (CheckSpriteCollision(*siSprite))
     // Restore the old sprite position
      (*siSprite)->SetPosition(rcOldSpritePos);

    // Handle the SA_KILL sprite action
    if (saSpriteAction & SA_KILL)
    {
      // Notify the game that the sprite is dying
      SpriteDying(*siSprite);
	  siSprite = m_vSprites.erase(siSprite);
	}
	else
	{
		++siSprite;
	}
  }
}
Ejemplo n.º 2
0
void GameEngine::UpdateSprites()
{
	//Update the sprites in the sprite vector
	RECT			rcOldSpritePos;
	SPRITEACTION	saSpriteAction;
	vector<Sprite*>::iterator siSprite;
	siSprite = m_vSprites.begin(); 
	while (siSprite != m_vSprites.end())
	{
		//Save the old sprite position in case we need to restore it
		rcOldSpritePos = (*siSprite)->GetPosition();

		//Update the sprite
		saSpriteAction = (*siSprite)->Update();

		//Handle the SA_ADDSPRITE sprite action
		if (saSpriteAction & SA_ADDSPRITE)
			//Allow the sprite to add its sprite
			AddSprite((*siSprite)->AddSprite());

		//Handle the SA_KILL sprite action
		if (saSpriteAction & SA_KILL)
		{
			//Notify the game that the sprite is dying
			SpriteDying(*siSprite);

			siSprite = m_vSprites.erase(siSprite);
			continue;
		}

		//See if the sprite collided with any others
		if (CheckSpriteCollision(*siSprite))
			//Restore old sprite position
			(*siSprite)->SetPosition(rcOldSpritePos);

		if (siSprite == m_vSprites.end() || m_vSprites.size() == 0)
		{
			break;
		}
			++siSprite;
	}
}