Added unit+items to world drawing procedure...

This commit is contained in:
Ognjen Milan Robovic 2024-05-09 05:07:20 -04:00
parent 7e660f394a
commit dad2e46c34
11 changed files with 91 additions and 57 deletions

View File

@ -211,8 +211,14 @@ package body core is
new_tint : ray.colour := (ray.colour_range (tint.r), ray.colour_range (tint.g), ray.colour_range (tint.b), ray.colour_range (tint.a)); new_tint : ray.colour := (ray.colour_range (tint.r), ray.colour_range (tint.g), ray.colour_range (tint.b), ray.colour_range (tint.a));
begin begin
ray.draw_texture (data => texture_array (data.index), ray.draw_texture (data => texture_array (data.index),
uv => (float (if u = 0 then (animation_time mod data.frames) * data.width else u), float (v), new_width, new_height), uv => (x => float (if u > 0 then u else (animation_time mod data.frames) * data.width),
view => (float (x), float (y), new_width * float (factor), new_height * float (factor)), y => float (if state = 0 then v else (state mod data.states) * data.height),
width => new_width,
height => new_height),
view => (x => float (x),
y => float (y),
width => new_width * float (factor),
height => new_height * float (factor)),
tint => new_tint); tint => new_tint);
end draw; end draw;
@ -280,7 +286,7 @@ package body core is
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
procedure idle is begin null; end idle; procedure idle_skip is begin null; end idle_skip;
procedure move_camera_up is begin core.camera.y := core.camera.y - 1; end move_camera_up; procedure move_camera_up is begin core.camera.y := core.camera.y - 1; end move_camera_up;
procedure move_camera_down is begin core.camera.y := core.camera.y + 1; end move_camera_down; procedure move_camera_down is begin core.camera.y := core.camera.y + 1; end move_camera_down;

View File

@ -27,6 +27,12 @@ package core is
signal_left_control signal_left_control
); );
type animation is (
idle, walk, melee, shoot, wounded, dead
);
------------------------------------------------------------------------------------------
type colour_range is range 0 .. 2 ** 8 - 1; type colour_range is range 0 .. 2 ** 8 - 1;
for colour_range'size use 8; for colour_range'size use 8;
@ -151,7 +157,7 @@ package core is
procedure increment (value : in out integer); procedure increment (value : in out integer);
procedure decrement (value : in out integer); procedure decrement (value : in out integer);
procedure idle; procedure idle_skip;
procedure move_camera_up; procedure move_camera_up;
procedure move_camera_down; procedure move_camera_down;
procedure move_camera_left; procedure move_camera_left;

View File

@ -27,9 +27,9 @@ package body item is
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
procedure draw (index : in enumeration; x, y : in integer) is procedure draw (index : in enumeration; state : in core.animation; x, y : in integer) is
begin begin
core.draw (sprite (index), x, y); core.draw (sprite (index), x, y, state => core.animation'pos (state));
end draw; end draw;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -9,8 +9,8 @@ package item is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
type slot is ( type slot is (
with_body, full_body, head, chest, hands, feet, full_body, head, chest, hands, feet,
neck, main_hand, off_hand, bag, cloak, additional neck, main_hand, off_hand
); );
type enumeration is ( type enumeration is (
@ -45,6 +45,13 @@ package item is
evoke : effect.enumeration; evoke : effect.enumeration;
end record; end record;
type value is record
index : enumeration;
allow : boolean;
end record;
type list is array (slot) of value;
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
count : constant natural := enumeration'pos (enumeration'last) + 1; count : constant natural := enumeration'pos (enumeration'last) + 1;
@ -163,7 +170,7 @@ package item is
procedure configure; procedure configure;
procedure draw (index : in enumeration; x, y : in integer); procedure draw (index : in enumeration; state : in core.animation; x, y : in integer);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -98,7 +98,7 @@ procedure main is
signal_v => ui_main_style'access, signal_v => ui_main_style'access,
signal_kp_add => zoom_in'access, signal_kp_add => zoom_in'access,
signal_kp_subtract => zoom_out'access, signal_kp_subtract => zoom_out'access,
others => idle'access others => idle_skip'access
); );
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------

View File

@ -84,7 +84,7 @@ package body ui is
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
procedure draw_horizontally (index : in element; x, y, width : in integer; action : core.pointer := core.idle'access) is procedure draw_horizontally (index : in element; x, y, width : in integer; action : core.pointer := core.idle_skip'access) is
step : constant integer := sprite (active, index).width; step : constant integer := sprite (active, index).width;
begin begin
for move in 0 .. width / step - 1 loop for move in 0 .. width / step - 1 loop
@ -103,7 +103,7 @@ package body ui is
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
procedure draw_vertically (index : in element; x, y, height : in integer; action : core.pointer := core.idle'access) is procedure draw_vertically (index : in element; x, y, height : in integer; action : core.pointer := core.idle_skip'access) is
step : constant integer := sprite (active, index).height; step : constant integer := sprite (active, index).height;
begin begin
for move in 0 .. height / step - 1 loop for move in 0 .. height / step - 1 loop
@ -122,7 +122,7 @@ package body ui is
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
procedure draw_background (index : in element; x, y, width, height : in integer; action : core.pointer := core.idle'access) is procedure draw_background (index : in element; x, y, width, height : in integer; action : core.pointer := core.idle_skip'access) is
base_width : integer := sprite (active, index).width; base_width : integer := sprite (active, index).width;
base_height : integer := sprite (active, index).height; base_height : integer := sprite (active, index).height;
crop_width : integer := width mod base_width; crop_width : integer := width mod base_width;
@ -246,7 +246,7 @@ package body ui is
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
procedure draw_icon (data : in core.sprite; description : in string; x, y : in integer; action : core.pointer := core.idle'access) is procedure draw_icon (data : in core.sprite; description : in string; x, y : in integer; action : core.pointer := core.idle_skip'access) is
save_zoom : natural := core.zoom; save_zoom : natural := core.zoom;
begin begin
draw (icon, x, y); draw (icon, x, y);
@ -269,7 +269,7 @@ package body ui is
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
procedure draw_overicon (data : in core.sprite; description : in string; x, y : in integer; action : core.pointer := core.idle'access) is procedure draw_overicon (data : in core.sprite; description : in string; x, y : in integer; action : core.pointer := core.idle_skip'access) is
save_zoom : natural := core.zoom; save_zoom : natural := core.zoom;
begin begin
core.zoom := 1; core.zoom := 1;
@ -305,7 +305,7 @@ package body ui is
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
procedure draw_help_box (x, y, width, height : in integer; action : core.pointer := core.idle'access) is procedure draw_help_box (x, y, width, height : in integer; action : core.pointer := core.idle_skip'access) is
offset : constant integer := sprite (active, text_middle).width; offset : constant integer := sprite (active, text_middle).width;
begin begin
draw_background (text_middle, x + offset, y + offset, width - 2 * offset, height - 2 * offset); draw_background (text_middle, x + offset, y + offset, width - 2 * offset, height - 2 * offset);
@ -325,7 +325,7 @@ package body ui is
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
procedure draw_frame (description : in string; x, y, width, height : in integer; action : core.pointer := core.idle'access) is procedure draw_frame (description : in string; x, y, width, height : in integer; action : core.pointer := core.idle_skip'access) is
offset_x : constant integer := sprite (active, frame_middle).width; offset_x : constant integer := sprite (active, frame_middle).width;
offset_y : constant integer := sprite (active, frame_middle).height; offset_y : constant integer := sprite (active, frame_middle).height;
begin begin

View File

@ -57,14 +57,14 @@ package ui is
procedure write (text : in string; x, y : in integer; tint : in core.colour := (others => 255); size : in natural := 0); procedure write (text : in string; x, y : in integer; tint : in core.colour := (others => 255); size : in natural := 0);
procedure draw_icon (data : in core.sprite; description : in string; x, y : in integer; action : core.pointer := core.idle'access); procedure draw_icon (data : in core.sprite; description : in string; x, y : in integer; action : core.pointer := core.idle_skip'access);
procedure draw_overicon (data : in core.sprite; description : in string; x, y : in integer; action : core.pointer := core.idle'access); procedure draw_overicon (data : in core.sprite; description : in string; x, y : in integer; action : core.pointer := core.idle_skip'access);
procedure draw_text_box (text : in string); procedure draw_text_box (text : in string);
procedure draw_help_box (x, y, width, height : in integer; action : core.pointer := core.idle'access); procedure draw_help_box (x, y, width, height : in integer; action : core.pointer := core.idle_skip'access);
procedure draw_frame (description : in string; x, y, width, height : in integer; action : core.pointer := core.idle'access); procedure draw_frame (description : in string; x, y, width, height : in integer; action : core.pointer := core.idle_skip'access);
procedure draw_title_bar (x, y, width : in integer; title : in string); procedure draw_title_bar (x, y, width : in integer; title : in string);
procedure draw_fill_bar (x, y, width : in integer; fill : in float); procedure draw_fill_bar (x, y, width : in integer; fill : in float);

View File

@ -34,9 +34,9 @@ package body unit is
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
procedure draw (index : in enumeration; state : in animation; x, y : in integer) is procedure draw (index : in enumeration; state : in core.animation; x, y : in integer) is
begin begin
core.draw (sprite (index), x, y, 6, animation'pos (state)); core.draw (sprite (index), x, y, state => core.animation'pos (state));
end draw; end draw;
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
@ -57,33 +57,16 @@ package body unit is
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
procedure stat (index : in enumeration; x, y : in integer; center : in boolean) is procedure full_draw (data : in value; x, y : in integer) is
offset : constant integer := 16;
width : constant integer := 10 + offset + 6 * (sprite (index).width + 8);
height : constant integer := attribute.count * core.icon + 2 * offset + 10 + sprite (index).height;
move_x : constant integer := (if center then (core.window_width - width) / 2 else x);
move_y : constant integer := (if center then (core.window_height - height) / 2 else y);
move : integer := 0;
begin begin
ui.draw_tiny_menu (move_x, move_y, width, height); draw (data.kind, data.state, x, y);
ui.draw_title_bar (move_x, move_y, width, trait (index).name);
-- --
view (index, move_x + offset, move_y + offset); for index in item.slot loop
-- if data.items (index).allow then
--~for data in attribute.enumeration item.draw (data.items (index).index, data.state, x, y);
--~loop end if;
--~move := attribute.enumeration'pos (data) * core.icon;
--~--
--~ui.draw_icon (attribute.sprite (data), attribute.trait (data).text, move_x + view_width + 12 + offset, move_y + offset + move);
--~--
--~ui.write (trait (index).attributes (data)'image, move_x + view_width + 12 + offset + core.icon, move_y + offset + move);
--~end loop;
--
for animate in animation loop
draw (index, animate, move_x + offset + animation'pos (animate) * (sprite (index).width + 8), move_y + offset + 8 + core.icon * attribute.count);
ui.draw_icon_menu (move_x + offset + animation'pos (animate) * (sprite (index).width + 8), move_y + offset + 8 + core.icon * attribute.count, sprite (index).width, sprite (index).height);
end loop; end loop;
end stat; end full_draw;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -2,16 +2,12 @@
-- --
-- GNU General Public Licence (version 3 or later) -- GNU General Public Licence (version 3 or later)
with core, effect, attribute, faction; with core, effect, attribute, faction, item;
package unit is package unit is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
type animation is (
idle, walk, melee, shoot, wounded, dead
);
type enumeration is ( type enumeration is (
dwarf_base, fairy_base, gnoll_base, goblin_base, imp_base, kobold_base dwarf_base, fairy_base, gnoll_base, goblin_base, imp_base, kobold_base
); );
@ -26,6 +22,14 @@ package unit is
text : core.long_string; text : core.long_string;
end record; end record;
type value is record
kind : enumeration;
state : core.animation;
attributes : attribute.points;
--
items : item.list;
end record;
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
count : constant natural := enumeration'pos (enumeration'last) + 1; count : constant natural := enumeration'pos (enumeration'last) + 1;
@ -39,15 +43,24 @@ package unit is
("Kobold ", faction.kobold, (others => 1), effect.none, " ") ("Kobold ", faction.kobold, (others => 1), effect.none, " ")
); );
list : array (0 .. 100) of value := (
others => (dwarf_base, core.idle, (others => 1), (
item.main_hand => (item.iron_sword, true),
item.full_body => (item.cyan_tunic, true),
item.head => (item.iron_helmet, true),
item.feet => (item.iron_greaves, true),
others => (item.iron_sword, false)))
);
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------
procedure configure; procedure configure;
procedure draw (index : in enumeration; state : in animation; x, y : in integer); procedure draw (index : in enumeration; state : in core.animation; x, y : in integer);
procedure icon (index : in enumeration; x, y : in integer); procedure icon (index : in enumeration; x, y : in integer);
procedure view (index : in enumeration; x, y : in integer); procedure view (index : in enumeration; x, y : in integer);
procedure stat (index : in enumeration; x, y : in integer; center : in boolean); procedure full_draw (data : in value; x, y : in integer);
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -50,6 +50,7 @@ package body world is
map.landmarks := new entity_array (1 .. landmark_limit); map.landmarks := new entity_array (1 .. landmark_limit);
map.constructions := new entity_array (1 .. 30); map.constructions := new entity_array (1 .. 30);
map.items := new entity_array (1 .. 60); map.items := new entity_array (1 .. 60);
map.units := new entity_array (1 .. 90);
-- --
for x in 0 .. width - 1 loop for x in 0 .. width - 1 loop
for y in 0 .. height - 1 loop for y in 0 .. height - 1 loop
@ -99,6 +100,14 @@ package body world is
map.items (index).y := core.random (0, map.height - 1); map.items (index).y := core.random (0, map.height - 1);
end loop; end loop;
-- --
for index in 1 .. 90 loop
map.units (index).index := core.random (0, unit.count - 1);
map.units (index).x := core.random (0, map.width - 1);
map.units (index).y := core.random (0, map.height - 1);
--
map.clips (map.units (index).x, map.units (index).y) := true;
end loop;
--
core.echo (core.success, "Finished procedurally generating new map."); core.echo (core.success, "Finished procedurally generating new map.");
end make; end make;
@ -167,11 +176,20 @@ package body world is
for index in 1 .. 60 loop for index in 1 .. 60 loop
if map.views (map.items (index).x, map.items (index).y) then if map.views (map.items (index).x, map.items (index).y) then
item.draw (item.enumeration'val (map.items (index).index), item.draw (item.enumeration'val (map.items (index).index),
core.idle,
offset.x + (map.items (index).x - core.camera.x) * core.base * core.zoom, offset.x + (map.items (index).x - core.camera.x) * core.base * core.zoom,
offset.y + (map.items (index).y - core.camera.y) * core.base * core.zoom); offset.y + (map.items (index).y - core.camera.y) * core.base * core.zoom);
end if; end if;
end loop; end loop;
-- --
for index in 1 .. 90 loop
if map.views (map.units (index).x, map.units (index).y) then
unit.full_draw (unit.list (map.units (index).index),
offset.x + (map.units (index).x - core.camera.x) * core.base * core.zoom,
offset.y + (map.units (index).y - core.camera.y) * core.base * core.zoom);
end if;
end loop;
--
for vertical in 0 .. map.height - 1 loop for vertical in 0 .. map.height - 1 loop
exit when offset.y + (vertical - core.camera.y) * core.base * core.zoom > core.window_height; exit when offset.y + (vertical - core.camera.y) * core.base * core.zoom > core.window_height;
-- --

View File

@ -45,6 +45,7 @@ package world is
landmarks : access entity_array; landmarks : access entity_array;
constructions : access entity_array; constructions : access entity_array;
items : access entity_array; items : access entity_array;
units : access entity_array;
end record; end record;
------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------