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.

188 lines
6.8KB

  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, world, ai;
  6. procedure main is
  7. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  8. side_panel : integer := 0;
  9. preview_width : integer := 0;
  10. preview_height : integer := 0;
  11. text_box_height : integer := 0;
  12. player : chad.information := chad.trait (chad.ognjen);
  13. ------------------------------------------------------------------------------------------
  14. -- TODO: This menu code is now useless due to new UI code.
  15. type menu_index is (
  16. menu_none, menu_attribute, menu_skill, menu_resource, menu_unit, menu_might, menu_magic
  17. );
  18. menu_limit : constant integer := 3;
  19. menu_count : integer := 0;
  20. menu_stack : array (1 .. menu_limit) of menu_index := (others => menu_none);
  21. procedure menu_insert (index : in menu_index) is
  22. begin
  23. if menu_count = menu_limit then return; end if;
  24. --
  25. menu_count := menu_count mod menu_limit + 1;
  26. --
  27. menu_stack (menu_count) := index;
  28. end menu_insert;
  29. procedure menu_remove is
  30. begin
  31. if menu_count = 0 then return; end if;
  32. --
  33. menu_stack (menu_count) := menu_none;
  34. --
  35. menu_count := menu_count - 1;
  36. end menu_remove;
  37. procedure menu_render is
  38. begin
  39. --~if menu_count > 0 then
  40. --~core.overlay; THIS SLOWS DOWN RENDERING BY 10 FRAMES!
  41. --~end if;
  42. --
  43. for index in 1 .. menu_limit loop
  44. case menu_stack (index) is
  45. when menu_none => null;
  46. when menu_attribute => attribute.menu (100, 100, false);
  47. when menu_skill => skill.menu (200, 200, false);
  48. when menu_resource => resource.menu (300, 300, false);
  49. when menu_unit => unit.menu (0, 0, true);
  50. when menu_might => might.menu (0, 0, true);
  51. when menu_magic => magic.menu (0, 0, true);
  52. end case;
  53. end loop;
  54. end menu_render;
  55. ------------------------------------------------------------------------------------------
  56. -- TODO: Also useless, delete later...
  57. procedure show_attribute_menu is begin menu_insert (menu_attribute); end show_attribute_menu;
  58. procedure show_skill_menu is begin menu_insert (menu_skill); end show_skill_menu;
  59. procedure show_resource_menu is begin menu_insert (menu_resource); end show_resource_menu;
  60. procedure show_unit_menu is begin menu_insert (menu_unit); end show_unit_menu;
  61. procedure show_might_menu is begin menu_insert (menu_might); end show_might_menu;
  62. procedure show_magic_menu is begin menu_insert (menu_magic); end show_magic_menu;
  63. procedure ui_main_style is begin ui.active := ui.style'val ((ui.style'pos (ui.active) + 1) mod 7); end ui_main_style;
  64. procedure hide_top_menu is begin menu_remove; end hide_top_menu;
  65. procedure zoom_in is begin core.zoom := 2; end zoom_in;
  66. procedure zoom_out is begin core.zoom := 1; end zoom_out;
  67. -- TODO: This is fine.
  68. signal_list : constant array (core.signal_code) of access procedure := (
  69. core.signal_up => core.move_camera_up'access,
  70. core.signal_down => core.move_camera_down'access,
  71. core.signal_left => core.move_camera_left'access,
  72. core.signal_right => core.move_camera_right'access,
  73. core.signal_a => show_attribute_menu'access,
  74. core.signal_s => show_skill_menu'access,
  75. core.signal_r => show_resource_menu'access,
  76. core.signal_u => show_unit_menu'access,
  77. core.signal_m => show_might_menu'access,
  78. core.signal_n => show_magic_menu'access,
  79. core.signal_v => ui_main_style'access,
  80. core.signal_grave => hide_top_menu'access,
  81. core.signal_kp_add => zoom_in'access,
  82. core.signal_kp_subtract => zoom_out'access,
  83. others => core.idle'access
  84. );
  85. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  86. begin
  87. core.dash;
  88. core.echo (core.comment, "Copyright (C) 2024 -- Ognjen 'xolatile' Milan Robovic");
  89. core.echo (core.comment, "Version -- 1.0.0");
  90. core.echo (core.comment, "License -- GNU/GPLv3+");
  91. core.echo (core.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.");
  92. core.dash;
  93. core.initialize;
  94. ui.configure;
  95. core.play (core.import_song (core.c_string ("./song/main_menu.ogg")).index);
  96. attribute.configure;
  97. skill.configure;
  98. resource.configure;
  99. --~might.configure;
  100. --~magic.configure;
  101. item.configure;
  102. unit.configure;
  103. construction.configure;
  104. chad.configure;
  105. world.configure;
  106. ai.configure;
  107. world.make (world.grass, 140, 120);
  108. core.dash;
  109. core.echo (core.success, "Successfully initialized game data, entering main gameplay loop.");
  110. core.dash;
  111. ------------------------------------------------------------------------------------------
  112. gameplay: loop
  113. core.synchronize;
  114. --
  115. exit when core.engine_active = false;
  116. --
  117. side_panel := core.window_width / 4;
  118. preview_width := core.window_width - side_panel;
  119. preview_height := core.window_height - text_box_height;
  120. text_box_height := 32;
  121. --
  122. core.camera.x := core.clip (core.camera.x, 0, world.map.width - 1);
  123. core.camera.y := core.clip (core.camera.y, 0, world.map.height - 1);
  124. --
  125. world.draw;
  126. --
  127. ui.draw_menu (0, 0, preview_width, preview_height);
  128. ui.draw_tiny_menu (preview_width, 0, side_panel, preview_height);
  129. --
  130. ui.draw_state_box (preview_width + 32, 32);
  131. --
  132. signal_list (core.signal_code'val (core.signal_mode)).all;
  133. --
  134. --~magic.menu (0, 0, true);
  135. --~might.menu (0, 0, true);
  136. --
  137. --~ui.draw_menu (60, 60, 256, 256);
  138. --~ui.draw_tiny_menu (360, 60, 256, 256);
  139. --
  140. menu_render;
  141. --
  142. --~ui.draw_fill_bar (64, core.window_height - 56, 320, 0.7);
  143. --
  144. chad.draw_alice;
  145. --
  146. ui.synchronize;
  147. --
  148. ui.draw_help_box (0, core.window_height - text_box_height, core.window_width, text_box_height);
  149. end loop gameplay;
  150. ------------------------------------------------------------------------------------------
  151. core.deinitialize;
  152. core.dash;
  153. end main;