From 8e72e66469fa05618532924fdaa7fa0a5b265c99 Mon Sep 17 00:00:00 2001 From: xolatile Date: Sun, 19 May 2024 15:06:20 -0400 Subject: [PATCH] Gameplay pretty much finished except for buildings... --- source/construction.adb | 3 ++- source/core.adb | 46 ++++++++++++------------------------- source/core.ads | 31 ++++++++++--------------- source/equipment.adb | 16 ++++--------- source/equipment.ads | 6 ++--- source/main.adb | 18 ++++++++++----- source/ui.adb | 36 +++++++++++++---------------- source/ui.ads | 9 ++++---- source/world.adb | 60 ++++++++++++++----------------------------------- source/world.ads | 2 -- 10 files changed, 84 insertions(+), 143 deletions(-) diff --git a/source/construction.adb b/source/construction.adb index 065ca3d..c44ffdf 100644 --- a/source/construction.adb +++ b/source/construction.adb @@ -31,10 +31,11 @@ package body construction is ------------------------------------------------------------------------------------------ procedure draw_plus (index : in enumeration; x, y : in integer) is + use type core.cursor_code; begin draw (index, x, y); -- - if core.cursor_inside (x, y, sprite (index).width, sprite (index).height) and core.cursor_mode = 2 and not ui.prioritize then + if core.cursor_inside (x, y, sprite (index).width, sprite (index).height) and core.cursor_mode = core.cursor_right and not ui.prioritize then core.write_text_box (trait (index).name); end if; end draw_plus; diff --git a/source/core.adb b/source/core.adb index 60c22c7..68eb2c4 100644 --- a/source/core.adb +++ b/source/core.adb @@ -46,6 +46,13 @@ package body core is ------------------------------------------------------------------------------------------ + function "=" (a, b : in signal_code) return boolean is begin return natural (signal_code'pos (a)) = natural (signal_code'pos (b)); end "="; + function "=" (a, b : in cursor_code) return boolean is begin return natural (cursor_code'pos (a)) = natural (cursor_code'pos (b)); end "="; + function "/" (a, b : in signal_code) return boolean is begin return natural (signal_code'pos (a)) /= natural (signal_code'pos (b)); end "/"; + function "/" (a, b : in cursor_code) return boolean is begin return natural (cursor_code'pos (a)) /= natural (cursor_code'pos (b)); end "/"; + + ------------------------------------------------------------------------------------------ + function "+" (data : in point; modifier : in natural) return point is this : point := data; begin @@ -370,19 +377,6 @@ package body core is ------------------------------------------------------------------------------------------ - procedure block_queue (data : in block) is - begin - if block_count = block_limit - 1 then - return; - end if; - -- - block_array (block_count) := data; - -- - increment (block_count); - end block_queue; - - ------------------------------------------------------------------------------------------ - function read_help_box return string is begin return to_string (help_box.text); end read_help_box; function read_text_box return string is begin return to_string (text_box.text); end read_text_box; @@ -441,7 +435,7 @@ package body core is -- ray.window_icon (game_icon); -- - ray.randomization (19970725); + --ray.randomization (19970725); ray.set_target_fps (60); -- echo (success, "Initialized core components."); @@ -495,12 +489,12 @@ package body core is engine_active := false; end if; -- - if ray.mouse_button_is_pressed (ray.mouse_button_left) then cursor_mode := 1; end if; - if ray.mouse_button_is_pressed (ray.mouse_button_right) then cursor_mode := 2; end if; - if ray.mouse_button_is_pressed (ray.mouse_button_middle) then cursor_mode := 3; end if; - if ray.mouse_button_is_released (ray.mouse_button_left) then cursor_mode := 0; end if; - if ray.mouse_button_is_released (ray.mouse_button_right) then cursor_mode := 0; end if; - if ray.mouse_button_is_released (ray.mouse_button_middle) then cursor_mode := 0; end if; + if ray.mouse_button_is_pressed (ray.mouse_button_left) then cursor_mode := cursor_left; end if; + if ray.mouse_button_is_pressed (ray.mouse_button_right) then cursor_mode := cursor_right; end if; + if ray.mouse_button_is_pressed (ray.mouse_button_middle) then cursor_mode := cursor_middle; end if; + if ray.mouse_button_is_released (ray.mouse_button_left) then cursor_mode := cursor_none; end if; + if ray.mouse_button_is_released (ray.mouse_button_right) then cursor_mode := cursor_none; end if; + if ray.mouse_button_is_released (ray.mouse_button_middle) then cursor_mode := cursor_none; end if; -- case signal is when 48 .. 57 => signal_mode := signal_code'val (signal - 48 + signal_code'pos (signal_0)); @@ -525,18 +519,6 @@ package body core is when others => signal_mode := signal_none; end case; -- - --~for index in reverse 0 .. block_count - 1 loop - --~if core.cursor.x > block_array (index).x and core.cursor.x < block_array (index).width - --~and core.cursor.y > block_array (index).y and core.cursor.y < block_array (index).height - --~and core.cursor_mode = block_array (index).mode then - --~block_array (index).action.all; - --~core.cursor_mode := 0; - --~exit; - --~end if; - --~end loop; - -- - block_count := 0; - -- ray.begin_drawing; -- ray.clear_background ((0, 0, 0, 255)); diff --git a/source/core.ads b/source/core.ads index d8c28fa..98abb8f 100644 --- a/source/core.ads +++ b/source/core.ads @@ -13,6 +13,10 @@ package core is failure, warning, success, comment, import, export ); + type cursor_code is ( + cursor_none, cursor_left, cursor_right, cursor_middle + ); + type signal_code is ( signal_none, signal_space, signal_0, signal_1, signal_2, signal_3, signal_4, signal_5, signal_6, signal_7, signal_8, signal_9, @@ -44,22 +48,13 @@ package core is type pointer is access procedure; - type point is record - value, limit : natural; - end record; - type vector is record x, y : integer; end record; type sprite is record index, width, height, frames, states : integer; end record; type font is record index, scale, space : integer; end record; type song is record index : integer; end record; - type block is record - x : integer := 0; - y : integer := 0; - width : integer := 0; - height : integer := 0; - mode : integer := 0; - action : access procedure := null; + type point is record + value, limit : natural; end record; type string_box_data is record @@ -90,7 +85,7 @@ package core is cursor : vector := (0, 0); camera : vector := (0, 0); - cursor_mode : integer := 0; + cursor_mode : cursor_code := cursor_none; signal_mode : signal_code := signal_none; framerate : integer := 0; global_time : natural := 0; @@ -101,11 +96,6 @@ package core is zoom : natural := 1; - block_limit : constant natural := 40; - block_count : natural := 0; - - block_array : array (0 .. block_limit - 1) of block := (others => (0, 0, 0, 0, 0, null)); - help_box : string_box_data; text_box : string_box_data; @@ -113,6 +103,11 @@ package core is ------------------------------------------------------------------------------------------ + function "=" (a, b : in signal_code) return boolean; + function "=" (a, b : in cursor_code) return boolean; + function "/" (a, b : in signal_code) return boolean; + function "/" (a, b : in cursor_code) return boolean; + function "+" (data : in point; modifier : in natural) return point; function "-" (data : in point; modifier : in natural) return point; function "*" (data : in point; modifier : in natural) return point; @@ -175,8 +170,6 @@ package core is procedure overlay; - procedure block_queue (data : in block); - function read_help_box return string; function read_text_box return string; diff --git a/source/equipment.adb b/source/equipment.adb index 8706287..85eed80 100644 --- a/source/equipment.adb +++ b/source/equipment.adb @@ -8,17 +8,8 @@ package body equipment is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - function "/" (a, b : in enumeration) return boolean is - begin - return natural (enumeration'pos (a)) /= natural (enumeration'pos (b)); - end "/"; - - ------------------------------------------------------------------------------------------ - - function "=" (a, b : in enumeration) return boolean is - begin - return natural (enumeration'pos (a)) = natural (enumeration'pos (b)); - end "="; + function "=" (a, b : in enumeration) return boolean is begin return natural (enumeration'pos (a)) = natural (enumeration'pos (b)); end "="; + function "/" (a, b : in enumeration) return boolean is begin return natural (enumeration'pos (a)) /= natural (enumeration'pos (b)); end "/"; ------------------------------------------------------------------------------------------ @@ -46,11 +37,12 @@ package body equipment is ------------------------------------------------------------------------------------------ procedure draw_plus (index : in enumeration; state : in core.animation; x, y : in integer) is + use type core.cursor_code; begin draw (index, state, x, y); -- if core.cursor_inside (x, y, sprite (index).width, sprite (index).height) - and core.cursor_mode = 2 + and core.cursor_mode = core.cursor_right and index / none and not ui.prioritize then core.write_text_box (trait (index).name); diff --git a/source/equipment.ads b/source/equipment.ads index 49acf3a..0cacf7c 100644 --- a/source/equipment.ads +++ b/source/equipment.ads @@ -200,14 +200,14 @@ package equipment is ------------------------------------------------------------------------------------------ + function "=" (a, b : in enumeration) return boolean; + function "/" (a, b : in enumeration) return boolean; + procedure configure; procedure draw (index : in enumeration; state : in core.animation; x, y : in integer); procedure draw_plus (index : in enumeration; state : in core.animation; x, y : in integer); - function "=" (a, b : in enumeration) return boolean; - function "/" (a, b : in enumeration) return boolean; - ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ end equipment; diff --git a/source/main.adb b/source/main.adb index e7d9e08..abb5522 100644 --- a/source/main.adb +++ b/source/main.adb @@ -219,7 +219,7 @@ begin world.configure; --~ai.configure; - world.make (world.swamp, 60, 40, 8); + world.make (world.swamp, 240, 180, 8); world.add_chad (player); dash; @@ -241,7 +241,7 @@ begin introduction_loop: loop synchronize; -- - exit when signal_mode = signal_space or cursor_mode = 2; + exit when signal_mode = signal_space or cursor_mode = cursor_right; -- case signal_mode is when signal_none => null; @@ -256,24 +256,30 @@ begin ui.write ("[-- Press Spacebar or RMB to continue]", 0, center_y (24), (102, 102, 102, 255)); end loop introduction_loop; - cursor_mode := 0; + cursor_mode := cursor_none; main_menu_loop: loop synchronize; -- - exit when signal_mode = signal_space or cursor_mode = 2; + exit when signal_mode = signal_space or cursor_mode = cursor_right; -- --~main_menu; -- declare source_code_data : string_box_data; begin import_text (source_code_data, to_string (source_code (view_source_code))); - if cursor_mode = 1 then view_source_code := (view_source_code + 1) mod 36; cursor_mode := 0; wheel := 0.0; end if; + -- + if cursor_mode = cursor_left then + view_source_code := (view_source_code + 1) mod 36; + cursor_mode := cursor_none; + wheel := 0.0; + end if; + -- ui.write_ada_code (source_code_data, 0, integer (wheel) * 30); end; end loop main_menu_loop; - cursor_mode := 0; + cursor_mode := cursor_none; ui.active := ui.style'val (faction.enumeration'pos (chad.trait (player.index).kind) + 1); diff --git a/source/ui.adb b/source/ui.adb index f2700c7..1db99dd 100644 --- a/source/ui.adb +++ b/source/ui.adb @@ -7,6 +7,8 @@ with core; with ada.strings.unbounded; use ada.strings.unbounded; +use type core.cursor_code; + package body ui is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ @@ -283,9 +285,9 @@ package body ui is -- core.write_help_box (text); -- - if core.cursor_mode = 1 then + if core.cursor_mode = core.cursor_left then action.all; - core.cursor_mode := 0; + core.cursor_mode := core.cursor_none; end if; end if; end draw_icon; @@ -312,9 +314,9 @@ package body ui is -- core.write_help_box (text); -- - if core.cursor_mode = 1 then + if core.cursor_mode = core.cursor_left then action.all; - core.cursor_mode := 0; + core.cursor_mode := core.cursor_none; end if; end if; end draw_sprite; @@ -390,9 +392,9 @@ package body ui is -- core.write_help_box (description); -- - if core.cursor_mode = 1 then + if core.cursor_mode = core.cursor_left then action.all; - core.cursor_mode := 0; + core.cursor_mode := core.cursor_none; end if; end if; end draw_frame; @@ -413,9 +415,9 @@ package body ui is if core.cursor_inside (x, y, width / core.zoom, height / core.zoom) then prioritize := true; -- - if core.cursor_mode = 1 then + if core.cursor_mode = core.cursor_left then action.all; - core.cursor_mode := 0; + core.cursor_mode := core.cursor_none; end if; end if; end draw_button; @@ -428,9 +430,10 @@ package body ui is -- write (text, x + sprite (active, check_box_on).width, y); -- - if core.cursor_mode = 1 and core.cursor_inside (x, y, sprite (active, check_box_on).width / core.zoom, sprite (active, check_box_on).height / core.zoom) then + if core.cursor_mode = core.cursor_left + and core.cursor_inside (x, y, sprite (active, check_box_on).width / core.zoom, sprite (active, check_box_on).height / core.zoom) then on := not on; - core.cursor_mode := 0; + core.cursor_mode := core.cursor_none; end if; end draw_check_box; @@ -699,24 +702,15 @@ package body ui is or word = "and" or word = "or" or word = "xor" or word = "exit" or word = "constant" or word = "access" or word = "range" or word = "subtype" or word = "array" or word = "in" or word = "out" or word = "return" or word = "for" or word = "with" or word = "loop" or word = "while" or word = "of" or word = "null" or word = "record" or word = "use" or word = "mod" or word = "new" - --~or word = "" - --~or word = "" - --~or word = "" - --~or word = "" - --~or word = "" - --~or word = "" - --~or word = "" - --~or word = "" - --~or word = "" or word = "aliased" then ui.write (to_string (word), offset.x, offset.y, (255, 255, 0, 255), height, code => true); else - ui.write (to_string (word), offset.x, offset.y, (255, 255, 255, 255), height, code => true); + ui.write (to_string (word), offset.x, offset.y, (others => 255), height, code => true); end if; offset.x := offset.x + (subset - 1) * width; length := length + subset - 1; when others => - ui.write (buffer & "", offset.x, offset.y, (255, 255, 255, 255), height, code => true); + ui.write (buffer & "", offset.x, offset.y, (others => 255), height, code => true); end case; -- core.increment (length); diff --git a/source/ui.ads b/source/ui.ads index e0929a7..76b0fba 100644 --- a/source/ui.ads +++ b/source/ui.ads @@ -14,15 +14,16 @@ package ui is ); type enumeration is ( - gui_none, gui_button, gui_line, gui_text, gui_icon, gui_sprite, gui_orient + gui_none, gui_button, gui_line, gui_text, gui_icon, gui_sprite, + gui_orient ); ------------------------------------------------------------------------------------------ type gui_data is record kind : enumeration := gui_none; - text : core.short_string := "- "; - info : core.long_string := "- "; + text : core.short_string := "-- "; + info : core.long_string := "-- "; number : integer := 0; image : core.sprite := (others => 0); end record; @@ -32,7 +33,7 @@ package ui is type gui_array is array (natural range <>) of gui_data; type structure is record - title : core.short_string := "- "; + title : core.short_string := "-- "; toggle : core.signal_code := core.signal_space; show : boolean := false; center : boolean := false; diff --git a/source/world.adb b/source/world.adb index a037bfa..ab7da48 100644 --- a/source/world.adb +++ b/source/world.adb @@ -4,20 +4,21 @@ with core, ui, resource, equipment, unit, construction, chad, effect; +use type core.cursor_code; + package body world is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ view_reach : constant integer := 96; - landmark_limit : constant integer := 60; - location_limit : constant integer := 60; - construction_limit : constant natural := 10; + landmark_limit : constant integer := 90; + location_limit : constant integer := 30; + construction_limit : constant natural := 60; equipment_limit : constant natural := 60; unit_limit : constant natural := 60; earth : core.sprite; - --~water : core.sprite; dark : core.sprite; border_upper : core.sprite; border_lower : core.sprite; @@ -35,7 +36,6 @@ package body world is core.echo (core.comment, "Configuring world components..."); -- earth := core.import_sprite (core.folder & "/game/world/terrain/earth.png", 1, 1); - --~water := core.import_sprite (core.folder & "/game/world/terrain/water.png", 1, 1); dark := core.import_sprite (core.folder & "/game/world/dark.png", 1, 1); border_upper := core.import_sprite (core.folder & "/game/world/frame/border_upper.png", 1, 1); border_lower := core.import_sprite (core.folder & "/game/world/frame/border_lower.png", 1, 1); @@ -77,8 +77,6 @@ package body world is map.chad_count := 0; -- map.earth := new integer_matrix (0 .. map.width - 1, 0 .. map.height - 1); - --~map.water := new integer_matrix (0 .. map.width - 1, 0 .. map.height - 1); - --~map.is_water := new boolean_matrix (0 .. map.width - 1, 0 .. map.height - 1); map.clips := new boolean_matrix (0 .. map.width - 1, 0 .. map.height - 1); map.views := new boolean_matrix (0 .. map.width - 1, 0 .. map.height - 1); map.landmarks := new entity_array (1 .. landmark_limit); @@ -91,26 +89,11 @@ package body world is for x in 0 .. width - 1 loop for y in 0 .. height - 1 loop map.earth (x, y) := (if core.random (0, 23) < 19 then core.random (0, 11) else core.random (0, 23)); - --~map.is_water (x, y) := (if x > 9 and x < width - 9 and y > 9 and y < height - 9 then core.random (0, 1023) = 0 else false); - --~map.water (x, y) := (if map.is_water (x, y) then core.random (0, 7) else 0); map.clips (x, y) := false; map.views (x, y) := false; end loop; end loop; -- - --~for x in 9 .. width - 9 loop - --~for y in 9 .. height - 9 loop - --~if map.is_water (x, y) then - --~for extend_x in -3 .. 3 loop - --~for extend_y in -2 .. 2 loop - --~map.is_water (extend_x + x, extend_y + y) := core.random (0, 3) /= 0; - --~map.water (extend_x + x, extend_y + y) := (if map.is_water (extend_x + x, extend_y + y) then core.random (0, 7) else 0); - --~end loop; - --~end loop; - --~end if; - --~end loop; - --~end loop; - -- for index in 1 .. landmark_limit loop map.landmarks (index).index := core.random (0, landmark_count - 1); map.landmarks (index).state := 0; @@ -233,26 +216,17 @@ package body world is v => core.base * map.earth (horizontal, vertical), width => core.base, height => core.base); - --~if map.is_water (horizontal, vertical) then - --~core.draw (data => water, - --~x => offset.x + (horizontal - core.camera.x) * core.base * core.zoom, - --~y => offset.y + (vertical - core.camera.y) * core.base * core.zoom, - --~u => core.base * biome'pos (map.kind) * 4 + (core.animation_time mod 4) * core.base, - --~v => core.base * map.water (horizontal, vertical), - --~width => core.base, - --~height => core.base); - --~end if; --~-- - --~if core.cursor.x > offset.x + (horizontal - core.camera.x ) * core.base * core.zoom - 6 - --~and core.cursor.x < offset.x + (horizontal - core.camera.x + 1) * core.base * core.zoom + 6 - --~and core.cursor.y > offset.y + (vertical - core.camera.y ) * core.base * core.zoom - 6 - --~and core.cursor.y < offset.y + (vertical - core.camera.y + 1) * core.base * core.zoom + 6 - --~and core.cursor_mode = 1 - --~and not ui.prioritize then - --~core.camera.x := horizontal; - --~core.camera.y := vertical; - --~core.cursor_mode := 0; - --~end if; + if core.cursor.x > offset.x + (horizontal - core.camera.x ) * core.base * core.zoom - 6 + and core.cursor.x < offset.x + (horizontal - core.camera.x + 1) * core.base * core.zoom + 6 + and core.cursor.y > offset.y + (vertical - core.camera.y ) * core.base * core.zoom - 6 + and core.cursor.y < offset.y + (vertical - core.camera.y + 1) * core.base * core.zoom + 6 + and core.cursor_mode = core.cursor_left + and not ui.prioritize then + map.chads (1).x := horizontal; + map.chads (1).y := vertical; + core.cursor_mode := core.cursor_none; + end if; end if; end loop; end loop; @@ -266,7 +240,7 @@ package body world is y => offset.y + (map.landmarks (index).y - core.camera.y) * core.base * core.zoom, width => landmarks (landmark_index'val (map.landmarks (index).index)).width, height => landmarks (landmark_index'val (map.landmarks (index).index)).height) - and core.cursor_mode = 2 + and core.cursor_mode = core.cursor_right and not ui.prioritize then core.write_text_box (landmark_trait (landmark_index'val (map.landmarks (index).index)).name); end if; @@ -285,7 +259,7 @@ package body world is y => offset.y + (map.locations (index).y - core.camera.y) * core.base * core.zoom, width => locations (location_index'val (map.locations (index).index)).width, height => locations (location_index'val (map.locations (index).index)).height) - and core.cursor_mode = 2 + and core.cursor_mode = core.cursor_right and not ui.prioritize then core.write_text_box (location_trait (location_index'val (map.locations (index).index)).name); end if; diff --git a/source/world.ads b/source/world.ads index 26ab2eb..e853a90 100644 --- a/source/world.ads +++ b/source/world.ads @@ -57,8 +57,6 @@ package world is chad_count : natural; chad_limit : natural; earth : access integer_matrix; - --~water : access integer_matrix; - --~is_water : access boolean_matrix; clips : access boolean_matrix; views : access boolean_matrix; landmarks : access entity_array;