map.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. #include "common.h"
  24. //
  25. // Map format:
  26. //
  27. // +----------------------------------------------> x
  28. // | * * * * * * * * * * ... * * * * * * * * * * (y = 0, h = 0)
  29. // | * * * * * * * * * * ... * * * * * * * * * * (y = 0, h = 1)
  30. // | * * * * * * * * * * ... * * * * * * * * * * (y = 1, h = 0)
  31. // | * * * * * * * * * * ... * * * * * * * * * * (y = 1, h = 1)
  32. // | * * * * * * * * * * ... * * * * * * * * * * (y = 2, h = 0)
  33. // | * * * * * * * * * * ... * * * * * * * * * * (y = 2, h = 1)
  34. // | ............................................
  35. // v
  36. // y
  37. //
  38. // Note:
  39. //
  40. // Tiles are in diamond shape (32x15).
  41. //
  42. // Each tile is represented with a DWORD value, which contains information
  43. // about the tile bitmap, block flag, height, etc.
  44. //
  45. // Bottom layer sprite index:
  46. // (d & 0xFF) | ((d >> 4) & 0x100)
  47. //
  48. // Top layer sprite index:
  49. // d >>= 16;
  50. // ((d & 0xFF) | ((d >> 4) & 0x100)) - 1)
  51. //
  52. // Block flag (player cannot walk through this tile):
  53. // d & 0x2000
  54. //
  55. typedef struct tagPALMAP
  56. {
  57. DWORD Tiles[128][64][2];
  58. LPSPRITE pTileSprite;
  59. INT iMapNum;
  60. } PALMAP, *LPPALMAP;
  61. typedef const PALMAP *LPCPALMAP;
  62. PAL_C_LINKAGE_BEGIN
  63. LPPALMAP
  64. PAL_LoadMap(
  65. INT iMapNum,
  66. FILE *fpMapMKF,
  67. FILE *fpGopMKF
  68. );
  69. VOID
  70. PAL_FreeMap(
  71. LPPALMAP lpMap
  72. );
  73. LPCBITMAPRLE
  74. PAL_MapGetTileBitmap(
  75. BYTE x,
  76. BYTE y,
  77. BYTE h,
  78. BYTE ucLayer,
  79. LPCPALMAP lpMap
  80. );
  81. BOOL
  82. PAL_MapTileIsBlocked(
  83. BYTE x,
  84. BYTE y,
  85. BYTE h,
  86. LPCPALMAP lpMap
  87. );
  88. BYTE
  89. PAL_MapGetTileHeight(
  90. BYTE x,
  91. BYTE y,
  92. BYTE h,
  93. BYTE ucLayer,
  94. LPCPALMAP lpMap
  95. );
  96. VOID
  97. PAL_MapBlitToSurface(
  98. LPCPALMAP lpMap,
  99. SDL_Surface *lpSurface,
  100. const SDL_Rect *lpSrcRect,
  101. BYTE ucLayer
  102. );
  103. PAL_C_LINKAGE_END
  104. //
  105. // Convert map location to the real location
  106. //
  107. #define PAL_XYH_TO_POS(x, y, h) \
  108. PAL_POS((x) * 32 + (h) * 16, (y) * 16 + (h) * 8)
  109. //
  110. // Convert real location to map location
  111. //
  112. #define PAL_POS_TO_XYH(pos, x, y, h) \
  113. { \
  114. (h) = (BYTE)(((PAL_X(pos) % 32) != 0) ? 1 : 0); \
  115. (x) = (BYTE)(PAL_X(pos) / 32); \
  116. (y) = (BYTE)(PAL_Y(pos) / 16); \
  117. }
  118. #endif