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.

224 line
9.1KB

  1. -- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic
  2. --
  3. -- GNU General Public Licence (version 3 or later)
  4. with ada.text_io, ada.strings.unbounded, interfaces.c, ray, system;
  5. use ada.text_io, ada.strings.unbounded, interfaces.c, ray, system;
  6. with ada.sequential_io;
  7. package core is
  8. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  9. type echo_status is (
  10. failure, warning, success, comment, import, export
  11. );
  12. type cursor_code is (
  13. cursor_none, cursor_left, cursor_right, cursor_middle
  14. );
  15. type signal_code is (
  16. signal_none, signal_space, signal_0, signal_1, signal_2, signal_3,
  17. signal_4, signal_5, signal_6, signal_7, signal_8, signal_9,
  18. signal_a, signal_b, signal_c, signal_d, signal_e, signal_f,
  19. signal_g, signal_h, signal_i, signal_j, signal_k, signal_l,
  20. signal_m, signal_n, signal_o, signal_p, signal_q, signal_r,
  21. signal_s, signal_t, signal_u, signal_v, signal_w, signal_x,
  22. signal_y, signal_z, signal_grave, signal_escape, signal_enter, signal_tab,
  23. signal_backspace, signal_right, signal_left, signal_down, signal_up, signal_kp_0,
  24. signal_kp_1, signal_kp_2, signal_kp_3, signal_kp_4, signal_kp_5, signal_kp_6,
  25. signal_kp_7, signal_kp_8, signal_kp_9, signal_kp_subtract, signal_kp_add, signal_left_shift,
  26. signal_left_control, signal_f1, signal_f2, signal_f3, signal_f4, signal_f5,
  27. signal_f6, signal_f7, signal_f8, signal_f9, signal_f10, signal_f11,
  28. signal_f12
  29. );
  30. type animation is (
  31. idle, walk, melee, shoot, wounded, dead
  32. );
  33. ------------------------------------------------------------------------------------------
  34. type colour_range is range 0 .. 2 ** 8 - 1;
  35. for colour_range'size use 8;
  36. type colour is record r, g, b, a : colour_range; end record;
  37. subtype short_string is string (1 .. 24);
  38. subtype long_string is string (1 .. 72);
  39. type pointer is access procedure;
  40. type address is new ray.pointer;
  41. type vector is record x, y : integer; end record;
  42. type sprite is record index, width, height, frames, states : integer; end record;
  43. type font is record index, scale, space : integer; end record;
  44. type song is record index : integer; end record;
  45. type point is record
  46. value, limit : natural;
  47. end record;
  48. type string_box_data is record
  49. data : access string := null;
  50. text : unbounded_string := null_unbounded_string;
  51. size : vector := (0, 0);
  52. end record;
  53. package io is new ada.sequential_io (integer);
  54. subtype unstring is ada.strings.unbounded.unbounded_string;
  55. --
  56. function bound (data : in unstring) return string renames ada.strings.unbounded.to_string;
  57. function unbound (data : in string) return unstring renames ada.strings.unbounded.to_unbounded_string;
  58. ------------------------------------------------------------------------------------------
  59. folder : constant string := ".";
  60. icon : constant natural := 32;
  61. base : constant natural := 16;
  62. gameplay_framerate : constant natural := 60;
  63. animation_framerate : constant natural := 4;
  64. echo_mark : constant array (echo_status) of boolean := (
  65. failure => true,
  66. warning => true,
  67. success => true,
  68. comment => true,
  69. import => true,
  70. export => true
  71. );
  72. engine_active : boolean := false;
  73. cursor : vector := (0, 0);
  74. camera : vector := (0, 0);
  75. cursor_mode : cursor_code := cursor_none;
  76. signal_mode : signal_code := signal_none;
  77. framerate : integer := 0;
  78. global_time : natural := 0;
  79. gameplay_time : natural := 0;
  80. animation_time : natural := 0;
  81. wheel : float := 0.0;
  82. zoom : natural := 1;
  83. help_box : string_box_data;
  84. text_box : string_box_data;
  85. global_image : ray.image;
  86. end_turn : boolean := false;
  87. ------------------------------------------------------------------------------------------
  88. function "=" (a, b : in signal_code) return boolean;
  89. function "=" (a, b : in cursor_code) return boolean;
  90. function "/" (a, b : in signal_code) return boolean;
  91. function "/" (a, b : in cursor_code) return boolean;
  92. function "+" (data : in point; modifier : in natural) return point;
  93. function "-" (data : in point; modifier : in natural) return point;
  94. function "*" (data : in point; modifier : in natural) return point;
  95. function "/" (data : in point; modifier : in natural) return point;
  96. function "+" (data : in string) return unstring;
  97. function "-" (data : in unstring) return string;
  98. procedure echo ( status : in echo_status; text : in string);
  99. procedure echo_when (condition : in boolean; status : in echo_status; text : in string);
  100. procedure dash;
  101. procedure semi_dash;
  102. function time return float;
  103. function compress (data : in address; size : in integer; used : out integer) return address;
  104. function decompress (data : in address; size : in integer; used : out integer) return address;
  105. --~procedure compress_file (file_path : in string);
  106. --~procedure decompress_file (file_path : in string);
  107. function c_string (ada_string : in string) return string;
  108. function random (minimum, maximum : in integer) return integer;
  109. procedure clip (value : in out integer; minimum, maximum : in integer);
  110. function lowercase (text : in string) return string;
  111. function window_width return integer;
  112. function window_height return integer;
  113. function center_x (object : in integer) return integer;
  114. function center_y (object : in integer) return integer;
  115. function cursor_inside (x, y, width, height : in integer) return boolean;
  116. function import_sprite (file_path : in string; frames, states : in integer) return sprite;
  117. function import_font (file_path : in string; scale, space : in integer) return font;
  118. function import_song (file_path : in string) return song;
  119. procedure import_text (data : in out string_box_data; file_path : in string);
  120. procedure create_image (width, height : in integer);
  121. procedure render_image (data : in sprite; x, y, u, v, width, height : in integer);
  122. procedure draw_pixel (x, y : in integer; tint : in colour);
  123. procedure export_image (file_path : in string);
  124. procedure draw (data : in sprite := (others => 0);
  125. x : in integer := 0;
  126. y : in integer := 0;
  127. u : in integer := 0;
  128. v : in integer := 0;
  129. width : in integer := 0;
  130. height : in integer := 0;
  131. ignore : in boolean := false;
  132. state : in animation := idle;
  133. factor : in integer := zoom;
  134. tint : in colour := (others => 255));
  135. procedure draw_horizontally (data : in sprite; x, y, width, factor : in integer; tint : in colour := (others => 255));
  136. procedure draw_vertically (data : in sprite; x, y, height, factor : in integer; tint : in colour := (others => 255));
  137. procedure write (text : in string := "";
  138. x : in integer := 0;
  139. y : in integer := 0;
  140. tint : in colour := (others => 255);
  141. size : in integer := 0;
  142. data : in font := (others => 0));
  143. procedure play (index : in integer);
  144. procedure stop (index : in integer);
  145. procedure overlay;
  146. function read_help_box return string;
  147. function read_text_box return string;
  148. procedure write_help_box (text : in string);
  149. procedure write_text_box (text : in string);
  150. procedure save_point (here : in core.io.file_type; data : in point);
  151. procedure load_point (here : in core.io.file_type; data : out point);
  152. procedure increment (value : in out integer; super : in natural := 1);
  153. procedure decrement (value : in out integer; super : in natural := 1);
  154. procedure idle_skip;
  155. procedure toggle_fullscreen;
  156. procedure initialize;
  157. procedure deinitialize;
  158. procedure synchronize;
  159. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  160. end core;