xhads/source/chad.adb

221 lines
9.4 KiB
Ada

-- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic
--
-- GNU General Public Licence (version 3 or later)
with core, ui, attribute, skill, resource, material, faction, equipment;
package body chad is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
view_width : constant integer := 64;
view_height : constant integer := 96;
sprite : array (enumeration) of core.sprite;
view : array (enumeration) of core.sprite;
pepe_the_frog : core.sprite;
alice_the_mad : core.sprite;
------------------------------------------------------------------------------------------
procedure configure is
begin
core.echo (core.comment, "Configuring chad components...");
--
pepe_the_frog := core.import_sprite (core.folder & "/game/unit/pepe_the_frog.png", 4, 6);
alice_the_mad := core.import_sprite (core.folder & "/game/unit/alice_the_mad.png", 4, 6);
--
for index in enumeration loop
sprite (index) := core.import_sprite (core.folder & "/game/chad/" & core.lowercase (enumeration'image (index)) & ".png", 4, 6);
view (index) := core.import_sprite (core.folder & "/view/chad/" & core.lowercase (enumeration'image (index)) & ".png", 1, 1);
null;
end loop;
end configure;
------------------------------------------------------------------------------------------
procedure draw (player : in information; x, y : in integer) is
begin
core.draw (sprite (player.index), x, y, state => player.state);
--
for index in equipment.slot loop
equipment.draw (player.equipments (index), player.state, x, y);
end loop;
end draw;
------------------------------------------------------------------------------------------
procedure draw_data (player : in information; x, y : in integer) is
offset : constant integer := 8;
begin
ui.draw_frame ("--", x, y, 360 + 2 * offset, 96 + 2 * offset);
--
ui.draw_sprite (view (player.index), description (player.index).name, x + offset, y + offset, 0);
--
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));
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));
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));
--
ui.write (text => "Health " & player.health.value'image & " /" & player.health.limit'image,
x => x + view_width + core.icon + 3 * offset,
y => y + 2 * offset,
tint => (255, 127, 127, 255),
size => 15,
code => true);
ui.write (text => "Mana " & player.mana.value'image & " /" & player.mana.limit'image,
x => x + view_width + core.icon + 3 * offset,
y => y + core.icon + 2 * offset,
tint => (127, 127, 255, 255),
size => 15,
code => true);
ui.write (text => "Stamina" & player.movement.value'image & " /" & player.movement.limit'image,
x => x + view_width + core.icon + 3 * offset,
y => y + 2 * core.icon + 2 * offset,
tint => (127, 255, 127, 255),
size => 15,
code => true);
--
declare move_x : integer := x;
begin
for index in attribute.enumeration loop
ui.draw_icon (attribute.icon (index), -(attribute.description (index).text), move_x, y + 96 + 3 * offset);
ui.draw_text_box (move_x, y + 96 + 3 * offset + core.icon, core.icon, core.icon);
ui.write (player.attributes (index).value'image, move_x + 4, y + 96 + 3 * offset + core.icon + 8, (255, 255, 255, 255), 15, true);
--
move_x := move_x + core.icon;
end loop;
end;
--
for index_y in 0 .. 3 loop
for index_x in 0 .. 5 loop
ui.draw_icon (data => equipment.icon (player.items (6 * index_y + index_x)),
text => -(equipment.description (player.items (6 * index_y + index_x)).name),
x => x + index_x * core.icon,
y => y + 96 + 4 * offset + 2 * core.icon + index_y * core.icon);
end loop;
end loop;
--
declare move_x : integer := x;
move_y : integer := y + 96 + 5 * offset + 6 * core.icon;
begin
for index in skill.enumeration loop
if (skill.enumeration'pos (index) + 1) mod (skill.count / 2 + 1) = 0 then
move_x := x + 2 * core.icon + 120;
move_y := y + 96 + 5 * offset + 6 * core.icon;
end if;
--
ui.draw_icon (skill.icon (index), -(skill.description (index).text), move_x, move_y);
ui.draw_text_box (move_x + core.icon, move_y, core.icon, core.icon);
ui.write (player.skills (index).value'image, move_x + core.icon, move_y + 8, (255, 255, 255, 255), 15, true);
ui.write (-(skill.description (index).name), move_x + 2 * core.icon + 4, move_y + 8, (255, 255, 255, 255), 15, true);
--
move_y := move_y + core.icon;
end loop;
end;
end draw_data;
------------------------------------------------------------------------------------------
procedure draw_menu (player : in information; x, y : in integer) is
begin
null;
end draw_menu;
------------------------------------------------------------------------------------------
function take_equipment_item (player : in out information; item : in equipment.enumeration) return boolean is
use type equipment.enumeration;
begin
if player.item_count = item_limit or item = equipment.none then
return false;
end if;
--
player.items (player.item_count) := item;
--
core.increment (player.item_count);
--
return true;
end take_equipment_item;
------------------------------------------------------------------------------------------
procedure draw_pepe is
begin
core.draw (pepe_the_frog, (core.window_width - core.base) / 2, (core.window_height - core.base) / 2);
end draw_pepe;
------------------------------------------------------------------------------------------
procedure draw_alice is
begin
core.draw (alice_the_mad, (core.window_width - core.base) / 2, (core.window_height - core.base) / 2);
end draw_alice;
------------------------------------------------------------------------------------------
procedure save_value (here : in core.io.file_type; data : in information) is
begin
core.io.write (here, enumeration'pos (data.index));
core.io.write (here, core.animation'pos (data.state));
core.io.write (here, data.x);
core.io.write (here, data.y);
--
core.save_point (here, data.health);
core.save_point (here, data.mana);
core.save_point (here, data.movement);
--
for index in attribute.enumeration loop core.save_point (here, data.attributes (index)); end loop;
for index in skill.enumeration loop core.save_point (here, data.skills (index)); end loop;
for index in resource.enumeration loop core.save_point (here, data.resources (index)); end loop;
for index in material.enumeration loop core.save_point (here, data.materials (index)); end loop;
--
for index in equipment.slot loop
core.io.write (here, equipment.enumeration'pos (data.equipments (index)));
end loop;
--
core.io.write (here, data.item_count);
--
if data.item_count > 0 then
for index in 0 .. data.item_count - 1 loop
core.io.write (here, equipment.enumeration'pos (data.items (index)));
end loop;
end if;
end save_value;
------------------------------------------------------------------------------------------
procedure load_value (here : in core.io.file_type; data : out information) is
this : integer;
begin
core.io.read (here, this); data.index := enumeration'val (this);
core.io.read (here, this); data.state := core.animation'val (this);
core.io.read (here, data.x);
core.io.read (here, data.y);
--
core.load_point (here, data.health);
core.load_point (here, data.mana);
core.load_point (here, data.movement);
--
for index in attribute.enumeration loop core.load_point (here, data.attributes (index)); end loop;
for index in skill.enumeration loop core.load_point (here, data.skills (index)); end loop;
for index in resource.enumeration loop core.load_point (here, data.resources (index)); end loop;
for index in material.enumeration loop core.load_point (here, data.materials (index)); end loop;
--
for index in equipment.slot loop
core.io.read (here, this); data.equipments (index) := equipment.enumeration'val (this);
end loop;
--
core.io.read (here, data.item_count);
--
if data.item_count > 0 then
for index in 0 .. data.item_count - 1 loop
core.io.read (here, this); data.items (index) := equipment.enumeration'val (this);
end loop;
end if;
end load_value;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end chad;