Prototype game engine for Heroes of Might & Magic, featuring a gameplay plot-twist...
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

275 satır
9.3KB

  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. --~with Ada.Text_IO; -- For text input/output operations
  9. --~with Ada.Text_IO.Text_Streams; -- For text file handling
  10. --~with Ada.Strings.Unbounded; -- For unbounded string handling
  11. procedure main is
  12. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  13. side_panel : integer := 0;
  14. preview_width : integer := 0;
  15. preview_height : integer := 0;
  16. text_box_height : integer := 0;
  17. player : chad.information := chad.trait (chad.ognjen);
  18. ------------------------------------------------------------------------------------------
  19. type view is (
  20. map_preview_panel, status_preview_panel, text_box_panel
  21. );
  22. view_icon : array (view) of sprite := (others => (others => 0));
  23. view_list : array (view) of boolean := (others => true);
  24. view_text : array (view) of long_string := (
  25. "Toggle map preview panel. ",
  26. "Toggle status preview panel. ",
  27. "Toggle text box panel. "
  28. );
  29. procedure swap_map_preview_panel is begin view_list (map_preview_panel) := not view_list (map_preview_panel); end swap_map_preview_panel;
  30. procedure swap_status_preview_panel is begin view_list (status_preview_panel) := not view_list (status_preview_panel); end swap_status_preview_panel;
  31. procedure swap_text_box_panel is begin view_list (text_box_panel) := not view_list (text_box_panel); end swap_text_box_panel;
  32. view_show : array (view) of access procedure := (
  33. swap_map_preview_panel'access,
  34. swap_status_preview_panel'access,
  35. swap_text_box_panel'access
  36. );
  37. game_title : sprite;
  38. ashland_preview : sprite;
  39. ------------------------------------------------------------------------------------------
  40. procedure check_move_camera_up is
  41. begin
  42. move_camera_up;
  43. camera.y := clip (camera.y, 0, world.map.height - 1);
  44. if world.map.clips (camera.x, camera.y) then
  45. increment (camera.y);
  46. end if;
  47. end check_move_camera_up;
  48. procedure check_move_camera_down is
  49. begin
  50. move_camera_down;
  51. camera.y := clip (camera.y, 0, world.map.height - 1);
  52. if world.map.clips (camera.x, camera.y) then
  53. decrement (camera.y);
  54. end if;
  55. end check_move_camera_down;
  56. procedure check_move_camera_left is
  57. begin
  58. move_camera_left;
  59. camera.x := clip (camera.x, 0, world.map.width - 1);
  60. if world.map.clips (camera.x, camera.y) then
  61. increment (camera.x);
  62. end if;
  63. end check_move_camera_left;
  64. procedure check_move_camera_right is
  65. begin
  66. move_camera_right;
  67. camera.x := clip (camera.x, 0, world.map.width - 1);
  68. if world.map.clips (camera.x, camera.y) then
  69. decrement (camera.x);
  70. end if;
  71. end check_move_camera_right;
  72. procedure ui_main_style is
  73. begin
  74. ui.active := ui.style'val ((ui.style'pos (ui.active) + 1) mod (ui.style'pos (ui.style'last) + 1));
  75. end ui_main_style;
  76. procedure zoom_in is begin zoom := 2; end zoom_in;
  77. procedure zoom_out is begin zoom := 1; end zoom_out;
  78. signal_list : constant array (signal_code) of access procedure := (
  79. signal_up => check_move_camera_up'access,
  80. signal_down => check_move_camera_down'access,
  81. signal_left => check_move_camera_left'access,
  82. signal_right => check_move_camera_right'access,
  83. signal_v => ui_main_style'access,
  84. signal_kp_add => zoom_in'access,
  85. signal_kp_subtract => zoom_out'access,
  86. others => idle_skip'access
  87. );
  88. ------------------------------------------------------------------------------------------
  89. procedure introduction is
  90. begin
  91. draw (ashland_preview, center_x (ashland_preview.width * 2), center_y (ashland_preview.height * 2), factor => 2);
  92. draw (game_title, center_x (game_title.width * 2), center_y (game_title.height * 2), factor => 2);
  93. --
  94. write ("[-- Please press Spacebar to continue]", 0, center_y (24), (102, 102, 102, 255));
  95. end introduction;
  96. ------------------------------------------------------------------------------------------
  97. --~File : Ada.Text_IO.File_Type;
  98. --~Line : Ada.Strings.Unbounded.unbounded_string;
  99. procedure main_menu is
  100. begin
  101. draw (ashland_preview, center_x (ashland_preview.width * 2), center_y (ashland_preview.height * 2), factor => 2);
  102. draw (game_title, center_x (game_title.width * 2), center_y (game_title.height * 2), factor => 2);
  103. --
  104. write ("Main Menu", 0, 0);
  105. --~write (Ada.Strings.Unbounded.To_String (Line), 64, 64);
  106. --
  107. ui.draw_check_box (0, 32, view_list (map_preview_panel), "map_preview_panel");
  108. ui.draw_check_box (0, 64, view_list (status_preview_panel), "status_preview_panel");
  109. ui.draw_check_box (0, 96, view_list (text_box_panel), "text_box_panel");
  110. end main_menu;
  111. ------------------------------------------------------------------------------------------
  112. procedure gameplay is
  113. begin
  114. if not view_list (status_preview_panel) then
  115. side_panel := 0;
  116. else
  117. side_panel := window_width / 4;
  118. end if;
  119. --
  120. preview_width := window_width - side_panel;
  121. preview_height := window_height - text_box_height;
  122. text_box_height := 32;
  123. --
  124. world.draw;
  125. --
  126. if view_list (map_preview_panel) then
  127. ui.draw_menu (0, 0, preview_width, preview_height);
  128. end if;
  129. --
  130. if view_list (status_preview_panel) then
  131. ui.draw_tiny_menu (preview_width, 0, side_panel, preview_height);
  132. ui.draw_state_box (preview_width + 32, 32);
  133. end if;
  134. --
  135. if view_list (text_box_panel) then
  136. ui.draw_help_box (0, window_height - text_box_height, window_width - icon * (view'pos (view'last) + 1), text_box_height);
  137. end if;
  138. --
  139. for index in view loop
  140. ui.draw_icon (view_icon (index), view_text (index),
  141. window_width - icon * (view'pos (view'last) + 1) + icon * view'pos (index),
  142. window_height - text_box_height,
  143. view_show (index));
  144. end loop;
  145. --
  146. signal_list (signal_mode).all;
  147. --
  148. --~magic.menu (0, 0, true);
  149. --~might.menu (0, 0, true);
  150. --
  151. chad.draw_alice;
  152. --
  153. ui.synchronize;
  154. end gameplay;
  155. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  156. begin
  157. --~Ada.Text_IO.Open(File, Ada.Text_IO.In_File, "./design/core.txt"); -- Open the file for reading
  158. --~while not Ada.Text_IO.End_Of_File(File) loop
  159. --~Line := Ada.Strings.Unbounded.To_Unbounded_String (Ada.Strings.Unbounded.To_String (Line) & Character'Val (10) & Character'Val (10) & Ada.Text_IO.Get_Line(File)); -- Read a line from the file
  160. --~Line := Line & Ada.Strings.Unbounded.To_Unbounded_String (Ada.Text_IO.Get_Line(File)); -- Read a line from the file
  161. --~Ada.Text_IO.Put_Line(Ada.Strings.Unbounded.To_String (Line)); -- Output the line to the console
  162. --~Ada.Text_IO.Put_Line (">");
  163. --~end loop;
  164. --~Ada.Text_IO.Close(File); -- Close the file after reading
  165. dash;
  166. echo (comment, "Copyright (C) 2024 -- Ognjen 'xolatile' Milan Robovic");
  167. echo (comment, "Version -- 1.0.0");
  168. echo (comment, "License -- GNU/GPLv3+");
  169. 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.");
  170. dash;
  171. initialize;
  172. ui.configure;
  173. play (import_song (c_string ("./song/main_menu.ogg")).index);
  174. attribute.configure;
  175. skill.configure;
  176. resource.configure;
  177. --~might.configure;
  178. --~magic.configure;
  179. item.configure;
  180. unit.configure;
  181. construction.configure;
  182. chad.configure;
  183. world.configure;
  184. --~ai.configure;
  185. world.make (world.swamp, 120, 60);
  186. dash;
  187. echo (success, "Successfully initialized game data, entering main gameplay loop.");
  188. dash;
  189. for index in view loop
  190. view_icon (index) := import_sprite ("./sprite/ui/icon/" & lowercase (view'image (index)) & ".png", 1, 1);
  191. end loop;
  192. ui.active := ui.imp;
  193. camera := (1, 1);
  194. game_title := import_sprite ("./sprite/game_title.png", 1, 1);
  195. ashland_preview := import_sprite ("./sprite/ashland_preview.png", 1, 1);
  196. ------------------------------------------------------------------------------------------
  197. introduction_loop: loop
  198. synchronize;
  199. --
  200. exit when signal_mode = signal_space;
  201. --
  202. introduction;
  203. end loop introduction_loop;
  204. main_menu_loop: loop
  205. synchronize;
  206. --
  207. exit when signal_mode = signal_a;
  208. --
  209. main_menu;
  210. end loop main_menu_loop;
  211. gameplay_loop: loop
  212. synchronize;
  213. --
  214. exit when engine_active = false;
  215. --
  216. gameplay;
  217. end loop gameplay_loop;
  218. mapshot ("./test.png");
  219. ------------------------------------------------------------------------------------------
  220. deinitialize;
  221. dash;
  222. end main;