Mine.cpp
上传用户:royluo
上传日期:2007-01-05
资源大小:1584k
文件大小:3k
源码类别:

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   Mine.cpp                                                            
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Module description: Implements the mine game object.
  11. *                       
  12. *                                                                             
  13. *   Authors: Eran Yariv - 28484475                                           
  14. *            Moshe Zur  - 24070856                                           
  15. *                                                                            
  16. *                                                                            
  17. *   Date: 23/09/98                                                           
  18. *                                                                            
  19. ******************************************************************************/
  20. #include <stdafx.h>
  21. #include <Mine.h>
  22. #include <Tanks.h>
  23. CMine::CMine (UINT uXPos, UINT uYPos) :
  24.     CExplodingGameObject (uXPos, uYPos, MINE_WIDTH, MINE_HEIGHT,
  25.                           MINE_INTENSITY, CImageManager::IMG_SHELL_EXPLODE),
  26.     m_dwStartTime (0)
  27. {
  28.     m_himgNormal = m_GlobalImageManager.GetImage (CImageManager::IMG_MINE);
  29.     m_pCurImage = &m_himgNormal;
  30. }
  31. StateType CMine::CalcState (DWORD dwCurTime)
  32. {
  33.     m_bImageChanged = FALSE;    // Assume no change since last CalcState
  34.     if (m_dwStartTime == 0) // Start time not set yet
  35.         m_dwStartTime = dwCurTime;
  36.     if ((dwCurTime - m_dwStartTime) >= MINE_EXPIRATION ||   // Mine expires (time-out)
  37.         IsExplosionOver())                                  // Mine is exploding and after its last frame
  38.     {
  39.         return STATE_DEAD;
  40.     }
  41.     else 
  42.     {
  43.         return STATE_ALIVE;
  44.     }
  45. }
  46. CReaction 
  47. CMine::React(CGameObject *pTo)
  48. {
  49.     if ((pTo->GetType() != TANK && pTo->GetType() != MINE) ||   // We react only to tanks and mines !
  50.         !CollidesWith (pTo))                                    // We react only on collision !
  51.         return CReaction(); // No reaction
  52.         // New mines that collides with us are blocked :
  53.     if (pTo->GetType() == MINE)
  54.         return CReaction (0, TERR_BLOCKED, BONUS_NONE);
  55.         // Now we know a tank hits us !!!
  56.     UINT uTankID = pTo->GetID();
  57.     if (CheckAndSetTankNotification(uTankID))
  58.             // We already exploded on this tank before
  59.         return CReaction(); // No reaction
  60.     // OK - this is a new tank !!!
  61.     Explode ();
  62.         // Play sound
  63.     TANKS_APP->m_gSoundManager.Play(CSoundManager::MINE_EXPLODE);
  64.     return CReaction (m_uMaxIntensity);
  65. }