Prototype game engine for Heroes of Might & Magic, featuring a gameplay plot-twist...
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

225 linhas
7.0KB

  1. -- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic
  2. --
  3. -- GNU General Public Licence (version 3 or later)
  4. pragma ada_2012;
  5. --~with core, ui, effect, attribute, skill, resource, faction, might, magic, item, unit, construction, chad, deity, world, ai;
  6. with core, ui, effect, attribute, skill, resource, faction, item, unit, construction, chad, world;
  7. use core;
  8. procedure main is
  9. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  10. side_panel : integer := 0;
  11. preview_width : integer := 0;
  12. preview_height : integer := 0;
  13. text_box_height : integer := 0;
  14. player : chad.information := chad.trait (chad.ognjen);
  15. ------------------------------------------------------------------------------------------
  16. type view is (
  17. map_preview_panel, status_preview_panel, text_box_panel
  18. );
  19. view_icon : array (view) of sprite := (others => (others => 0));
  20. view_list : array (view) of boolean := (others => true);
  21. view_text : array (view) of long_string := (
  22. "Toggle map preview panel. ",
  23. "Toggle status preview panel. ",
  24. "Toggle text box panel. "
  25. );
  26. procedure swap_map_preview_panel is begin view_list (map_preview_panel) := not view_list (map_preview_panel); end swap_map_preview_panel;
  27. procedure swap_status_preview_panel is begin view_list (status_preview_panel) := not view_list (status_preview_panel); end swap_status_preview_panel;
  28. procedure swap_text_box_panel is begin view_list (text_box_panel) := not view_list (text_box_panel); end swap_text_box_panel;
  29. view_show : array (view) of access procedure := (
  30. swap_map_preview_panel'access,
  31. swap_status_preview_panel'access,
  32. swap_text_box_panel'access
  33. );
  34. ------------------------------------------------------------------------------------------
  35. procedure check_move_camera_up is
  36. begin
  37. move_camera_up;
  38. camera.y := clip (camera.y, 0, world.map.height - 1);
  39. if world.map.clips (camera.x, camera.y) then
  40. increment (camera.y);
  41. end if;
  42. end check_move_camera_up;
  43. procedure check_move_camera_down is
  44. begin
  45. move_camera_down;
  46. camera.y := clip (camera.y, 0, world.map.height - 1);
  47. if world.map.clips (camera.x, camera.y) then
  48. decrement (camera.y);
  49. end if;
  50. end check_move_camera_down;
  51. procedure check_move_camera_left is
  52. begin
  53. move_camera_left;
  54. camera.x := clip (camera.x, 0, world.map.width - 1);
  55. if world.map.clips (camera.x, camera.y) then
  56. increment (camera.x);
  57. end if;
  58. end check_move_camera_left;
  59. procedure check_move_camera_right is
  60. begin
  61. move_camera_right;
  62. camera.x := clip (camera.x, 0, world.map.width - 1);
  63. if world.map.clips (camera.x, camera.y) then
  64. decrement (camera.x);
  65. end if;
  66. end check_move_camera_right;
  67. procedure ui_main_style is
  68. begin
  69. ui.active := ui.style'val ((ui.style'pos (ui.active) + 1) mod (ui.style'pos (ui.style'last) + 1));
  70. end ui_main_style;
  71. procedure zoom_in is begin zoom := 2; end zoom_in;
  72. procedure zoom_out is begin zoom := 1; end zoom_out;
  73. signal_list : constant array (signal_code) of access procedure := (
  74. signal_up => check_move_camera_up'access,
  75. signal_down => check_move_camera_down'access,
  76. signal_left => check_move_camera_left'access,
  77. signal_right => check_move_camera_right'access,
  78. signal_v => ui_main_style'access,
  79. signal_kp_add => zoom_in'access,
  80. signal_kp_subtract => zoom_out'access,
  81. others => idle'access
  82. );
  83. ------------------------------------------------------------------------------------------
  84. procedure introduction is
  85. begin
  86. core.write ("[-- Please press Spacebar to continue]", 0, center_y (24), (102, 102, 102, 255));
  87. end introduction;
  88. ------------------------------------------------------------------------------------------
  89. procedure gameplay is
  90. begin
  91. if not view_list (status_preview_panel) then
  92. side_panel := 0;
  93. else
  94. side_panel := window_width / 4;
  95. end if;
  96. --
  97. preview_width := window_width - side_panel;
  98. preview_height := window_height - text_box_height;
  99. text_box_height := 32;
  100. --
  101. world.draw;
  102. --
  103. if view_list (map_preview_panel) then
  104. ui.draw_menu (0, 0, preview_width, preview_height);
  105. end if;
  106. --
  107. if view_list (status_preview_panel) then
  108. ui.draw_tiny_menu (preview_width, 0, side_panel, preview_height);
  109. ui.draw_state_box (preview_width + 32, 32);
  110. end if;
  111. --
  112. if view_list (text_box_panel) then
  113. ui.draw_help_box (0, window_height - text_box_height, window_width - icon * (view'pos (view'last) + 1), text_box_height);
  114. end if;
  115. --
  116. for index in view loop
  117. ui.draw_icon (view_icon (index), view_text (index),
  118. window_width - icon * (view'pos (view'last) + 1) + icon * view'pos (index),
  119. window_height - text_box_height,
  120. view_show (index));
  121. end loop;
  122. --
  123. signal_list (signal_mode).all;
  124. --
  125. --~magic.menu (0, 0, true);
  126. --~might.menu (0, 0, true);
  127. --
  128. chad.draw_alice;
  129. --
  130. ui.synchronize;
  131. end gameplay;
  132. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  133. begin
  134. dash;
  135. echo (comment, "Copyright (C) 2024 -- Ognjen 'xolatile' Milan Robovic");
  136. echo (comment, "Version -- 1.0.0");
  137. echo (comment, "License -- GNU/GPLv3+");
  138. echo (comment, "Xhads is free software, you can redistribute it and modify it under the terms of the GNU General Public License by Free Software Foundation.");
  139. dash;
  140. initialize;
  141. ui.configure;
  142. play (import_song (c_string ("./song/main_menu.ogg")).index);
  143. attribute.configure;
  144. skill.configure;
  145. resource.configure;
  146. --~might.configure;
  147. --~magic.configure;
  148. item.configure;
  149. unit.configure;
  150. construction.configure;
  151. chad.configure;
  152. world.configure;
  153. --~ai.configure;
  154. world.make (world.swamp, 120, 60);
  155. dash;
  156. echo (success, "Successfully initialized game data, entering main gameplay loop.");
  157. dash;
  158. for index in view loop
  159. view_icon (index) := import_sprite ("./sprite/ui/icon/" & lowercase (view'image (index)) & ".png", 1, 1);
  160. end loop;
  161. ui.active := ui.imp;
  162. camera := (1, 1);
  163. ------------------------------------------------------------------------------------------
  164. introduction_loop: loop
  165. synchronize;
  166. --
  167. exit when signal_mode = signal_space;
  168. --
  169. introduction;
  170. end loop introduction_loop;
  171. gameplay_loop: loop
  172. synchronize;
  173. --
  174. exit when engine_active = false;
  175. --
  176. gameplay;
  177. end loop gameplay_loop;
  178. ------------------------------------------------------------------------------------------
  179. deinitialize;
  180. dash;
  181. end main;