From 8afc4fb6ef3dcbd37cee14b45ad99bf18de0f659 Mon Sep 17 00:00:00 2001 From: xolatile Date: Fri, 26 Apr 2024 18:25:29 -0400 Subject: [PATCH] Major code refactoring compiles and runs, next is data... --- source/construction.adb | 2 +- source/core.adb | 351 +++++++++++------------------------------------- source/core.ads | 132 ++++++------------ source/main.adb | 6 +- source/ui.adb | 6 +- source/unit.adb | 2 +- source/world.adb | 63 ++------- source/world.ads | 4 +- 8 files changed, 138 insertions(+), 428 deletions(-) diff --git a/source/construction.adb b/source/construction.adb index d2f5850..16fc894 100644 --- a/source/construction.adb +++ b/source/construction.adb @@ -31,7 +31,7 @@ package body construction is procedure draw (index : in enumeration; x, y : in integer) is begin - core.move (sprite (index), x, y, trait (index).frames, 1); + core.draw (sprite (index), x, y, trait (index).frames, 1); end draw; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/core.adb b/source/core.adb index 08ee1e5..91949ac 100644 --- a/source/core.adb +++ b/source/core.adb @@ -8,21 +8,35 @@ package body core is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - texture_count : integer := 0; - sound_count : integer := 0; - font_count : integer := 0; + type terminal_colour is ( + grey, red, green, yellow, blue, pink, + cyan, white + ); + + type terminal_effect is ( + normal, bold, italic, underline, blink, invert + ); + + ------------------------------------------------------------------------------------------ type texture_data_array is array (natural range <>) of ray.texture; type sound_data_array is array (natural range <>) of ray.sound; type font_data_array is array (natural range <>) of ray.font; + ------------------------------------------------------------------------------------------ + + texture_count : integer := 0; + sound_count : integer := 0; + font_count : integer := 0; + texture_array : access texture_data_array; sound_array : access sound_data_array; font_array : access font_data_array; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + ------------------------------------------------------------------------------------------ - procedure terminal (colour : in terminal_colour := white; effect : in terminal_effect := normal) is + procedure terminal (colour : in terminal_colour := white; + effect : in terminal_effect := normal) is format : string := character'val (27) & "[" & character'val (terminal_effect'pos (effect) + 48) & ";3" & character'val (terminal_colour'pos (colour) + 48) & "m"; begin put (format); @@ -30,7 +44,8 @@ package body core is ------------------------------------------------------------------------------------------ - procedure echo (status : in echo_status; message : in string) is + procedure echo (status : in echo_status; + text : in string) is begin if not echo_mark (status) then return; @@ -43,12 +58,11 @@ package body core is when success => terminal (green, bold); put ("Success"); when comment => terminal (grey, bold); put ("Comment"); when import => terminal (cyan, bold); put (" + "); - when export => terminal (pink, bold); put (" > "); - when deport => terminal (blue, bold); put (" - "); - when ray_ada => terminal (white, bold); put ("Ray-Ada"); + when export => terminal (pink, bold); put (" - "); end case; terminal; - put_line ("] " & message); + put ("]"); + put_line (text); end echo; ------------------------------------------------------------------------------------------ @@ -75,27 +89,6 @@ package body core is ------------------------------------------------------------------------------------------ - function flip_coin return integer is - begin - return (random (0, 1)); - end flip_coin; - - ------------------------------------------------------------------------------------------ - - function roll_dice return integer is - begin - return (random (1, 6)); - end roll_dice; - - ------------------------------------------------------------------------------------------ - - function by_chance (chance : in integer) return integer is - begin - return (random (0, 100) mod chance); - end by_chance; - - ------------------------------------------------------------------------------------------ - function c_string (ada_string : string) return string is begin return (ada_string & character'val (0)); @@ -132,7 +125,7 @@ package body core is this.states := states; -- if this.width = 0 or this.height = 0 then - echo (failure, "./" & file_path); + echo (failure, file_path); end if; -- return this; @@ -140,127 +133,68 @@ package body core is ------------------------------------------------------------------------------------------ - function import_song (file_path : in string) return integer is - begin - sound_array (sound_count) := ray.load_sound (c_string (file_path)); - -- - sound_count := sound_count + 1; - -- - return sound_count - 1; - end import_song; - - ------------------------------------------------------------------------------------------ - - function import_glyphs (file_path : in string; size, pad : in integer) return glyphs is - this : glyphs; + function import_font (file_path : in string; scale, space : in integer) return font is + this : font; begin font_array (font_count) := ray.load_font (c_string (file_path)); -- font_count := font_count + 1; this.index := font_count - 1; - this.size := size; - this.pad := pad; + this.scale := scale; + this.space := space; -- return this; - end import_glyphs; + end import_font; ------------------------------------------------------------------------------------------ - procedure crop (data : in sprite; x, y, u, v, width, height : in integer) is + function import_song (file_path : in string) return song is + this : song; begin - render_sprite (data.index, x, y, u, v, width, height); - end crop; + sound_array (sound_count) := ray.load_sound (c_string (file_path)); + -- + sound_count := sound_count + 1; + this.index := sound_count - 1; + -- + return this; + end import_song; ------------------------------------------------------------------------------------------ - procedure view (data : in sprite; x, y, u, v, width, height : in integer) is - --~crop_u, crop_v, crop_width, crop_height : integer; + procedure draw (data : in sprite; + x : in integer := 0; + y : in integer := 0; + u : in integer := 0; + v : in integer := 0; + width : in integer := 0; + height : in integer := 0; + state : in integer := 0) is + resize : vector := (0, 0); begin - if x > u + width - or y > v + height - or x < u - data.width - or y < v - data.height then - return; - end if; + resize.x := (if width = 0 then texture_array (data.index).width else width); + resize.y := (if height = 0 then texture_array (data.index).height else height); -- - --~crop_width := data.width - (if x + data.width > u + width then (x + data.width) mod (u + width) else 0); - --~crop_height := data.height - (if y + data.height > v + height then (y + data.height) mod (v + height) else 0); - -- - --~crop_u := (if x < u then data.width - u mod (x + data.width) else 0); - --~crop_v := (if y < v then data.height - v mod (y + data.height) else 0); - --~crop_u := (if x < u and x < u - data.width then data.width - (x + data.width) mod u else 0); - --~crop_v := (if y < v and y < v - data.height then data.height - (y + data.height) mod v else 0); - --~crop_u := data.width - (if x < u then (x + data.width) mod u else 0); - --~crop_v := data.height - (if y < v then (y + data.height) mod v else 0); - --~crop_u := data.width - (if x < u then u mod x else 0); - --~crop_v := data.height - (if y < v then v mod y else 0); - -- - --~render_sprite (data.index, x, y, crop_u, crop_v, crop_width, crop_height); - render_sprite (data.index, x, y, 0, 0, data.width, data.height); - end view; - - ------------------------------------------------------------------------------------------ - - procedure draw (data : in sprite; x, y : in integer) is - begin - render_sprite (data.index, x, y, 0, 0, data.width, data.height); + ray.draw_texture (data => texture_array (data.index), + uv => (float ((animation_time mod data.frames) * u), float (v), float (resize.x), float (resize.y)), + view => (float (x), float (y), float (resize.x) * zoom, float (resize.y) * zoom)); end draw; ------------------------------------------------------------------------------------------ - procedure move (data : in sprite; x, y, frame, state : in integer) is + procedure write (text : in string := ""; + x : in integer := 0; + y : in integer := 0; + data : in font) is begin - render_sprite (data.index, x, y, (animation_time mod frame) * data.width, state * data.height, data.width, data.height); - end move; - - ------------------------------------------------------------------------------------------ - - procedure line (origin, offset : in vector) is - begin - render_vector (origin.x, origin.y, origin.x + offset.x, origin.y + offset.y); - end line; - - ------------------------------------------------------------------------------------------ - - procedure write (text : in string; x, y : in integer; data : in glyphs; colour : in colour_range := 16#FFFFFFFF#) is - begin - render_string (text, x, y, colour, data.index, data.size, data.pad); + ray.draw_text (data => font_array (data.index), + text => c_string (text), + view => (float ((icon - data.scale) / 2 + x), float ((icon - data.scale) / 2 + y)), + scale => float (data.scale), + space => float (data.space)); end write; ------------------------------------------------------------------------------------------ - procedure debug (text : in string) is - begin - put_line ("> " & text); - end debug; - - ------------------------------------------------------------------------------------------ - - procedure hexagonal_grid (x, y, width, height : in integer; fill : in boolean) is - crop_width : constant integer := width mod hexagon_grid_sprite.width; - crop_height : constant integer := height mod hexagon_grid_sprite.height; - use_sprite : constant sprite := (if fill then hexagon_fill_sprite else hexagon_grid_sprite); - begin - for move_y in 0 .. height / hexagon_grid_sprite.height - 1 - loop - for move_x in 0 .. width / hexagon_grid_sprite.width - 1 - loop - draw (use_sprite, x + move_x * hexagon_grid_sprite.width, y + move_y * hexagon_grid_sprite.height); - end loop; - -- - crop (use_sprite, x + width - crop_width, y + move_y * hexagon_grid_sprite.height, 0, 0, crop_width, hexagon_grid_sprite.height); - end loop; - -- - for move_x in 0 .. width / hexagon_grid_sprite.width - 1 - loop - crop (use_sprite, x + move_x * hexagon_grid_sprite.width, y + height - crop_height, 0, 0, hexagon_grid_sprite.width, crop_height); - end loop; - -- - crop (use_sprite, x + width - crop_width, y + height - crop_height, 0, 0, crop_width, crop_height); - end hexagonal_grid; - - ------------------------------------------------------------------------------------------ - function lowercase (text : in string) return string is result : string (1 .. text'length); begin @@ -278,111 +212,6 @@ package body core is ------------------------------------------------------------------------------------------ - function uppercase (text : in string) return string is - result : string (1 .. text'length); - begin - for index in text'range - loop - if text (index) in 'a' .. 'z' then - result (index) := character'val (character'pos (text (index)) - 32); - else - result (index) := text (index); - end if; - end loop; - -- - return result; - end uppercase; - - ------------------------------------------------------------------------------------------ - - procedure draw_central_grid (x, y, width, height : in integer) is - begin - render_vector (width / 2 + x, y, width / 2 + x, height + y); - render_vector ( x, height / 2 + y, width + x, height / 2 + y); - end draw_central_grid; - - ------------------------------------------------------------------------------------------ - - procedure draw_squared_grid (x, y, width, height : in integer) is - offset : constant vector := (((width - base) / 2) mod base, ((height - base) / 2) mod base); - repeat : constant vector := (2 * (((width - base) / 2) / base) + 1, 2 * (((height - base) / 2) / base) + 1); - begin - for next in 0 .. repeat.y - loop - line ((x, y + offset.y + next * base), (width, 0)); - end loop; - -- - if repeat.y mod 4 = 1 then - for next in 0 .. repeat.x - 1 loop line ((x + offset.x + base / 2 + next * base, y ), (0, offset.y)); end loop; - for next in 0 .. repeat.x - 1 loop line ((x + offset.x + base / 2 + next * base, y + height - offset.y), (0, offset.y)); end loop; - -- - for step in 0 .. repeat.y / 2 - 1 loop - for next in 0 .. repeat.x - 1 loop line ((x + offset.x + base / 2 + next * base, y + base + offset.y + 2 * step * base), (0, base)); end loop; - end loop; - for step in 0 .. repeat.y / 2 loop - for next in 0 .. repeat.x loop line ((x + offset.x + next * base, y + offset.y + 2 * step * base), (0, base)); end loop; - end loop; - else - for next in 0 .. repeat.x - 1 loop line ((x + offset.x + next * base, y ), (0, offset.y)); end loop; - for next in 0 .. repeat.x - 1 loop line ((x + offset.x + next * base, y + height - offset.y), (0, offset.y)); end loop; - -- - for step in 0 .. repeat.y / 2 - 1 loop - for next in 0 .. repeat.x loop line ((x + offset.x + next * base, y + base + offset.y + 2 * step * base), (0, base)); end loop; - end loop; - for step in 0 .. repeat.y / 2 loop - for next in 0 .. repeat.x - 1 loop line ((x + offset.x + base / 2 + next * base, y + offset.y + 2 * step * base), (0, base)); end loop; - end loop; - end if; - end draw_squared_grid; - - ------------------------------------------------------------------------------------------ - - procedure draw_hexagon_grid (x, y, width, height : in integer) is - offset : constant vector := (((width - base) / 2) mod base, ((height - base) / 2) mod base); - repeat : constant vector := (2 * (((width - base) / 2) / base) + 1, 2 * (((height - base) / 2) / base) + 1); - begin - for step in 0 .. repeat.y - loop - if step mod 2 = 1 then - for next in 0 .. repeat.x - 1 - loop - line ((x + offset.x + base / 2 + next * base, y + offset.y + step * base + base / 4), (-base / 2, -base / 2)); - line ((x + offset.x + base / 2 + next * base, y + offset.y + step * base + base / 4), ( base / 2, -base / 2)); - end loop; - else - for next in 0 .. repeat.x - 1 - loop - line ((x + offset.x + base / 2 + next * base, y + offset.y + step * base - base / 4), (-base / 2, base / 2)); - line ((x + offset.x + base / 2 + next * base, y + offset.y + step * base - base / 4), ( base / 2, base / 2)); - end loop; - end if; - end loop; - -- - if repeat.y mod 4 = 1 then - for next in 0 .. repeat.x - 1 loop line ((x + offset.x + base / 2 + next * base, y ), (0, offset.y - base / 4)); end loop; - for next in 0 .. repeat.x - 1 loop line ((x + offset.x + base / 2 + next * base, y + base / 4 + height - offset.y), (0, offset.y - base / 4)); end loop; - -- - for step in 0 .. repeat.y / 2 - 1 loop - for next in 0 .. repeat.x - 1 loop line ((x + offset.x + base / 2 + next * base, y + 5 * base / 4 + offset.y + 2 * step * base), (0, base / 2)); end loop; - end loop; - for step in 0 .. repeat.y / 2 loop - for next in 0 .. repeat.x loop line ((x + offset.x + next * base, y + base / 4 + offset.y + 2 * step * base), (0, base / 2)); end loop; - end loop; - else - for next in 0 .. repeat.x - 1 loop line ((x + offset.x + next * base, y ), (0, offset.y)); end loop; - for next in 0 .. repeat.x - 1 loop line ((x + offset.x + next * base, y + height - offset.y), (0, offset.y)); end loop; - -- - for step in 0 .. repeat.y / 2 - 1 loop - for next in 0 .. repeat.x loop line ((x + offset.x + next * base, y + 5 * base / 4 + offset.y + 2 * step * base), (0, base / 2)); end loop; - end loop; - for step in 0 .. repeat.y / 2 loop - for next in 0 .. repeat.x - 1 loop line ((x + offset.x + base / 2 + next * base, y + base / 4 + offset.y + 2 * step * base), (0, base / 2)); end loop; - end loop; - end if; - end draw_hexagon_grid; - - ------------------------------------------------------------------------------------------ - function read_text_box return string is begin return to_string (text_box.data); @@ -397,31 +226,6 @@ package body core is ------------------------------------------------------------------------------------------ - procedure render_sprite (sprite, x, y, u, v, width, height : in integer) is - begin - ray.draw_texture (data => texture_array (sprite), - uv => (float (u), float (v), float (width), float (height)), - view => (float (x), float (y), float (width) * zoom, float (height) * zoom)); - end render_sprite; - - ------------------------------------------------------------------------------------------ - - procedure render_string (text : in string; x, y : in integer; colour : in colour_range; index, size, pad : in integer) is - begin - ray.draw_text (data => font_array (index), - text => c_string (text), - view => (float ((32 - size) / 2 + x), float ((32 - size) / 2 + y)), - scale => float (size), - space => float (pad)); - end render_string; - - ------------------------------------------------------------------------------------------ - - procedure render_vector (x1, y1, x2, y2 : in integer) is - begin - ray.draw_line (x1, y1, x2, y2, (0, 0, 0, 255)); - end render_vector; - function window_width return integer is begin return ray.get_screen_width; end window_width; function window_height return integer is begin return ray.get_screen_height; end window_height; @@ -436,22 +240,19 @@ package body core is sound_array := new sound_data_array (0 .. 4); font_array := new font_data_array (0 .. 4); -- - echo (ray_ada, "-- Setting trace log level to none (ignoring all default Raylib logs)."); + echo (comment, "-- Setting trace log level to none (ignoring all default Raylib logs)."); ray.set_trace_log_level (ray.log_none); - echo (ray_ada, "-- Initializing Raylib window data..."); - echo (ray_ada, "-- -- Window title : Chads of Might & Magic"); - echo (ray_ada, "-- -- Window width : 1800"); - echo (ray_ada, "-- -- Window height : 900"); + echo (comment, "-- Initializing Raylib window data..."); + echo (comment, "-- -- Window title : Chads of Might & Magic"); + echo (comment, "-- -- Window width : 1800"); + echo (comment, "-- -- Window height : 900"); ray.open_window (1800, 900, "Chads of Might & Magic"); - echo (ray_ada, "-- Initializing Raylib audio device data..."); + echo (comment, "-- Initializing Raylib audio device data..."); ray.open_audio_device; -- ray.randomization (25071997); ray.set_target_fps (60); -- - hexagon_grid_sprite := import_sprite ("./sprite/ui/hexagon_grid_tile.png", 1, 1); - hexagon_fill_sprite := import_sprite ("./sprite/ui/hexagon_fill_tile.png", 1, 1); - -- echo (success, "Initialized core components."); end initialize; @@ -463,18 +264,18 @@ package body core is -- engine_active := false; -- - echo (deport, "-- -- Unloading Raylib" & texture_count'image & " textures."); - echo (deport, "-- -- Unloading Raylib" & sound_count'image & " sounds."); - echo (deport, "-- -- Unloading Raylib" & font_count'image & " fonts."); + echo (comment, "-- -- Unloading Raylib" & texture_count'image & " textures."); + echo (comment, "-- -- Unloading Raylib" & sound_count'image & " sounds."); + echo (comment, "-- -- Unloading Raylib" & font_count'image & " fonts."); -- for index in 0 .. texture_count - 1 loop ray.unload_texture (texture_array (index)); end loop; for index in 0 .. sound_count - 1 loop ray.unload_sound (sound_array (index)); end loop; for index in 0 .. font_count - 1 loop ray.unload_font (font_array (index)); end loop; -- - echo (ray_ada, "-- Deinitializing Raylib audio device data..."); + echo (comment, "-- Deinitializing Raylib audio device data..."); ray.close_audio_device; -- - echo (ray_ada, "-- Deinitializing Raylib window data..."); + echo (comment, "-- Deinitializing Raylib window data..."); ray.close_window; -- echo (success, "Deinitialized core components."); @@ -537,14 +338,14 @@ package body core is ------------------------------------------------------------------------------------------ - procedure play_song (index : in integer) is begin ray.play_sound (sound_array (index)); end play_song; - procedure stop_song (index : in integer) is begin ray.stop_sound (sound_array (index)); end stop_song; + procedure play (index : in integer) is begin ray.play_sound (sound_array (index)); end play; + procedure stop (index : in integer) is begin ray.stop_sound (sound_array (index)); end stop; ------------------------------------------------------------------------------------------ procedure overlay is begin - ray.draw_rectangle (0, 0, window_width, window_height, (0, 0, 0, 100)); + ray.draw_rectangle (0, 0, window_width, window_height, (0, 0, 0, 127)); end overlay; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/core.ads b/source/core.ads index 50a5943..ff2605f 100644 --- a/source/core.ads +++ b/source/core.ads @@ -9,18 +9,8 @@ package core is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ - type terminal_colour is ( - grey, red, green, yellow, blue, pink, - cyan, white - ); - - type terminal_effect is ( - normal, bold, italic, underline, blink, invert - ); - type echo_status is ( - failure, warning, success, comment, import, export, - deport, ray_ada + failure, warning, success, comment, import, export ); type signal_code is ( @@ -42,28 +32,14 @@ package core is type procedure_pointer is access procedure; - type colour_range is range 0 .. 2 ** 32 - 1; + 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 sprite is - record - index, width, height, frames, states : integer; - end record; - - type glyphs is - record - index, size, pad : integer; - end record; - - type vector is - record - x, y : integer; - end record; - - type volatile is - record - data : unbounded_string := null_unbounded_string; - rows : integer := 0; - columns : integer := 0; + type text_box_data is record + data : unbounded_string := null_unbounded_string; + size : vector := (0, 0); end record; ------------------------------------------------------------------------------------------ @@ -71,7 +47,7 @@ package core is icon : constant natural := 32; base : constant natural := 16; gameplay_framerate : constant natural := 60; - animation_framerate : constant natural := 6; + animation_framerate : constant natural := 4; echo_mark : constant array (echo_status) of boolean := ( failure => true, @@ -79,74 +55,36 @@ package core is success => true, comment => true, import => true, - export => true, - deport => true, - ray_ada => true + export => true ); - cursor : vector := (0, 0); - cursor_mode : integer := 0; - signal_mode : integer := 0; engine_active : boolean := false; - framerate : integer := 0; + cursor : vector := (0, 0); + camera : vector := (0, 0); + cursor_mode : integer := 0; + signal_mode : integer := 0; + framerate : integer := 0; global_time : natural := 0; gameplay_time : natural := 0; animation_time : natural := 0; + zoom : float := 2.0; - camera : vector := (0, 0); - - zoom : float := 2.0; - - hexagon_grid_sprite : sprite; - hexagon_fill_sprite : sprite; - - text_box : volatile; + text_box : text_box_data; ------------------------------------------------------------------------------------------ - procedure terminal (colour : in terminal_colour := white; effect : in terminal_effect := normal); - - procedure echo (status : in echo_status; message : in string); + procedure echo (status : in echo_status; text : in string); procedure dash; procedure semi_dash; - function flip_coin return integer; - function roll_dice return integer; - function by_chance (chance : in integer) return integer; - function c_string (ada_string : in string) return string; + function c_string (ada_string : in string) return string; - function random (minimum, maximum : in integer) return integer; - - function clip (value, minimum, maximum : in integer) return integer; - - function import_sprite (file_path : in string; frames, states : in integer) return sprite; - function import_song (file_path : in string) return integer; - function import_glyphs (file_path : in string; size, pad : in integer) return glyphs; - - procedure crop (data : in sprite; x, y, u, v, width, height : in integer); - procedure view (data : in sprite; x, y, u, v, width, height : in integer); - procedure draw (data : in sprite; x, y : in integer); - procedure move (data : in sprite; x, y, frame, state : in integer); - - procedure line (origin, offset : in vector); - - procedure write (text : in string; x, y : in integer; data : in glyphs; colour : in colour_range := 16#FFFFFFFF#); - procedure debug (text : in string); - - procedure hexagonal_grid (x, y, width, height : in integer; fill : in boolean); + function random (minimum, maximum : in integer) return integer; + function clip (value, minimum, maximum : in integer) return integer; function lowercase (text : in string) return string; - function uppercase (text : in string) return string; - - procedure draw_central_grid (x, y, width, height : in integer); - procedure draw_squared_grid (x, y, width, height : in integer); - procedure draw_hexagon_grid (x, y, width, height : in integer); - - function read_text_box return string; - - procedure write_text_box (text : in string); procedure initialize; procedure deinitialize; @@ -155,15 +93,33 @@ package core is function window_width return integer; function window_height return integer; - procedure render_sprite (sprite, x, y, u, v, width, height : in integer); - procedure render_string (text : in string; x, y : in integer; colour : in colour_range; index, size, pad : in integer); - procedure render_vector (x1, y1, x2, y2 : in integer); + function import_sprite (file_path : in string; frames, states : in integer) return sprite; + function import_font (file_path : in string; scale, space : in integer) return font; + function import_song (file_path : in string) return song; - procedure play_song (index : in integer); - procedure stop_song (index : in integer); + procedure draw (data : in sprite; + x : in integer := 0; + y : in integer := 0; + u : in integer := 0; + v : in integer := 0; + width : in integer := 0; + height : in integer := 0; + state : in integer := 0); + + procedure write (text : in string := ""; + x : in integer := 0; + y : in integer := 0; + data : in font); + + procedure play (index : in integer); + procedure stop (index : in integer); procedure overlay; + function read_text_box return string; + + procedure write_text_box (text : in string); + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ end core; diff --git a/source/main.adb b/source/main.adb index a6c7c37..2f4ccc9 100644 --- a/source/main.adb +++ b/source/main.adb @@ -112,7 +112,7 @@ begin ui.configure; - core.play_song (core.import_song (core.c_string ("./song/main_menu.ogg"))); + core.play (core.import_song (core.c_string ("./song/main_menu.ogg")).index); attribute.configure; skill.configure; @@ -126,7 +126,7 @@ begin world.configure; ai.configure; - world.make (world.grass, 120, 100); + world.make (world.ash, 120, 100); preview_width := core.window_width - side_panel; preview_height := core.window_height; @@ -147,7 +147,7 @@ begin core.camera.x := core.clip (core.camera.x, 0, world.map.width - preview_width / core.base); core.camera.y := core.clip (core.camera.y, 0, world.map.height - preview_height / core.base); -- - world.draw (preview_x, preview_y, preview_width - 2 * preview_x, preview_height - 2 * preview_y - 32, core.signal_mode = core.signal_code'pos (core.signal_g)); + world.draw (preview_x, preview_y, preview_width - 2 * preview_x, preview_height - 2 * preview_y - 32); -- --~core.draw_central_grid (preview_x, preview_y, preview_width - 2 * preview_x, preview_height - 2 * preview_y); --~core.draw_squared_grid (preview_x, preview_y, preview_width - 2 * preview_x, preview_height - 2 * preview_y); diff --git a/source/ui.adb b/source/ui.adb index ef34705..73bc2a5 100644 --- a/source/ui.adb +++ b/source/ui.adb @@ -9,7 +9,7 @@ package body ui is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ sprite : array (style, enumeration) of core.sprite; - glyphs : array (style) of core.glyphs; + glyphs : array (style) of core.font; ------------------------------------------------------------------------------------------ @@ -35,7 +35,7 @@ package body ui is procedure crop (index : in enumeration; x, y, u, v, width, height : in integer) is begin core.zoom := 1.0; - core.crop (sprite (active, index), x, y, u, v, width, height); + core.draw (sprite (active, index), x, y, u, v, width, height); core.zoom := 2.0; end crop; @@ -96,7 +96,7 @@ package body ui is procedure configure is procedure load_ui (index : in style; folder_path : in string) is begin - glyphs (index) := core.import_glyphs ("./sprite/ui/" & folder_path & "/font.png", (if index = default then 16 else 24), 0); + glyphs (index) := core.import_font ("./sprite/ui/" & folder_path & "/font.png", (if index = default then 16 else 24), 0); -- for this in enumeration loop diff --git a/source/unit.adb b/source/unit.adb index bed421b..4542861 100644 --- a/source/unit.adb +++ b/source/unit.adb @@ -38,7 +38,7 @@ package body unit is procedure draw (index : in enumeration; state : in animation; x, y : in integer) is begin - core.move (sprite (index), x, y, 6, animation'pos (state)); + core.draw (sprite (index), x, y, 6, animation'pos (state)); end draw; ------------------------------------------------------------------------------------------ diff --git a/source/world.adb b/source/world.adb index cd4dc93..6f9dc87 100644 --- a/source/world.adb +++ b/source/world.adb @@ -76,7 +76,7 @@ package body world is loop for y in 0 .. height - 1 loop - map.block (x, y) := core.random (0, 23); + map.block (x, y) := (x * x + x * y + y * y) mod 24; end loop; end loop; -- @@ -87,44 +87,30 @@ package body world is map.landmark (object).y := core.base * core.random (1, map.height - 1); end loop; -- - for object in 0 .. construction_limit - loop - map.construction (object).index := core.random (0, construction.enumeration'pos (construction.enumeration'last)); - map.construction (object).x := core.base * core.random (1, map.width - 1); - map.construction (object).y := core.base * core.random (1, map.height - 1); - end loop; - -- - for object in 0 .. item_limit - loop - map.item (object).index := core.random (0, item.enumeration'pos (item.enumeration'last)); - map.item (object).x := core.base * core.random (1, map.width - 1); - map.item (object).y := core.base * core.random (1, map.height - 1); - end loop; - -- core.echo (core.success, "Finished procedurally generating new map."); end make; ------------------------------------------------------------------------------------------ - procedure draw (x, y, width, height : in integer; show_grid : in boolean) is + procedure draw (x, y, width, height : in integer) is crop_width : integer := width mod core.base; crop_height : integer := height mod core.base; u, v : integer; begin for move_y in 0 .. height / core.base - 1 loop - for move_x in 0 .. + width / core.base - 1 + for move_x in 0 .. width / core.base - 1 loop u := core.base * enumeration'pos (map.terrain) * 4; v := core.base * map.block (core.camera.x + move_x, core.camera.y + move_y); -- - core.crop (blocks, x + move_x * core.base, y + move_y * core.base, u, v, core.base, core.base); + core.draw (blocks, x + move_x * core.base, y + move_y * core.base, u, v, core.base, core.base); end loop; -- u := core.base * enumeration'pos (map.terrain) * 4; v := core.base * map.block (width / core.base, core.camera.y + move_y); -- - core.crop (blocks, x + width - crop_width, y + move_y * core.base, u, v, crop_width, core.base); + core.draw (blocks, x + width - crop_width, y + move_y * core.base, u, v, crop_width, core.base); end loop; -- for move_x in 0 .. width / core.base - 1 @@ -132,54 +118,21 @@ package body world is u := core.base * enumeration'pos (map.terrain) * 4; v := core.base * map.block (core.camera.x + move_x, height / core.base); -- - core.crop (blocks, x + move_x * core.base, y + height - crop_height, u, v, core.base, crop_height); + core.draw (blocks, x + move_x * core.base, y + height - crop_height, u, v, core.base, crop_height); end loop; -- u := core.base * enumeration'pos (map.terrain) * 4; v := core.base * map.block (width / core.base, height / core.base); -- - core.crop (blocks, x + width - crop_width, y + height - crop_height, u, v, crop_width, crop_height); + core.draw (blocks, x + width - crop_width, y + height - crop_height, u, v, crop_width, crop_height); -- for object in 0 .. landmark_limit loop - core.view (landmarks (map.terrain) (map.landmark (object).index), + core.draw (landmarks (map.terrain) (map.landmark (object).index), map.landmark (object).x - core.camera.x * core.base, map.landmark (object).y - core.camera.y * core.base, x, y, width, height); end loop; - -- - if show_grid then - core.hexagonal_grid (x, y, width, height, false); - core.hexagonal_grid (x, y, width, height, true); - end if; - -- - for object in 0 .. construction_limit - loop - if map.construction (object).x > width - or map.construction (object).y > height then - goto skip_drawing_out_of_view_construction; - end if; - -- - construction.draw (construction.enumeration'val (map.construction (object).index), - map.construction (object).x - core.camera.x * core.base, - map.construction (object).y - core.camera.y * core.base); - -- - <> - end loop; - -- - for object in 0 .. item_limit - loop - if map.item (object).x > width - or map.item (object).y > height then - goto skip_drawing_out_of_view_item; - end if; - -- - item.draw (item.enumeration'val (map.item (object).index), - map.item (object).x - core.camera.x * core.base, - map.item (object).y - core.camera.y * core.base); - -- - <> - end loop; end draw; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ diff --git a/source/world.ads b/source/world.ads index bd29266..35a43e1 100644 --- a/source/world.ads +++ b/source/world.ads @@ -2,7 +2,7 @@ -- -- GNU General Public Licence (version 3 or later) -with core, resource, item, unit, construction; +with core, item, unit, construction; package world is @@ -43,7 +43,7 @@ package world is procedure make (index : in enumeration; width, height : in natural); - procedure draw (x, y, width, height : in integer; show_grid : in boolean); + procedure draw (x, y, width, height : in integer); ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------