Prototype game engine for Heroes of Might & Magic, featuring a gameplay plot-twist...
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
7.4KB

  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. game_title : sprite;
  35. ashland_preview : sprite;
  36. ------------------------------------------------------------------------------------------
  37. procedure check_move_camera_up is
  38. begin
  39. move_camera_up;
  40. camera.y := clip (camera.y, 0, world.map.height - 1);
  41. if world.map.clips (camera.x, camera.y) then
  42. increment (camera.y);
  43. end if;
  44. end check_move_camera_up;
  45. procedure check_move_camera_down is
  46. begin
  47. move_camera_down;
  48. camera.y := clip (camera.y, 0, world.map.height - 1);
  49. if world.map.clips (camera.x, camera.y) then
  50. decrement (camera.y);
  51. end if;
  52. end check_move_camera_down;
  53. procedure check_move_camera_left is
  54. begin
  55. move_camera_left;
  56. camera.x := clip (camera.x, 0, world.map.width - 1);
  57. if world.map.clips (camera.x, camera.y) then
  58. increment (camera.x);
  59. end if;
  60. end check_move_camera_left;
  61. procedure check_move_camera_right is
  62. begin
  63. move_camera_right;
  64. camera.x := clip (camera.x, 0, world.map.width - 1);
  65. if world.map.clips (camera.x, camera.y) then
  66. decrement (camera.x);
  67. end if;
  68. end check_move_camera_right;
  69. procedure ui_main_style is
  70. begin
  71. ui.active := ui.style'val ((ui.style'pos (ui.active) + 1) mod (ui.style'pos (ui.style'last) + 1));
  72. end ui_main_style;
  73. procedure zoom_in is begin zoom := 2; end zoom_in;
  74. procedure zoom_out is begin zoom := 1; end zoom_out;
  75. signal_list : constant array (signal_code) of access procedure := (
  76. signal_up => check_move_camera_up'access,
  77. signal_down => check_move_camera_down'access,
  78. signal_left => check_move_camera_left'access,
  79. signal_right => check_move_camera_right'access,
  80. signal_v => ui_main_style'access,
  81. signal_kp_add => zoom_in'access,
  82. signal_kp_subtract => zoom_out'access,
  83. others => idle_skip'access
  84. );
  85. ------------------------------------------------------------------------------------------
  86. procedure introduction is
  87. begin
  88. draw (ashland_preview, center_x (ashland_preview.width * 2), center_y (ashland_preview.height * 2), factor => 2);
  89. draw (game_title, center_x (game_title.width * 2), center_y (game_title.height * 2), factor => 2);
  90. --
  91. write ("[-- Please press Spacebar to continue]", 0, center_y (24), (102, 102, 102, 255));
  92. end introduction;
  93. ------------------------------------------------------------------------------------------
  94. procedure gameplay is
  95. begin
  96. if not view_list (status_preview_panel) then
  97. side_panel := 0;
  98. else
  99. side_panel := window_width / 4;
  100. end if;
  101. --
  102. preview_width := window_width - side_panel;
  103. preview_height := window_height - text_box_height;
  104. text_box_height := 32;
  105. --
  106. world.draw;
  107. --
  108. if view_list (map_preview_panel) then
  109. ui.draw_menu (0, 0, preview_width, preview_height);
  110. end if;
  111. --
  112. if view_list (status_preview_panel) then
  113. ui.draw_tiny_menu (preview_width, 0, side_panel, preview_height);
  114. ui.draw_state_box (preview_width + 32, 32);
  115. end if;
  116. --
  117. if view_list (text_box_panel) then
  118. ui.draw_help_box (0, window_height - text_box_height, window_width - icon * (view'pos (view'last) + 1), text_box_height);
  119. end if;
  120. --
  121. for index in view loop
  122. ui.draw_icon (view_icon (index), view_text (index),
  123. window_width - icon * (view'pos (view'last) + 1) + icon * view'pos (index),
  124. window_height - text_box_height,
  125. view_show (index));
  126. end loop;
  127. --
  128. signal_list (signal_mode).all;
  129. --
  130. --~magic.menu (0, 0, true);
  131. --~might.menu (0, 0, true);
  132. --
  133. chad.draw_alice;
  134. --
  135. ui.synchronize;
  136. end gameplay;
  137. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  138. begin
  139. dash;
  140. echo (comment, "Copyright (C) 2024 -- Ognjen 'xolatile' Milan Robovic");
  141. echo (comment, "Version -- 1.0.0");
  142. echo (comment, "License -- GNU/GPLv3+");
  143. 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.");
  144. dash;
  145. initialize;
  146. ui.configure;
  147. play (import_song (c_string ("./song/main_menu.ogg")).index);
  148. attribute.configure;
  149. skill.configure;
  150. resource.configure;
  151. --~might.configure;
  152. --~magic.configure;
  153. item.configure;
  154. unit.configure;
  155. construction.configure;
  156. chad.configure;
  157. world.configure;
  158. --~ai.configure;
  159. world.make (world.swamp, 120, 60);
  160. dash;
  161. echo (success, "Successfully initialized game data, entering main gameplay loop.");
  162. dash;
  163. for index in view loop
  164. view_icon (index) := import_sprite ("./sprite/ui/icon/" & lowercase (view'image (index)) & ".png", 1, 1);
  165. end loop;
  166. ui.active := ui.imp;
  167. camera := (1, 1);
  168. game_title := import_sprite ("./sprite/game_title.png", 1, 1);
  169. ashland_preview := import_sprite ("./sprite/ashland_preview.png", 1, 1);
  170. ------------------------------------------------------------------------------------------
  171. introduction_loop: loop
  172. synchronize;
  173. --
  174. exit when signal_mode = signal_space;
  175. --
  176. introduction;
  177. end loop introduction_loop;
  178. gameplay_loop: loop
  179. synchronize;
  180. --
  181. exit when engine_active = false;
  182. --
  183. gameplay;
  184. end loop gameplay_loop;
  185. ------------------------------------------------------------------------------------------
  186. deinitialize;
  187. dash;
  188. end main;