Prototype game engine for Heroes of Might & Magic, featuring a gameplay plot-twist...
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

252 rindas
9.7KB

  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. type screen_view is (
  15. map_preview_panel, status_preview_panel, text_box_panel
  16. );
  17. screen_view_icon : array (screen_view) of core.sprite;
  18. screen_view_list : array (screen_view) of boolean := (others => true);
  19. screen_view_text : array (screen_view) of core.long_string := (
  20. "Toggle map preview panel. ",
  21. "Toggle status preview panel. ",
  22. "Toggle text box panel. "
  23. );
  24. procedure toggle_map_preview_panel is begin screen_view_list (map_preview_panel) := (if screen_view_list (map_preview_panel) then false else true); end toggle_map_preview_panel;
  25. procedure toggle_status_preview_panel is begin screen_view_list (status_preview_panel) := (if screen_view_list (status_preview_panel) then false else true); end toggle_status_preview_panel;
  26. procedure toggle_text_box_panel is begin screen_view_list (text_box_panel) := (if screen_view_list (text_box_panel) then false else true); end toggle_text_box_panel;
  27. screen_view_show : array (screen_view) of access procedure := (
  28. toggle_map_preview_panel'access,
  29. toggle_status_preview_panel'access,
  30. toggle_text_box_panel'access
  31. );
  32. ------------------------------------------------------------------------------------------
  33. -- TODO: This menu code is now useless due to new UI code.
  34. --~type menu_index is (
  35. --~menu_none, menu_attribute, menu_skill, menu_resource, menu_unit, menu_might, menu_magic
  36. --~);
  37. --~menu_limit : constant integer := 3;
  38. --~menu_count : integer := 0;
  39. --~menu_stack : array (1 .. menu_limit) of menu_index := (others => menu_none);
  40. --~procedure menu_insert (index : in menu_index) is
  41. --~begin
  42. --~if menu_count = menu_limit then return; end if;
  43. --~--
  44. --~menu_count := menu_count mod menu_limit + 1;
  45. --~--
  46. --~menu_stack (menu_count) := index;
  47. --~end menu_insert;
  48. --~procedure menu_remove is
  49. --~begin
  50. --~if menu_count = 0 then return; end if;
  51. --~--
  52. --~menu_stack (menu_count) := menu_none;
  53. --~--
  54. --~menu_count := menu_count - 1;
  55. --~end menu_remove;
  56. --~procedure menu_render is
  57. --~begin
  58. --~if menu_count > 0 then
  59. --~core.overlay; THIS SLOWS DOWN RENDERING BY 10 FRAMES!
  60. --~end if;
  61. --~--
  62. --~for index in 1 .. menu_limit loop
  63. --~case menu_stack (index) is
  64. --~when menu_none => null;
  65. --~when menu_attribute => attribute.menu (100, 100, false);
  66. --~when menu_skill => skill.menu (200, 200, false);
  67. --~when menu_resource => resource.menu (300, 300, false);
  68. --~when menu_unit => unit.menu (0, 0, true);
  69. --~when menu_might => might.menu (0, 0, true);
  70. --~when menu_magic => magic.menu (0, 0, true);
  71. --~end case;
  72. --~end loop;
  73. --~end menu_render;
  74. ------------------------------------------------------------------------------------------
  75. -- TODO: Also useless, delete later...
  76. --~procedure show_attribute_menu is begin menu_insert (menu_attribute); end show_attribute_menu;
  77. --~procedure show_skill_menu is begin menu_insert (menu_skill); end show_skill_menu;
  78. --~procedure show_resource_menu is begin menu_insert (menu_resource); end show_resource_menu;
  79. --~procedure show_unit_menu is begin menu_insert (menu_unit); end show_unit_menu;
  80. --~procedure show_might_menu is begin menu_insert (menu_might); end show_might_menu;
  81. --~procedure show_magic_menu is begin menu_insert (menu_magic); end show_magic_menu;
  82. procedure ui_main_style is begin ui.active := ui.style'val ((ui.style'pos (ui.active) + 1) mod 7); end ui_main_style;
  83. --~procedure hide_top_menu is begin menu_remove; end hide_top_menu;
  84. procedure zoom_in is begin core.zoom := 2; end zoom_in;
  85. procedure zoom_out is begin core.zoom := 1; end zoom_out;
  86. -- TODO: This is fine.
  87. signal_list : constant array (core.signal_code) of access procedure := (
  88. core.signal_up => core.move_camera_up'access,
  89. core.signal_down => core.move_camera_down'access,
  90. core.signal_left => core.move_camera_left'access,
  91. core.signal_right => core.move_camera_right'access,
  92. --~core.signal_a => show_attribute_menu'access,
  93. --~core.signal_s => show_skill_menu'access,
  94. --~core.signal_r => show_resource_menu'access,
  95. --~core.signal_u => show_unit_menu'access,
  96. --~core.signal_m => show_might_menu'access,
  97. --~core.signal_n => show_magic_menu'access,
  98. core.signal_v => ui_main_style'access,
  99. --~core.signal_grave => hide_top_menu'access,
  100. core.signal_kp_add => zoom_in'access,
  101. core.signal_kp_subtract => zoom_out'access,
  102. others => core.idle'access
  103. );
  104. a, b, c : core.sprite;
  105. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  106. begin
  107. core.dash;
  108. core.echo (core.comment, "Copyright (C) 2024 -- Ognjen 'xolatile' Milan Robovic");
  109. core.echo (core.comment, "Version -- 1.0.0");
  110. core.echo (core.comment, "License -- GNU/GPLv3+");
  111. 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.");
  112. core.dash;
  113. core.initialize;
  114. ui.configure;
  115. core.play (core.import_song (core.c_string ("./song/main_menu.ogg")).index);
  116. attribute.configure;
  117. skill.configure;
  118. resource.configure;
  119. --~might.configure;
  120. --~magic.configure;
  121. item.configure;
  122. unit.configure;
  123. construction.configure;
  124. chad.configure;
  125. world.configure;
  126. ai.configure;
  127. world.make (world.grass, 140, 120);
  128. core.dash;
  129. core.echo (core.success, "Successfully initialized game data, entering main gameplay loop.");
  130. core.dash;
  131. for index in screen_view loop
  132. screen_view_icon (index) := core.import_sprite ("./sprite/ui/icon/" & core.lowercase (screen_view'image (index)) & ".png", 1, 1);
  133. end loop;
  134. a := core.import_sprite ("./sprite/magic/fire/fireball.png", 1, 1);
  135. b := core.import_sprite ("./sprite/magic/light/heal.png", 1, 1);
  136. c := core.import_sprite ("./sprite/magic/dark/torment.png", 1, 1);
  137. ui.active := ui.imp;
  138. core.camera := (50, 50);
  139. ------------------------------------------------------------------------------------------
  140. gameplay: loop
  141. core.synchronize;
  142. --
  143. exit when core.engine_active = false;
  144. --
  145. if not screen_view_list (status_preview_panel) then
  146. side_panel := 0;
  147. else
  148. side_panel := core.window_width / 4;
  149. end if;
  150. --
  151. preview_width := core.window_width - side_panel;
  152. preview_height := core.window_height - text_box_height;
  153. text_box_height := 32;
  154. --
  155. core.camera.x := core.clip (core.camera.x, 0, world.map.width - 1);
  156. core.camera.y := core.clip (core.camera.y, 0, world.map.height - 1);
  157. --
  158. world.draw;
  159. --
  160. if screen_view_list (map_preview_panel) then
  161. ui.draw_menu (0, 0, preview_width, preview_height);
  162. end if;
  163. --
  164. if screen_view_list (status_preview_panel) then
  165. ui.draw_tiny_menu (preview_width, 0, side_panel, preview_height);
  166. ui.draw_state_box (preview_width + 32, 32);
  167. end if;
  168. --
  169. if screen_view_list (text_box_panel) then
  170. ui.draw_help_box (0, core.window_height - text_box_height, core.window_width - core.icon * (screen_view'pos (screen_view'last) + 1), text_box_height);
  171. end if;
  172. --
  173. for index in screen_view loop
  174. ui.draw_icon (screen_view_icon (index), screen_view_text (index),
  175. core.window_width - core.icon * (screen_view'pos (screen_view'last) + 1) + core.icon * screen_view'pos (index),
  176. core.window_height - text_box_height,
  177. screen_view_show (index));
  178. end loop;
  179. --
  180. signal_list (core.signal_code'val (core.signal_mode)).all;
  181. --
  182. --~magic.menu (0, 0, true);
  183. --~might.menu (0, 0, true);
  184. --
  185. --~ui.draw_menu (60, 60, 256, 256);
  186. --~ui.draw_tiny_menu (360, 60, 256, 256);
  187. --
  188. --~menu_render;
  189. --
  190. core.draw (a, 64*1, core.window_height - 56 - 64);
  191. core.draw (b, 64*2, core.window_height - 56 - 64);
  192. core.draw (c, 64*3, core.window_height - 56 - 64);
  193. ui.draw_icon_menu ("", 64*1, core.window_height - 56 - 64, 64, 64, null);
  194. ui.draw_icon_menu ("", 64*2, core.window_height - 56 - 64, 64, 64, null);
  195. ui.draw_icon_menu ("", 64*3, core.window_height - 56 - 64, 64, 64, null);
  196. ui.draw_fill_bar (64*4, core.window_height - 56, 320, 0.7);
  197. --
  198. chad.draw_alice;
  199. --
  200. ui.synchronize;
  201. end loop gameplay;
  202. ------------------------------------------------------------------------------------------
  203. core.deinitialize;
  204. core.dash;
  205. end main;