Prototype game engine for Heroes of Might & Magic, featuring a gameplay plot-twist...
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

183 řádky
7.6KB

  1. -- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic
  2. --
  3. -- GNU General Public Licence (version 3 or later)
  4. with core, ui, resource, item, unit, construction;
  5. package body world is
  6. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  7. procedure configure is
  8. begin
  9. core.echo (core.comment, "Configuring world components...");
  10. --
  11. tiles := core.import_sprite ("./sprite/world/terrain/terrain.png", 1, 1);
  12. --
  13. for index in landmark_index loop
  14. declare file : constant string := core.lowercase (index'image);
  15. begin
  16. landmarks (index) := core.import_sprite ("./sprite/world/landmark/" & file & ".png", trait (index).frames, 1);
  17. end;
  18. end loop;
  19. end configure;
  20. ------------------------------------------------------------------------------------------
  21. procedure make (index : in biome; width, height : in natural) is
  22. begin
  23. core.echo (core.comment, "-- Procedurally generating new map...");
  24. --
  25. core.echo (core.comment, "-- -- Map type : " & index'image);
  26. core.echo (core.comment, "-- -- Map width :" & width'image);
  27. core.echo (core.comment, "-- -- Map height :" & height'image);
  28. core.echo (core.comment, "-- -- Landmark count :" & landmark_limit'image);
  29. --
  30. map.kind := index;
  31. map.width := width;
  32. map.height := height;
  33. --
  34. map.tiles := new tile_array (0 .. map.width - 1, 0 .. map.height - 1);
  35. map.clips := new clip_array (0 .. map.width - 1, 0 .. map.height - 1);
  36. map.views := new view_array (0 .. map.width - 1, 0 .. map.height - 1);
  37. map.landmarks := new entity_array (1 .. landmark_limit);
  38. map.constructions := new entity_array (1 .. 30);
  39. map.items := new entity_array (1 .. 60);
  40. --
  41. for x in 0 .. width - 1 loop
  42. for y in 0 .. height - 1 loop
  43. map.tiles (x, y) := (core.random (0, 23) * core.random (0, 23)) mod 24;
  44. map.clips (x, y) := false;
  45. map.views (x, y) := false;
  46. end loop;
  47. end loop;
  48. --
  49. for index in 1 .. landmark_limit loop
  50. map.landmarks (index).index := core.random (0, 9);
  51. map.landmarks (index).x := core.random (6, map.width - 6);
  52. map.landmarks (index).y := core.random (6, map.height - 6);
  53. --
  54. if trait (landmark_index'val (map.landmarks (index).index)).clip then
  55. declare reach_x : constant natural := landmarks (landmark_index'val (map.landmarks (index).index)).width / core.base;
  56. reach_y : constant natural := landmarks (landmark_index'val (map.landmarks (index).index)).height / core.base;
  57. begin
  58. for x in 0 .. reach_x - 1 loop
  59. for y in 0 .. reach_y - 1 loop
  60. map.clips (map.landmarks (index).x + x, map.landmarks (index).y + y) := true;
  61. end loop;
  62. end loop;
  63. end;
  64. end if;
  65. end loop;
  66. --
  67. for index in 1 .. 30 loop
  68. map.constructions (index).index := core.random (0, construction.count - 1);
  69. map.constructions (index).x := core.random (6, map.width - 6);
  70. map.constructions (index).y := core.random (6, map.height - 6);
  71. --
  72. declare reach_x : constant natural := construction.sprite (construction.enumeration'val (map.constructions (index).index)).width / core.base;
  73. reach_y : constant natural := construction.sprite (construction.enumeration'val (map.constructions (index).index)).height / core.base;
  74. begin
  75. for x in 0 .. reach_x - 1 loop
  76. for y in 0 .. reach_y - 1 loop
  77. map.clips (map.constructions (index).x + x, map.constructions (index).y + y) := true;
  78. end loop;
  79. end loop;
  80. end;
  81. end loop;
  82. --
  83. for index in 1 .. 60 loop
  84. map.items (index).index := core.random (0, item.count - 1);
  85. map.items (index).x := core.random (0, map.width - 1);
  86. map.items (index).y := core.random (0, map.height - 1);
  87. end loop;
  88. --
  89. core.echo (core.success, "Finished procedurally generating new map.");
  90. end make;
  91. ------------------------------------------------------------------------------------------
  92. procedure draw is
  93. u : integer := 0;
  94. v : integer := 0;
  95. --
  96. offset : core.vector := ((core.window_width - core.base) / 2,
  97. (core.window_height - core.base) / 2);
  98. --
  99. render : core.vector := (map.width - 1,
  100. map.height - 1);
  101. begin
  102. view;
  103. --
  104. for vertical in 0 .. map.height - 1 loop
  105. exit when offset.y + (vertical - core.camera.y) * core.base * core.zoom > core.window_height;
  106. --
  107. for horizontal in 0 .. map.width - 1 loop
  108. exit when offset.x + (horizontal - core.camera.x) * core.base * core.zoom > core.window_width;
  109. --
  110. if map.views (horizontal, vertical) then
  111. u := core.base * biome'pos (map.kind) * 4;
  112. v := core.base * map.tiles (horizontal, vertical);
  113. --
  114. core.draw (data => tiles,
  115. x => offset.x + (horizontal - core.camera.x) * core.base * core.zoom,
  116. y => offset.y + (vertical - core.camera.y) * core.base * core.zoom,
  117. u => u,
  118. v => v,
  119. width => core.base,
  120. height => core.base);
  121. --~--MOVE PLAYER TO TILE WHERE YOU CLICKED
  122. --~if core.cursor.x > offset.x + (horizontal - core.camera.x ) * core.base * core.zoom
  123. --~and core.cursor.x < offset.x + (horizontal - core.camera.x + 1) * core.base * core.zoom
  124. --~and core.cursor.y > offset.y + (vertical - core.camera.y ) * core.base * core.zoom
  125. --~and core.cursor.y < offset.y + (vertical - core.camera.y + 1) * core.base * core.zoom
  126. --~and core.cursor_mode = 1 then
  127. --~core.camera.x := horizontal;
  128. --~core.camera.y := vertical;
  129. --~core.cursor_mode := 0;
  130. --~end if;
  131. end if;
  132. end loop;
  133. end loop;
  134. --
  135. for index in 1 .. landmark_limit loop
  136. if map.views (map.landmarks (index).x, map.landmarks (index).y) then
  137. core.draw (data => landmarks (landmark_index'val (map.landmarks (index).index)),
  138. x => offset.x + (map.landmarks (index).x - core.camera.x) * core.base * core.zoom,
  139. y => offset.y + (map.landmarks (index).y - core.camera.y) * core.base * core.zoom);
  140. end if;
  141. end loop;
  142. --
  143. for index in 1 .. 30 loop
  144. if map.views (map.constructions (index).x, map.constructions (index).y) then
  145. construction.draw (construction.enumeration'val (map.constructions (index).index),
  146. offset.x + (map.constructions (index).x - core.camera.x) * core.base * core.zoom,
  147. offset.y + (map.constructions (index).y - core.camera.y) * core.base * core.zoom);
  148. end if;
  149. end loop;
  150. --
  151. for index in 1 .. 60 loop
  152. if map.views (map.items (index).x, map.items (index).y) then
  153. item.draw (item.enumeration'val (map.items (index).index),
  154. offset.x + (map.items (index).x - core.camera.x) * core.base * core.zoom,
  155. offset.y + (map.items (index).y - core.camera.y) * core.base * core.zoom);
  156. end if;
  157. end loop;
  158. end draw;
  159. ------------------------------------------------------------------------------------------
  160. procedure view is
  161. view_reach : constant integer := 12;
  162. begin
  163. for x in 0 .. view_reach loop
  164. for y in 0 .. view_reach loop
  165. map.views ((x + core.camera.x - view_reach / 2) mod map.width, (y + core.camera.y - view_reach / 2) mod map.height) := true;
  166. end loop;
  167. end loop;
  168. end view;
  169. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  170. end world;