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

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   ImageManager.inl
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Contents: Inline functions implementations.
  11. *                                                                             
  12. *   Authors: Eran Yariv - 28484475                                           
  13. *            Moshe Zur  - 24070856                                           
  14. *                                                                            
  15. *                                                                            
  16. *   Date: 23/09/98                                                           
  17. *                                                                            
  18. ******************************************************************************/
  19. inline CImageManager::CImageManager () :
  20.     m_bCreated (FALSE)
  21. {}
  22. #ifdef _DEBUG
  23. inline void 
  24. CImageManager::AssertValidHImage (HIMAGE &himg)
  25. {
  26.     ASSERT (himg.bImageType < IMG_LAST_INDEX);
  27.     ASSERT (himg.bSubImgID < m_ImagesInfo[himg.bImageType].uNumSubImages);
  28.     ASSERT (himg.bFrame < m_ImagesInfo[himg.bImageType].SubImages[himg.bSubImgID].uNumBitmaps);
  29. }
  30. #endif
  31. inline HIMAGE 
  32. CImageManager::GetImage (ImageType typ)
  33. {
  34.     ASSERT (m_bCreated);
  35.         // Check for valid type
  36.     ASSERT (typ >= 0 && typ < IMG_LAST_INDEX);
  37.     HIMAGE res = {BYTE(typ),    // Type of image
  38.                   0,            // Sub-image ID
  39.                   0,            // Frame number
  40.                   FALSE,        // Animation ended
  41.                   0,            // Animation start time
  42.                   NULL};        // No overlay
  43.     return res;
  44. }    
  45.     
  46. inline BOOL 
  47. CImageManager::ImageEnded (HIMAGE &himg)
  48. {
  49.     ASSERT (m_bCreated);
  50.     //ASSERT_VALID_HIMAGE (himg); // Costly call
  51.     // If the following assertion fails, the function was called for a non-animating 
  52.     // image or a repeatative animation image.
  53.     ASSERT (!m_ImagesInfo[himg.bImageType].SubImages[himg.bSubImgID].bCyclicAnim &&  // Animation is acyclic
  54.             m_ImagesInfo[himg.bImageType].SubImages[himg.bSubImgID].dwFrameDelay >0); // and has a limited time
  55.     return himg.bAnimEnded;
  56. }
  57. inline void 
  58. CImageManager::GetImageSize (HIMAGE &himg, CSize &size)
  59. {
  60.     ASSERT (m_bCreated);
  61.     //ASSERT_VALID_HIMAGE (himg); // Costly call
  62.     size = m_ImagesInfo[himg.bImageType].SubImages[himg.bSubImgID].Bitmaps[himg.bFrame].pDIB->Size();
  63. }
  64. inline void 
  65. CImageManager::GetImageOffset (HIMAGE &himg, CPoint &offset)
  66. {
  67.     ASSERT (m_bCreated);
  68.     //ASSERT_VALID_HIMAGE (himg); // Costly call
  69.     BitmapType *pCurBitmap = &m_ImagesInfo[himg.bImageType].SubImages[himg.bSubImgID].Bitmaps[himg.bFrame];
  70.     offset.x = pCurBitmap->iXOffset;
  71.     offset.y = pCurBitmap->iYOffset;
  72. }
  73. inline void 
  74. CImageManager::RotateImage (HIMAGE &himg, UINT uRotationIndex)
  75. {   // Assuming sub-images are ordered by degrees, comprising a full circle.
  76.     ASSERT (m_bCreated);
  77.     //ASSERT_VALID_HIMAGE (himg); // Costly call
  78.     ASSERT (m_ImagesInfo[himg.bImageType].uNumSubImages > uRotationIndex);   // Can't rotate with only one sub-image
  79.     himg.bSubImgID = BYTE(uRotationIndex); 
  80. }
  81. inline CDIB *
  82. CImageManager::ExposeDIB (HIMAGE &himg)
  83. {
  84.     ASSERT (m_bCreated);
  85.     ASSERT_VALID_HIMAGE (himg); // Costly call
  86.     return m_ImagesInfo[himg.bImageType].SubImages[himg.bSubImgID].Bitmaps[himg.bFrame].pDIB;
  87. }
  88. inline CBitMask *
  89. CImageManager::ExposeBitMask(HIMAGE &himg)
  90. {
  91.     ASSERT (m_bCreated);
  92.     ASSERT_VALID_HIMAGE (himg); // Costly call
  93.     return m_ImagesInfo[himg.bImageType].SubImages[himg.bSubImgID].Bitmaps[himg.bFrame].pBitMask;
  94. }
  95. inline void
  96. CImageManager::LoadGameOverBitmaps ()
  97. {
  98.     LoadSingleImage (IMG_GAMEOVER);
  99. }
  100. inline void
  101. CImageManager::ReleaseGameOverBitmaps ()
  102. {
  103.     ReleaseSingleImage (IMG_GAMEOVER);
  104. }
  105. inline void
  106. CImageManager::SetOverlay (HIMAGE &img, HIMAGE *pimg)
  107. {
  108.     img.pOverlay = pimg;
  109. }
  110.     
  111. inline HIMAGE *
  112. CImageManager::GetOverlay(HIMAGE &img)
  113. {
  114.     return img.pOverlay;
  115. }