map.h 3.2 KB

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