map.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //
  2. // Copyright (c) 2009, Wei Mingzhi <whistler_wmz@users.sf.net>.
  3. // All rights reserved.
  4. //
  5. // This file is part of SDLPAL.
  6. //
  7. // SDLPAL is free software: you can redistribute it and/or modify
  8. // it under the terms of the GNU General Public License as published by
  9. // the Free Software Foundation, either version 3 of the License, or
  10. // (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. //
  17. // You should have received a copy of the GNU General Public License
  18. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. //
  20. #ifndef _MAP_H
  21. #define _MAP_H
  22. #ifdef __cplusplus
  23. extern "C"
  24. {
  25. #endif
  26. #include "common.h"
  27. //
  28. // Map format:
  29. //
  30. // +----------------------------------------------> x
  31. // | * * * * * * * * * * ... * * * * * * * * * * (y = 0, h = 0)
  32. // | * * * * * * * * * * ... * * * * * * * * * * (y = 0, h = 1)
  33. // | * * * * * * * * * * ... * * * * * * * * * * (y = 1, h = 0)
  34. // | * * * * * * * * * * ... * * * * * * * * * * (y = 1, h = 1)
  35. // | * * * * * * * * * * ... * * * * * * * * * * (y = 2, h = 0)
  36. // | * * * * * * * * * * ... * * * * * * * * * * (y = 2, h = 1)
  37. // | ............................................
  38. // v
  39. // y
  40. //
  41. // Note:
  42. //
  43. // Tiles are in diamond shape (32x15).
  44. //
  45. // Each tile is represented with a DWORD value, which contains information
  46. // about the tile bitmap, block flag, height, etc.
  47. //
  48. // Bottom layer sprite index:
  49. // (d & 0xFF) | ((d >> 4) & 0x100)
  50. //
  51. // Top layer sprite index:
  52. // d >>= 16;
  53. // ((d & 0xFF) | ((d >> 4) & 0x100)) - 1)
  54. //
  55. // Block flag (player cannot walk through this tile):
  56. // d & 0x2000
  57. //
  58. typedef struct tagPALMAP
  59. {
  60. DWORD Tiles[128][64][2];
  61. LPSPRITE pTileSprite;
  62. INT iMapNum;
  63. } PALMAP, *LPPALMAP;
  64. typedef const PALMAP *LPCPALMAP;
  65. LPPALMAP
  66. PAL_LoadMap(
  67. INT iMapNum,
  68. FILE *fpMapMKF,
  69. FILE *fpGopMKF
  70. );
  71. VOID
  72. PAL_FreeMap(
  73. LPPALMAP lpMap
  74. );
  75. LPCBITMAPRLE
  76. PAL_MapGetTileBitmap(
  77. BYTE x,
  78. BYTE y,
  79. BYTE h,
  80. BYTE ucLayer,
  81. LPCPALMAP lpMap
  82. );
  83. BOOL
  84. PAL_MapTileIsBlocked(
  85. BYTE x,
  86. BYTE y,
  87. BYTE h,
  88. LPCPALMAP lpMap
  89. );
  90. BYTE
  91. PAL_MapGetTileHeight(
  92. BYTE x,
  93. BYTE y,
  94. BYTE h,
  95. BYTE ucLayer,
  96. LPCPALMAP lpMap
  97. );
  98. VOID
  99. PAL_MapBlitToSurface(
  100. LPCPALMAP lpMap,
  101. SDL_Surface *lpSurface,
  102. const SDL_Rect *lpSrcRect,
  103. BYTE ucLayer
  104. );
  105. //
  106. // Convert map location to the real location
  107. //
  108. #define PAL_XYH_TO_POS(x, y, h) \
  109. PAL_POS((x) * 32 + (h) * 16, (y) * 16 + (h) * 8)
  110. //
  111. // Convert real location to map location
  112. //
  113. #define PAL_POS_TO_XYH(pos, x, y, h) \
  114. { \
  115. (h) = (BYTE)(((PAL_X(pos) % 32) != 0) ? 1 : 0); \
  116. (x) = (BYTE)(PAL_X(pos) / 32); \
  117. (y) = (BYTE)(PAL_Y(pos) / 16); \
  118. }
  119. #ifdef __cplusplus
  120. }
  121. #endif
  122. #endif