From dad2e46c34b1cf4fd2ee04a408f36d4e914a7b03 Mon Sep 17 00:00:00 2001 From: xolatile Date: Thu, 9 May 2024 05:07:20 -0400 Subject: [PATCH] Added unit+items to world drawing procedure... --- source/core.adb | 14 ++++++++++---- source/core.ads | 8 +++++++- source/item.adb | 4 ++-- source/item.ads | 13 ++++++++++--- source/main.adb | 2 +- source/ui.adb | 14 +++++++------- source/ui.ads | 8 ++++---- source/unit.adb | 35 +++++++++-------------------------- source/unit.ads | 31 ++++++++++++++++++++++--------- source/world.adb | 18 ++++++++++++++++++ source/world.ads | 1 + 11 files changed, 91 insertions(+), 57 deletions(-) diff --git a/source/core.adb b/source/core.adb index 17e7986..2872ef5 100644 --- a/source/core.adb +++ b/source/core.adb @@ -211,9 +211,15 @@ 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)); begin 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), - view => (float (x), float (y), new_width * float (factor), new_height * float (factor)), - tint => new_tint); + uv => (x => float (if u > 0 then u else (animation_time mod data.frames) * data.width), + 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); 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_down is begin core.camera.y := core.camera.y + 1; end move_camera_down; diff --git a/source/core.ads b/source/core.ads index 29090d9..8cbf4dc 100644 --- a/source/core.ads +++ b/source/core.ads @@ -27,6 +27,12 @@ package core is signal_left_control ); + type animation is ( + idle, walk, melee, shoot, wounded, dead + ); + + ------------------------------------------------------------------------------------------ + type colour_range is range 0 .. 2 ** 8 - 1; for colour_range'size use 8; @@ -151,7 +157,7 @@ package core is procedure increment (value : in out integer); procedure decrement (value : in out integer); - procedure idle; + procedure idle_skip; procedure move_camera_up; procedure move_camera_down; procedure move_camera_left; diff --git a/source/item.adb b/source/item.adb index f4af823..edfc709 100644 --- a/source/item.adb +++ b/source/item.adb @@ -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 - core.draw (sprite (index), x, y); + core.draw (sprite (index), x, y, state => core.animation'pos (state)); end draw; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/item.ads b/source/item.ads index c38c296..e317350 100644 --- a/source/item.ads +++ b/source/item.ads @@ -9,8 +9,8 @@ package item is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ type slot is ( - with_body, full_body, head, chest, hands, feet, - neck, main_hand, off_hand, bag, cloak, additional + full_body, head, chest, hands, feet, + neck, main_hand, off_hand ); type enumeration is ( @@ -45,6 +45,13 @@ package item is evoke : effect.enumeration; 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; @@ -163,7 +170,7 @@ package item is procedure configure; - procedure draw (index : in enumeration; x, y : in integer); + procedure draw (index : in enumeration; state : in core.animation; x, y : in integer); ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/main.adb b/source/main.adb index 3db62f5..5fbc97b 100644 --- a/source/main.adb +++ b/source/main.adb @@ -98,7 +98,7 @@ procedure main is signal_v => ui_main_style'access, signal_kp_add => zoom_in'access, signal_kp_subtract => zoom_out'access, - others => idle'access + others => idle_skip'access ); ------------------------------------------------------------------------------------------ diff --git a/source/ui.adb b/source/ui.adb index fb339ff..c8c5cd9 100644 --- a/source/ui.adb +++ b/source/ui.adb @@ -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; begin 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; begin 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_height : integer := sprite (active, index).height; 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; begin 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; begin 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; begin 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_y : constant integer := sprite (active, frame_middle).height; begin diff --git a/source/ui.ads b/source/ui.ads index a26eed7..ec9a38c 100644 --- a/source/ui.ads +++ b/source/ui.ads @@ -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 draw_icon (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'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_skip'access); 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_fill_bar (x, y, width : in integer; fill : in float); diff --git a/source/unit.adb b/source/unit.adb index 4d1eb81..65263a4 100644 --- a/source/unit.adb +++ b/source/unit.adb @@ -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 - core.draw (sprite (index), x, y, 6, animation'pos (state)); + core.draw (sprite (index), x, y, state => core.animation'pos (state)); end draw; ------------------------------------------------------------------------------------------ @@ -57,33 +57,16 @@ package body unit is ------------------------------------------------------------------------------------------ - procedure stat (index : in enumeration; x, y : in integer; center : in boolean) 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; + procedure full_draw (data : in value; x, y : in integer) is begin - ui.draw_tiny_menu (move_x, move_y, width, height); - ui.draw_title_bar (move_x, move_y, width, trait (index).name); + draw (data.kind, data.state, x, y); -- - view (index, move_x + offset, move_y + offset); - -- - --~for data in attribute.enumeration - --~loop - --~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); + for index in item.slot loop + if data.items (index).allow then + item.draw (data.items (index).index, data.state, x, y); + end if; end loop; - end stat; + end full_draw; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/unit.ads b/source/unit.ads index 41fe643..f9f7014 100644 --- a/source/unit.ads +++ b/source/unit.ads @@ -2,16 +2,12 @@ -- -- GNU General Public Licence (version 3 or later) -with core, effect, attribute, faction; +with core, effect, attribute, faction, item; package unit is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - type animation is ( - idle, walk, melee, shoot, wounded, dead - ); - type enumeration is ( dwarf_base, fairy_base, gnoll_base, goblin_base, imp_base, kobold_base ); @@ -26,6 +22,14 @@ package unit is text : core.long_string; 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; @@ -39,15 +43,24 @@ package unit is ("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 draw (index : in enumeration; state : in animation; x, y : in integer); - procedure icon (index : in enumeration; x, y : in integer); - procedure view (index : in enumeration; 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 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); ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/world.adb b/source/world.adb index 0027509..f160d75 100644 --- a/source/world.adb +++ b/source/world.adb @@ -50,6 +50,7 @@ package body world is map.landmarks := new entity_array (1 .. landmark_limit); map.constructions := new entity_array (1 .. 30); map.items := new entity_array (1 .. 60); + map.units := new entity_array (1 .. 90); -- for x in 0 .. width - 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); 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."); end make; @@ -167,11 +176,20 @@ package body world is for index in 1 .. 60 loop if map.views (map.items (index).x, map.items (index).y) then 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.y + (map.items (index).y - core.camera.y) * core.base * core.zoom); end if; 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 exit when offset.y + (vertical - core.camera.y) * core.base * core.zoom > core.window_height; -- diff --git a/source/world.ads b/source/world.ads index 61dd6e0..c026b10 100644 --- a/source/world.ads +++ b/source/world.ads @@ -45,6 +45,7 @@ package world is landmarks : access entity_array; constructions : access entity_array; items : access entity_array; + units : access entity_array; end record; ------------------------------------------------------------------------------------------