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

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   ImageManager.h
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Module description: Handle the images of all the game objects.
  11. *                       
  12. *                                                                             
  13. *   Authors: Eran Yariv - 28484475                                           
  14. *            Moshe Zur  - 24070856                                           
  15. *                                                                            
  16. *                                                                            
  17. *   Date: 23/09/98                                                           
  18. *                                                                            
  19. ******************************************************************************/
  20. #ifndef _IMAGE_MANAGER_H
  21. #define _IMAGE_MANAGER_H
  22. #include <DIB.h>
  23. #include <BitMask.h>
  24. #define HIMAGE CImageManager::ImageIdentifierType
  25. class CImageManager 
  26. {
  27. public:
  28. typedef enum {  IMG_TANK0 = 0,      //  Tank of type 0 (White) 
  29.                                     //      15 degrees rotations (24 bitmaps)
  30.                 IMG_TANK1,          //  Tank of type 1 (Blue)
  31.                                     //      15 degrees rotations (24 bitmaps)
  32.                 IMG_TANK2,          //  Tank of type 2 (Red)
  33.                                     //      15 degrees rotations (24 bitmaps)
  34.                 IMG_TANK3,          //  Tank of type 3 (Green)
  35.                                     //      15 degrees rotations (24 bitmaps)
  36.                 IMG_TANK_EXPLODE,   //  Tank explosion 
  37.                                     //      (16 frames)
  38.                 IMG_SHELL,          //  Sheel image
  39.                                     //      15 degrees rotations (24 bitmaps)
  40.                 IMG_SHELL_EXPLODE,  //  Shell explosion 
  41.                                     //      (28 frames)
  42.                 IMG_BULLET,         //  Bullet 
  43.                                     //      (1 bitmap)    
  44.                 IMG_BOARD,          //  Empty board
  45.                                     //      (1 bitmap)
  46.                 IMG_MINE,           //  Mine 
  47.                                     //      (2 frames ,cyclic animation, 1.00 seconds per cycle)
  48.                 IMG_BONUS_SHELLS,   //  Shells bonus 
  49.                                     //      (20 frames, cyclic animation, 2.00 seconds per cycle)
  50.                 IMG_BONUS_BULLETS,  //  Bullets bonus 
  51.                                     //      (20 frames, cyclic animation, 2.00 seconds per cycle)
  52.                 IMG_BONUS_MINES,    //  Mines bonus 
  53.                                     //      (9 frames, cyclic animation, 2.00 seconds per cycle)
  54.                 IMG_BONUS_BOMBER,   //  Areal support bonus 
  55.                                     //      (20 frames, cyclic animation, 2.00 seconds per cycle)
  56.                 IMG_BONUS_FIRERATE, //  Faster fire rate bonus 
  57.                                     //      (20 frames, cyclic animation, 2.00 seconds per cycle)
  58.                 IMG_BONUS_SHIELD,   //  Shield repair bonus 
  59.                                     //      (9 frames, cyclic animation, 2.00 seconds per cycle)
  60.                 IMG_GAMEOVER,       //  Game-over sign
  61.                                     //      (60 frames, cyclic animation, 4.00 seconds per cycle)
  62.                 IMG_BOMBER,         //  Bomber plane
  63.                                     //      15 degrees rotations (24 bitmaps)
  64.                 IMG_BOMB,           //  Dropping bomb
  65.                                     //      (11 frames, 2.00 seconds)
  66.                 IMG_TANK_ZOMBIE,    //  Zombie tank (Gray)
  67.                                     //      15 degrees rotations (24 bitmaps)
  68.                 IMG_LAST_INDEX      //  For compilation purposes (keep it last)
  69.             } ImageType;
  70.     typedef struct _ImageIdentifierType {
  71.         BYTE  bImageType;        // Type of image
  72.         BYTE  bSubImgID;         // Sub image ID
  73.         BYTE  bFrame;            // Animation frame
  74.         BOOL  bAnimEnded;        // Animation is expired
  75.         DWORD dwStartFrameTime;  // Start time of animation
  76.         struct _ImageIdentifierType *pOverlay;  // Pointer to optional overlay
  77.     } ImageIdentifierType;
  78.     CImageManager ();
  79.     virtual ~CImageManager ();
  80.     void   LoadImages();        // Creation - must be called only once and after the main window
  81.                                 //            is constructed !!!
  82.     HIMAGE      GetImage (ImageType);
  83.     void        UpdateImage (HIMAGE &, BOOL &);
  84.     void        DisplayImage (HIMAGE &himg, CDIB *pDstDIB, CPoint &pos);
  85.     void        RotateImage (HIMAGE &, UINT uAngle);
  86.     BOOL        ImageEnded (HIMAGE &);
  87.     CDIB       *ExposeDIB (HIMAGE &);
  88.     void        GetImageSize (HIMAGE &, CSize &);
  89.     void        GetImageOffset (HIMAGE &, CPoint &);
  90.     CBitMask   *ExposeBitMask(HIMAGE &);
  91.     void        SetOverlay (HIMAGE &, HIMAGE *p = NULL);
  92.     HIMAGE     *GetOverlay(HIMAGE &);
  93.     void        ReloadMap();        // Reload map image from file (for a new game session)
  94.     // The following two functions are here for memory consumption purposes:
  95.     void        LoadGameOverBitmaps ();
  96.     void        ReleaseGameOverBitmaps ();
  97. private:
  98. /*  O.K. - We hold a list of images (m_ImagesInfo). Each item on the list
  99.     is of ImageInfoType which is itself a list of subimages (SubImageType).
  100.     For example, a tank image has 24 sub images (different rotation angles).
  101.     Every subimage can be one or more frames of animation.
  102.     So, every sub image holds animation info (time, cyclic etc.) and a list of bitmaps.
  103.     Every bitmap holds the resource bitmap ID and a DIB buffer for the data.
  104.     The list is static and is composed at compile-time.
  105.     Only the DIB buffer in the list is dynamic and is initialized and loaded 
  106.     on run-time construction.
  107.     The image handle (HIMAGE) is actually a structure that points into the list.
  108.     It holds the following data:
  109.         1. Image index (Image type)
  110.         2. Sub image index (for example, tank angle)
  111.         3. Bitmap ID (animation frame)
  112.         4. Animation expiration flag (for non-cyclic animation images)
  113.         5. Last animation frame time
  114. */
  115. typedef struct {
  116.     UINT            uBitmapID;      // ID of resource bitmap
  117.     CDIB           *pDIB;           // DIB data of bitmap
  118.     CBitMask       *pBitMask;       // Bit mask of DIB 
  119.     int             iXOffset,       // Offset from original point
  120.                     iYOffset;
  121. } BitmapType;
  122. typedef struct {
  123.     UINT            uNumBitmaps;    // Number of frames (bitmaps)
  124.     BitmapType     *Bitmaps;        // Bitmaps of the sub-image
  125.     BOOL            bCyclicAnim;    // Is the animation cyclic (repeatative)?
  126.     DWORD           dwFrameDelay;   // Time gap (in millisecs) between the animation frames (0 = static image)
  127. } SubImageType;
  128. typedef struct {
  129.     UINT            uNumSubImages;  // Number of sub-images
  130.     SubImageType   *SubImages;      // Sub-images
  131. } ImageInfoType;
  132. #ifdef _DEBUG
  133.     void AssertValidHImage (HIMAGE &himg);
  134. #endif
  135.     void LoadSingleImage (ImageType);
  136.     void ReleaseSingleImage (ImageType);
  137.     BOOL                    m_bCreated;
  138.     static ImageInfoType    m_ImagesInfo[IMG_LAST_INDEX];
  139.     static BitmapType       m_Bitmaps[];
  140.     static SubImageType     m_SubImages[];
  141. };
  142. #ifdef _DEBUG
  143.     #define ASSERT_VALID_HIMAGE(h)      AssertValidHImage(h)
  144. #else
  145.     #define ASSERT_VALID_HIMAGE(h)
  146. #endif
  147. // Inline sections:
  148. #include <ImageManager.inl>
  149. #endif