home *** CD-ROM | disk | FTP | other *** search
/ NEXT Generation 27 / NEXT27.iso / pc / demos / emperor / dx3.exe / SDK / SAMPLES / IKLOWNS / CGIMAGE.H < prev    next >
C/C++ Source or Header  |  1996-08-28  |  4KB  |  152 lines

  1. /*===========================================================================*\
  2. |
  3. |  File:        cgimage.h
  4. |
  5. |  Description: 
  6. |       
  7. |-----------------------------------------------------------------------------
  8. |
  9. |  Copyright (C) 1995-1996 Microsoft Corporation.  All Rights Reserved.
  10. |
  11. |  Written by Moss Bay Engineering, Inc. under contract to Microsoft Corporation
  12. |
  13. \*===========================================================================*/
  14.  
  15. /**************************************************************************
  16.  
  17.     (C) Copyright 1995-1996 Microsoft Corp.  All rights reserved.
  18.  
  19.     You have a royalty-free right to use, modify, reproduce and 
  20.     distribute the Sample Files (and/or any modified version) in 
  21.     any way you find useful, provided that you agree that 
  22.     Microsoft has no warranty obligations or liability for any 
  23.     Sample Application Files which are modified. 
  24.  
  25.     we do not recomend you base your game on IKlowns, start with one of
  26.     the other simpler sample apps in the GDK
  27.  
  28.  **************************************************************************/
  29.  
  30. #ifndef CGIMAGE_H
  31. #define CGIMAGE_H
  32.  
  33. #include "cggraph.h"
  34.  
  35. #define TRANSPARENT_TILE ((WORD)-1)
  36. #define MARK_TRANSPARENT(tile) ((WORD) tile | 0x8000)
  37.  
  38. // we use palette index 1 for transparency
  39. #define TRANSPARENCY_INDEX ((BYTE)1)
  40.  
  41. #define HAS_TRANSPARENCY( num ) ((WORD) num & 0x8000)
  42. #define IS_TRANSPARENT( num ) (num == TRANSPARENT_TILE)
  43.  
  44. #define TILE_INDEX( num ) ((WORD)IS_TRANSPARENT(num)?0:num & ~0x8000)
  45.  
  46. // maximum width we can allow for our tile source bitmaps
  47. #define MAX_TILE_SRC_WIDTH 640
  48. #define MAX_TILE_COLUMNS 20
  49.  
  50. // convert a tile number into x or y from source bitmap
  51. #define TILE_SRC_X( num ) ((WORD) (TILE_INDEX(num) % MAX_TILE_COLUMNS) * TILE_SIZE)
  52. #define TILE_SRC_Y( num ) ((WORD) (TILE_INDEX(num) / MAX_TILE_COLUMNS) * TILE_SIZE)
  53.  
  54. //#define TILE_MAP_SIGNATURE 'TLMP'
  55. #define TILE_MAP_SIGNATURE 0x544c4d50
  56. #define TILE_MAP_VERSION 0x0012
  57.  
  58. #define TILE_SIZE 32
  59.  
  60. #define TILE_TO_TX(tile) (tile * TILE_SIZE)
  61. #define TILE_TO_TY(tile) (0)
  62.  
  63. #define WX_TO_INDEX(wx) (wx % TILE_SIZE)
  64. #define WY_TO_INDEX(wy) (wy / TILE_SIZE)
  65.  
  66. struct TileMapStamp
  67. {
  68.     DWORD signature;
  69.     DWORD version;
  70.     WORD columns;
  71.     WORD rows;
  72.     WORD tileSize;
  73.     WORD nameLength;    // length of following filename including terminator
  74.  
  75.     // this is followed by the DIB name, then the WORD array[col][row] of tile numbers
  76. };
  77.  
  78. #define CG_DEFAULT_TILE_SIZE 16
  79.  
  80. // maximum number of tiles in an image
  81. #define CG_TILE_LIMIT ((WORD)0xffff)
  82.  
  83. typedef WORD CG_TILE_INDEX;
  84.  
  85. class CGameImage : public CGameGraphic
  86. {
  87. public:
  88.     CGameImage(char* pFileName, int curz) : CGameGraphic(curz){};       // load existing image file
  89.     virtual ~CGameImage(){};
  90.  
  91.     virtual HPALETTE GetHPalette() = 0;
  92. protected:
  93. };
  94.  
  95. class CGameSkyImage : public CGameImage
  96. {
  97. public:
  98.     CGameSkyImage(char* pFileName);     // load existing image file
  99.     virtual ~CGameSkyImage();
  100.  
  101.     virtual HPALETTE GetHPalette()
  102.     {
  103.         return NULL;
  104.     }
  105.  
  106.     virtual void Update(CGameLevel* pLevel, CGameUpdateList* pUpdate);
  107.     virtual void Render(CGameLevel* pLevel, CGameScreen* pScreen, CGameUpdateList* pUpdate);
  108.  
  109. protected:
  110. };
  111.  
  112. #define SCREEN_WIDTH 640
  113. #define SCREEN_HEIGHT 480
  114. #define SCREEN_COLS (SCREEN_WIDTH / TILE_SIZE)
  115. #define SCREEN_ROWS (SCREEN_HEIGHT / TILE_SIZE)
  116.  
  117. #define BUFFER_COLS (SCREEN_COLS+2)
  118. #define BUFFER_ROWS (SCREEN_ROWS+2)
  119.  
  120. #define BUFFER_WIDTH (BUFFER_COLS * TILE_SIZE)
  121. #define BUFFER_HEIGHT (BUFFER_ROWS * TILE_SIZE)
  122.  
  123. #define EXTRA_WIDTH (TILE_SIZE * 2)
  124. #define EXTRA_HEIGHT (TILE_SIZE * 2)
  125.  
  126. // the "read-only" tiled image (for use in games)
  127. class CGameTiledImage : public CGameImage
  128. {
  129. public:
  130.     CGameTiledImage(char* pFileName, int curz,
  131.         int curx=0, int cury=0  );      // load existing image file
  132.  
  133.     virtual ~CGameTiledImage();
  134.  
  135.     virtual void Update(CGameLevel* pLevel, CGameUpdateList* pUpdate);
  136.     virtual void Render(CGameLevel* pLevel, CGameScreen* pScreen, CGameUpdateList* pUpdate);
  137.  
  138.     virtual HPALETTE GetHPalette()
  139.     {
  140.         return mpDIBBuffer ? mpDIBBuffer->GetHPalette() : NULL;
  141.     }
  142.  
  143. protected:
  144.     int mNumCols;
  145.  
  146.     CG_TILE_INDEX** mTileArray;     // array[row][column] of tile #s describing image
  147.  
  148.     CGameBitBuffer* mpDIBBuffer;    // holds the image's DIB tiles
  149. };
  150.  
  151. #endif // CGIMAGE_H
  152.