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

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   Bomb.cpp                                                            
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Module description: Implements the bomb 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 <Bomb.h>
  22. #include <TankObj.h>
  23. CBomb::CBomb (CPoint& Origin, UINT uDirectionIndex) :
  24.     CMovingGameObject (         Origin.x, Origin.y,
  25.                                 BOMB_WIDTH, BOMB_HEIGHT, 
  26.                                 uDirectionIndex, 
  27.                                 BOMB_SPEED),
  28.     CExplodingGameObject (      Origin.x, Origin.y,
  29.                                 BOMB_WIDTH, BOMB_HEIGHT,
  30.                                 BOMB_INTENSITY,
  31.                                 CImageManager::IMG_SHELL_EXPLODE),   // TODO: replace(?)
  32.     m_Origin(Origin)
  33. {
  34.     m_himgBomb = m_GlobalImageManager.GetImage (CImageManager::IMG_BOMB);
  35.     m_pCurImage = &m_himgBomb; // Override explosion image as current image
  36. }
  37. StateType 
  38. CBomb::CalcState (DWORD dwCurTime)
  39. {
  40.     m_bImageChanged = FALSE;    // Assume no change since last CalcState
  41.     if (m_bIsExploding)
  42.     {
  43.         if (IsExplosionOver()) // Bomb is exploding and after its last frame
  44.         {
  45.             return STATE_DEAD;
  46.         }
  47.         else 
  48.         {
  49.             return STATE_ALIVE;
  50.         }
  51.     }
  52.     // We're flying high, we're flying high right to the sky......
  53.     // Try to advance...
  54.     int iDistSqr = CalcNewPos (dwCurTime, FALSE);
  55.     if (iDistSqr < 0) 
  56.     {   // Out of map situation
  57.         return STATE_DEAD;
  58.     }
  59.     if (m_GlobalImageManager.ImageEnded (m_himgBomb))
  60.     {
  61.         // Bomb hit's the ground
  62.         Explode ();
  63.     }
  64.     return STATE_ALIVE;
  65. }
  66.         
  67. CReaction
  68. CBomb::React(CGameObject *pTo)
  69. {
  70.     if (!m_bIsExploding ||          // We don't react until we explode
  71.         pTo->GetType() != TANK)     // We react only to tanks !
  72.     {
  73.         return CReaction(); // No reaction
  74.     }
  75.     UINT uTankID = pTo->GetID();
  76.     if (CheckAndSetTankNotification(uTankID))
  77.             // We already exploded on this tank before
  78.         return CReaction(); // No reaction
  79.         // OK, this is a tank and it is the first time we explode on it ....
  80.     return CReaction (CalcRelativeExplosionIntensity (pTo, MIN_BOMB_RADIUS, MAX_BOMB_RADIUS));
  81. }