which is important because it detects when a
which is important because it detects when a game ends. Listing 24.2 contains the code for the SpriteCollision() function. Listing 24.2 The SpriteCollision() Function Updates the High Score List Whenever a Game Ends 1: BOOL SpriteCollision(Sprite* pSpriteHitter, Sprite* pSpriteHittee) 2: { 3: // See if a player missile and an alien have collided 4: Bitmap* pHitter = pSpriteHitter->GetBitmap(); 5: Bitmap* pHittee = pSpriteHittee->GetBitmap(); 6: if ((pHitter == _pMissileBitmap && (pHittee == _pBlobboBitmap || 7: pHittee == _pJellyBitmap || pHittee == _pTimmyBitmap)) || 8: (pHittee == _pMissileBitmap && (pHitter == _pBlobboBitmap || 9: pHitter == _pJellyBitmap || pHitter == _pTimmyBitmap))) 10: { 11: // Play the small explosion sound 12: PlaySound((LPCSTR)IDW_LGEXPLODE, _hInstance, SND_ASYNC | 13: SND_RESOURCE); 14: 15: // Kill both sprites 16: pSpriteHitter->Kill(); 17: pSpriteHittee->Kill(); 18: 19: // Create a large explosion sprite at the alien’s position 20: RECT rcBounds = { 0, 0, 600, 450 }; 21: RECT rcPos; 22: if (pHitter == _pMissileBitmap) 23: rcPos = pSpriteHittee->GetPosition(); 24: else 25: rcPos = pSpriteHitter->GetPosition(); 26: Sprite* pSprite = new Sprite(_pLgExplosionBitmap, rcBounds); 27: pSprite->SetNumFrames(8, TRUE); 28: pSprite->SetPosition(rcPos.left, rcPos.top); 29: _pGame->AddSprite(pSprite); 30: 31: // Update the score 32: _iScore += 25; 33: _iDifficulty = max(80 - (_iScore / 20), 20); 34: } 35: 36: // See if an alien missile has collided with the car 37: if ((pHitter == _pCarBitmap && (pHittee == _pBMissileBitmap || 38: pHittee == _pJMissileBitmap || pHittee == _pTMissileBitmap)) || 39: (pHittee == _pCarBitmap && (pHitter == _pBMissileBitmap || 40: pHitter == _pJMissileBitmap || pHitter == _pTMissileBitmap))) 41: { 42: // Play the large explosion sound 43: PlaySound((LPCSTR)IDW_LGEXPLODE, _hInstance, SND_ASYNC | 44: SND_RESOURCE); 45: 46: // Kill the missile sprite 47: if (pHitter == _pCarBitmap) 48: pSpriteHittee->Kill(); 49: else 50: pSpriteHitter->Kill(); 51: 52: // Create a large explosion sprite at the car’s position 53: RECT rcBounds = { 0, 0, 600, 480 }; 54: RECT rcPos; 55: if (pHitter == _pCarBitmap) 56: rcPos = pSpriteHitter->GetPosition(); 57: else 58: rcPos = pSpriteHittee->GetPosition(); 59: Sprite* pSprite = new Sprite(_pLgExplosionBitmap, rcBounds); 60: pSprite->SetNumFrames(8, TRUE); 61: pSprite->SetPosition(rcPos.left, rcPos.top); 62: _pGame->AddSprite(pSprite); 63:
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Cheap Web Hosting services