map.h 3.2 KB

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