Facebook
From Putrid Tern, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 129
  1.  
  2. void GameEngine::UpdateSprites(bool** map, int x)
  3. {
  4.         // Update the sprites in the sprite vector
  5.         RECT          rcOldSpritePos;
  6.         SPRITEACTION  saSpriteAction;
  7.         vector<Sprite*>::iterator siSprite;
  8.         for (siSprite = m_vSprites.begin(); siSprite != m_vSprites.end(); siSprite++)
  9.         {
  10.                 // Save the old sprite position in case we need to restore it
  11.                 rcOldSpritePos = (*siSprite)->GetPosition();
  12.                 //sprite lara x'in modu eklenmeli
  13.                 bool top        = map[(( rcOldSpritePos.right - x % 40) / 40)+3 ][(rcOldSpritePos.top )/ 40] || map[((rcOldSpritePos.left - x % 40) / 40) + 1][(rcOldSpritePos.top) / 40];     // works both ai and player characters
  14.                 bool bottom = map[((rcOldSpritePos.right - x % 40) / 40) +3][(rcOldSpritePos.bottom) / 40] || map[((rcOldSpritePos.left - x % 40) / 40) + 1][(rcOldSpritePos.bottom) / 40];     // works both ai and player characters
  15.  
  16.                 bool right = map[(( rcOldSpritePos.right - x % 40) / 40)+3 ] [(((rcOldSpritePos.top + rcOldSpritePos.bottom) / 2)) / 40]; // for moving enemies
  17.                 bool left  = map[(( rcOldSpritePos.left  - x % 40) / 40)+3] [(((rcOldSpritePos.top + rcOldSpritePos.bottom) / 2)) / 40];        // does not work for player character
  18.                
  19.                 // Update the sprite
  20.                 // Update the sprite
  21.                 saSpriteAction = (*siSprite)->Update(top, bottom, right, left);
  22.  
  23.                 // Handle the SA_KILL sprite action
  24.                 if (saSpriteAction & SA_KILL)
  25.                 {
  26.                         delete (*siSprite);
  27.                         m_vSprites.erase(siSprite);
  28.                         siSprite--;
  29.                         continue;
  30.                 }
  31.  
  32.                 // See if the sprite collided with any others
  33.                 if (CheckSpriteCollision(*siSprite))
  34.                         // Restore the old sprite position
  35.                         (*siSprite)->SetPosition(rcOldSpritePos);
  36.                
  37.         }
  38. }
  39.