Prototype game engine for Heroes of Might & Magic, featuring a gameplay plot-twist...
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

137 lignes
4.8KB

  1. -- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic
  2. --
  3. -- GNU General Public Licence (version 3 or later)
  4. with core, resource, item, unit, construction, world;
  5. package body world is
  6. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  7. type landmark_index is (
  8. dead_tree, mossy_rock, palm_tree, pine_tree, reeds, rock, snowed_pine_tree, snowed_rock, spiky_rock
  9. );
  10. type landmark_trait is record
  11. spawn : biome;
  12. clip : boolean;
  13. frames : integer;
  14. end record;
  15. type landmark_value is record
  16. index : landmark_index;
  17. x : integer;
  18. y : integer;
  19. end record;
  20. type tile_array is array (natural range <>, natural range <>) of integer;
  21. type landmark_array is array (natural range <>) of landmark_value;
  22. type information is record
  23. terrain : biome;
  24. width : natural;
  25. height : natural;
  26. tiles : access tile_array;
  27. landmarks : access landmark_array;
  28. end record;
  29. ------------------------------------------------------------------------------------------
  30. map : information;
  31. tiles : core.sprite;
  32. landmarks : array (landmark_index) of core.sprite;
  33. landmark_limit : constant integer := 7;
  34. trait : constant array (landmark_index) of landmark_trait := (
  35. (ash, true, 1),
  36. (swamp, true, 1),
  37. (cave, true, 4),
  38. (grass, true, 4),
  39. (swamp, false, 4),
  40. (cave, true, 1),
  41. (snow, true, 4),
  42. (snow, true, 1),
  43. (ash, true, 1)
  44. );
  45. ------------------------------------------------------------------------------------------
  46. procedure configure is
  47. begin
  48. core.echo (core.comment, "Configuring world components...");
  49. --
  50. tiles := core.import_sprite ("./sprite/world/terrain/terrain.png", 1, 1);
  51. --
  52. for index in landmark_index loop
  53. declare file : constant string := core.lowercase (index'image);
  54. begin
  55. landmarks (index) := core.import_sprite ("./sprite/world/landmark/" & file & ".png", trait (index).frames, 1);
  56. end;
  57. end loop;
  58. end configure;
  59. ------------------------------------------------------------------------------------------
  60. procedure make (index : in biome; width, height : in natural) is
  61. begin
  62. core.echo (core.comment, "-- Procedurally generating new map...");
  63. --
  64. core.echo (core.comment, "-- -- Map type : " & index'image);
  65. core.echo (core.comment, "-- -- Map width :" & width'image);
  66. core.echo (core.comment, "-- -- Map height :" & height'image);
  67. core.echo (core.comment, "-- -- Landmark count :" & landmark_limit'image);
  68. --
  69. map.terrain := index;
  70. map.width := width;
  71. map.height := height;
  72. map.tiles := new tile_array (0 .. width - 1, 0 .. height - 1);
  73. map.landmarks := new landmark_array (1 .. landmark_limit);
  74. --
  75. for x in 0 .. width - 1 loop
  76. for y in 0 .. height - 1 loop
  77. map.tiles (x, y) := (x * x + x * y + y * y) mod 24;
  78. end loop;
  79. end loop;
  80. --
  81. for index in 1 .. landmark_limit loop
  82. map.landmarks (index).index := landmark_index'val (core.random (0, 8));
  83. map.landmarks (index).x := core.base * core.random (1, 24);
  84. map.landmarks (index).y := core.base * core.random (1, 24);
  85. end loop;
  86. --
  87. core.echo (core.success, "Finished procedurally generating new map.");
  88. end make;
  89. ------------------------------------------------------------------------------------------
  90. procedure draw is
  91. u, v : integer;
  92. begin
  93. for move_y in 0 .. core.window_height / core.base / core.zoom + 1 loop
  94. for move_x in 0 .. core.window_width / core.base / core.zoom + 1 loop
  95. u := core.base * biome'pos (map.terrain) * 4;
  96. v := core.base * map.tiles (core.camera.x + move_x, core.camera.y + move_y);
  97. --
  98. core.draw (tiles, (move_x - 1) * core.base * core.zoom, (move_y - 1) * core.base * core.zoom, u, v, core.base, core.base);
  99. end loop;
  100. end loop;
  101. --
  102. --~for index in 1 .. landmark_limit loop
  103. --~core.draw (landmarks (map.landmarks (index).index),
  104. --~map.landmarks (index).x - core.camera.x * core.base,
  105. --~map.landmarks (index).y - core.camera.y * core.base,
  106. --~x, y, core.base, core.base);
  107. --~end loop;
  108. end draw;
  109. ------------------------------------------------------------------------------------------
  110. function width return integer is begin return map.width; end width;
  111. function height return integer is begin return map.height; end height;
  112. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  113. end world;