Prototype game engine for Heroes of Might & Magic, featuring a gameplay plot-twist...
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

221 líneas
9.4KB

  1. -- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic
  2. --
  3. -- GNU General Public Licence (version 3 or later)
  4. with core, ui, attribute, skill, resource, material, faction, equipment;
  5. package body chad is
  6. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  7. view_width : constant integer := 64;
  8. view_height : constant integer := 96;
  9. sprite : array (enumeration) of core.sprite;
  10. view : array (enumeration) of core.sprite;
  11. pepe_the_frog : core.sprite;
  12. alice_the_mad : core.sprite;
  13. ------------------------------------------------------------------------------------------
  14. procedure configure is
  15. begin
  16. core.echo (core.comment, "Configuring chad components...");
  17. --
  18. pepe_the_frog := core.import_sprite (core.folder & "/game/unit/pepe_the_frog.png", 4, 6);
  19. alice_the_mad := core.import_sprite (core.folder & "/game/unit/alice_the_mad.png", 4, 6);
  20. --
  21. for index in enumeration loop
  22. sprite (index) := core.import_sprite (core.folder & "/game/chad/" & core.lowercase (enumeration'image (index)) & ".png", 4, 6);
  23. view (index) := core.import_sprite (core.folder & "/view/chad/" & core.lowercase (enumeration'image (index)) & ".png", 1, 1);
  24. null;
  25. end loop;
  26. end configure;
  27. ------------------------------------------------------------------------------------------
  28. procedure draw (player : in information; x, y : in integer) is
  29. begin
  30. core.draw (sprite (player.index), x, y, state => player.state);
  31. --
  32. for index in equipment.slot loop
  33. core.draw (equipment.sprite (player.equipments (index)), x, y, state => player.state);
  34. end loop;
  35. end draw;
  36. ------------------------------------------------------------------------------------------
  37. procedure draw_data (player : in information; x, y : in integer) is
  38. offset : constant integer := 8;
  39. begin
  40. ui.draw_frame ("--", x, y, 360 + 2 * offset, 96 + 2 * offset);
  41. --
  42. ui.draw_sprite (view (player.index), description (player.index).name, x + offset, y + offset, 0);
  43. --
  44. ui.draw_tiny_fill_bar (x + view_width + 2 * offset, y + 1 * core.icon + offset, 360 - view_width - offset, float (player.health.value) / float (player.health.limit), (127, 0, 0, 255));
  45. ui.draw_tiny_fill_bar (x + view_width + 2 * offset, y + 2 * core.icon + offset, 360 - view_width - offset, float (player.mana.value) / float (player.mana.limit), (0, 0, 127, 255));
  46. ui.draw_tiny_fill_bar (x + view_width + 2 * offset, y + 3 * core.icon + offset, 360 - view_width - offset, float (player.movement.value) / float (player.movement.limit), (0, 127, 0, 255));
  47. --
  48. ui.write (text => "Health " & player.health.value'image & " /" & player.health.limit'image,
  49. x => x + view_width + core.icon + 3 * offset,
  50. y => y + 2 * offset,
  51. tint => (255, 127, 127, 255),
  52. size => 15,
  53. code => true);
  54. ui.write (text => "Mana " & player.mana.value'image & " /" & player.mana.limit'image,
  55. x => x + view_width + core.icon + 3 * offset,
  56. y => y + core.icon + 2 * offset,
  57. tint => (127, 127, 255, 255),
  58. size => 15,
  59. code => true);
  60. ui.write (text => "Stamina" & player.movement.value'image & " /" & player.movement.limit'image,
  61. x => x + view_width + core.icon + 3 * offset,
  62. y => y + 2 * core.icon + 2 * offset,
  63. tint => (127, 255, 127, 255),
  64. size => 15,
  65. code => true);
  66. --
  67. declare move_x : integer := x;
  68. begin
  69. for index in attribute.enumeration loop
  70. ui.draw_icon (attribute.icon (index), -(attribute.description (index).text), move_x, y + 96 + 3 * offset);
  71. ui.draw_text_box (move_x, y + 96 + 3 * offset + core.icon, core.icon, core.icon);
  72. ui.write (player.attributes (index).value'image, move_x + 4, y + 96 + 3 * offset + core.icon + 8, (255, 255, 255, 255), 15, true);
  73. --
  74. move_x := move_x + core.icon;
  75. end loop;
  76. end;
  77. --
  78. for index_y in 0 .. 3 loop
  79. for index_x in 0 .. 5 loop
  80. ui.draw_icon (data => equipment.icon (player.items (6 * index_y + index_x)),
  81. text => -(equipment.description (player.items (6 * index_y + index_x)).name),
  82. x => x + index_x * core.icon,
  83. y => y + 96 + 4 * offset + 2 * core.icon + index_y * core.icon);
  84. end loop;
  85. end loop;
  86. --
  87. declare move_x : integer := x;
  88. move_y : integer := y + 96 + 5 * offset + 6 * core.icon;
  89. begin
  90. for index in skill.enumeration loop
  91. if (skill.enumeration'pos (index) + 1) mod (skill.count / 2 + 1) = 0 then
  92. move_x := x + 2 * core.icon + 120;
  93. move_y := y + 96 + 5 * offset + 6 * core.icon;
  94. end if;
  95. --
  96. ui.draw_icon (skill.icon (index), -(skill.description (index).text), move_x, move_y);
  97. ui.draw_text_box (move_x + core.icon, move_y, core.icon, core.icon);
  98. ui.write (player.skills (index).value'image, move_x + core.icon, move_y + 8, (255, 255, 255, 255), 15, true);
  99. ui.write (-(skill.description (index).name), move_x + 2 * core.icon + 4, move_y + 8, (255, 255, 255, 255), 15, true);
  100. --
  101. move_y := move_y + core.icon;
  102. end loop;
  103. end;
  104. end draw_data;
  105. ------------------------------------------------------------------------------------------
  106. procedure draw_menu (player : in information; x, y : in integer) is
  107. begin
  108. null;
  109. end draw_menu;
  110. ------------------------------------------------------------------------------------------
  111. function take_equipment_item (player : in out information; item : in equipment.enumeration) return boolean is
  112. use type equipment.enumeration;
  113. begin
  114. if player.item_count = item_limit or item = equipment.none then
  115. return false;
  116. end if;
  117. --
  118. player.items (player.item_count) := item;
  119. --
  120. core.increment (player.item_count);
  121. --
  122. return true;
  123. end take_equipment_item;
  124. ------------------------------------------------------------------------------------------
  125. procedure draw_pepe is
  126. begin
  127. core.draw (pepe_the_frog, (core.window_width - core.base) / 2, (core.window_height - core.base) / 2);
  128. end draw_pepe;
  129. ------------------------------------------------------------------------------------------
  130. procedure draw_alice is
  131. begin
  132. core.draw (alice_the_mad, (core.window_width - core.base) / 2, (core.window_height - core.base) / 2);
  133. end draw_alice;
  134. ------------------------------------------------------------------------------------------
  135. procedure save_value (here : in core.io.file_type; data : in information) is
  136. begin
  137. core.io.write (here, enumeration'pos (data.index));
  138. core.io.write (here, core.animation'pos (data.state));
  139. core.io.write (here, data.x);
  140. core.io.write (here, data.y);
  141. --
  142. core.save_point (here, data.health);
  143. core.save_point (here, data.mana);
  144. core.save_point (here, data.movement);
  145. --
  146. for index in attribute.enumeration loop core.save_point (here, data.attributes (index)); end loop;
  147. for index in skill.enumeration loop core.save_point (here, data.skills (index)); end loop;
  148. for index in resource.enumeration loop core.save_point (here, data.resources (index)); end loop;
  149. for index in material.enumeration loop core.save_point (here, data.materials (index)); end loop;
  150. --
  151. for index in equipment.slot loop
  152. core.io.write (here, equipment.enumeration'pos (data.equipments (index)));
  153. end loop;
  154. --
  155. core.io.write (here, data.item_count);
  156. --
  157. if data.item_count > 0 then
  158. for index in 0 .. data.item_count - 1 loop
  159. core.io.write (here, equipment.enumeration'pos (data.items (index)));
  160. end loop;
  161. end if;
  162. end save_value;
  163. ------------------------------------------------------------------------------------------
  164. procedure load_value (here : in core.io.file_type; data : out information) is
  165. this : integer;
  166. begin
  167. core.io.read (here, this); data.index := enumeration'val (this);
  168. core.io.read (here, this); data.state := core.animation'val (this);
  169. core.io.read (here, data.x);
  170. core.io.read (here, data.y);
  171. --
  172. core.load_point (here, data.health);
  173. core.load_point (here, data.mana);
  174. core.load_point (here, data.movement);
  175. --
  176. for index in attribute.enumeration loop core.load_point (here, data.attributes (index)); end loop;
  177. for index in skill.enumeration loop core.load_point (here, data.skills (index)); end loop;
  178. for index in resource.enumeration loop core.load_point (here, data.resources (index)); end loop;
  179. for index in material.enumeration loop core.load_point (here, data.materials (index)); end loop;
  180. --
  181. for index in equipment.slot loop
  182. core.io.read (here, this); data.equipments (index) := equipment.enumeration'val (this);
  183. end loop;
  184. --
  185. core.io.read (here, data.item_count);
  186. --
  187. if data.item_count > 0 then
  188. for index in 0 .. data.item_count - 1 loop
  189. core.io.read (here, this); data.items (index) := equipment.enumeration'val (this);
  190. end loop;
  191. end if;
  192. end load_value;
  193. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  194. end chad;