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

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   SheildStatus.cpp
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Module description: Implements the shield status object that is displayed
  11. *                       in the main dialog.
  12. *                       
  13. *                                                                             
  14. *   Authors: Eran Yariv - 28484475                                           
  15. *            Moshe Zur  - 24070856                                           
  16. *                                                                            
  17. *                                                                            
  18. *   Date: 23/09/98                                                           
  19. *                                                                            
  20. ******************************************************************************/
  21. #include "stdafx.h"
  22. #include "Tanks.h"
  23. #include "ShieldStatus.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. BEGIN_MESSAGE_MAP(CShieldStatus, CButton)
  30. //{{AFX_MSG_MAP(CShieldStatus)
  31. ON_WM_QUERYNEWPALETTE()
  32. ON_WM_PALETTECHANGED()
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. CShieldStatus::CShieldStatus():
  36.         m_uPrevShieldLevel (0),
  37.         m_uCurShieldLevel (100)
  38. {
  39.     m_DIB.CreateEmpty (SHIELD_STATUS_WIDTH, MAP_HEIGHT);
  40.     m_DIB.GetPaletteFromResourceBitmap (IDB_BULLET);
  41. }
  42. void CShieldStatus::SetLevel (UINT uShieldLevel)
  43. {
  44.     ASSERT (uShieldLevel <= 100);
  45.     m_uCurShieldLevel = uShieldLevel;
  46.     if (m_uCurShieldLevel != m_uPrevShieldLevel)
  47.         InvalidateRect (NULL, FALSE);
  48. }
  49. enum {  BLOCK_SIZE = 7,
  50.         GAP_SIZE   = 2
  51.      };
  52. CDIB *CShieldStatus::GetImage ()
  53. {
  54.     if (m_uCurShieldLevel != m_uPrevShieldLevel)
  55.     {   // Level has changed - recreate image
  56.         int iNumBars = (MAP_HEIGHT + GAP_SIZE) / (BLOCK_SIZE + GAP_SIZE);
  57.         int iColorStep = int(float(255) / float(iNumBars));
  58.         iNumBars = int (float(iNumBars) * float (m_uCurShieldLevel) / float(100));
  59.         int iCurColor = 0;
  60.         m_DIB.FillSolidColor (0,0,0); // Clear to background
  61.         for (int i=0; i < iNumBars; i++)
  62.         {
  63.             m_DIB.FillRect (0, 
  64.                             i*(BLOCK_SIZE + GAP_SIZE), 
  65.                             SHIELD_STATUS_WIDTH,
  66.                             BLOCK_SIZE, 
  67.                             255 - iCurColor, 0, iCurColor);
  68.             iCurColor += iColorStep;
  69.         }
  70.         m_uPrevShieldLevel = m_uCurShieldLevel;
  71.     }
  72.     return &m_DIB;
  73. }