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

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   Shell.cpp                                                            
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Module description: Implements the shell 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 <Shell.h>
  22. #include <TankObj.h>
  23. #include <SoundManager.h>
  24. CShell::CShell (UINT uXPos, UINT uYPos, UINT uDirectionIndex, UINT uParentTankID) :
  25.     CMovingGameObject (         uXPos, uYPos,
  26.                                 SHELL_WIDTH, SHELL_HEIGHT, 
  27.                                 uDirectionIndex, 
  28.                                 SHELL_SPEED),
  29.     CExplodingGameObject (      uXPos, uYPos,
  30.                                 SHELL_WIDTH, SHELL_HEIGHT,
  31.                                 SHELL_INTENSITY,
  32.                                 CImageManager::IMG_SHELL_EXPLODE),
  33.     m_uParentTankID (uParentTankID)
  34. {
  35.     m_himgShell = m_GlobalImageManager.GetImage (CImageManager::IMG_SHELL);
  36.     m_GlobalImageManager.RotateImage (m_himgShell, uDirectionIndex);
  37.     m_pCurImage = &m_himgShell; // Ovverride explosion image as current image
  38. }
  39. StateType 
  40. CShell::CalcState (DWORD dwCurTime)
  41. {
  42.     m_bImageChanged = FALSE;    // Assume no change since last CalcState
  43.     if (m_bIsExploding)
  44.     {
  45.         if (IsExplosionOver()) // Shell is exploding and after its last frame
  46.         {
  47.             return STATE_DEAD;
  48.         }
  49.         else 
  50.         {
  51.             return STATE_ALIVE;
  52.         }
  53.     }
  54.     // We're flying high, we're flying high right to the sky......
  55.     // Try to advance...
  56.     int iDistSqr = CalcNewPos (dwCurTime);
  57.     if (iDistSqr < 0) 
  58.     {   // Out of map situation
  59.         return STATE_DEAD;
  60.     }
  61.     // See what the rest of the world thinks about our movement
  62.     CReaction react = m_GlobalObjsList.GetGameReaction (this);
  63.     TerrainType ter = react.GetTerrainDifficulty();
  64.     if ((ter < TERR_BLOCKED) ||  
  65.             // Cool - didn't hit a thing or ...
  66.         ((HIT_TANK == ter) && (react.GetTankID() == m_uParentTankID)))
  67.             // Hit a tank but it's our father
  68.     {
  69.         
  70.         m_bImageChanged = TRUE;
  71.         return STATE_ALIVE;
  72.     }
  73.         // Now we're either hitting a wall or a tank !!
  74.     Explode ();
  75.         // Play the explosion sound
  76.     TANKS_APP->m_gSoundManager.Play(CSoundManager::SHELL_EXPLODE);
  77.     return STATE_ALIVE;
  78. }
  79.         
  80. CReaction
  81. CShell::React(CGameObject *pTo)
  82. {
  83.     if (!m_bIsExploding ||          // We don't react until we explode
  84.         pTo->GetType() != TANK)     // We react only to tanks !
  85.     {
  86.         return CReaction(); // No reaction
  87.     }
  88.     UINT uTankID = pTo->GetID();
  89.     if (CheckAndSetTankNotification(uTankID))
  90.             // We already exploded on this tank before
  91.         return CReaction(); // No reaction
  92.         // OK, this is a tank and it is the first time we explode on it ....
  93.     return CReaction (CalcRelativeExplosionIntensity (pTo, MIN_SHELL_RADIUS, MAX_SHELL_RADIUS));
  94. }