|
- -- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic
- --
- -- GNU General Public Licence (version 3 or later)
-
- with core, resource, item, unit, construction, world;
-
- package body world is
-
- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
- type landmark_index is (
- dead_tree, mossy_rock, palm_tree, pine_tree, reeds, rock, snowed_pine_tree, snowed_rock, spiky_rock
- );
-
- type landmark_trait is record
- spawn : biome;
- clip : boolean;
- frames : integer;
- end record;
-
- type landmark_value is record
- index : landmark_index;
- x : integer;
- y : integer;
- end record;
-
- type tile_array is array (natural range <>, natural range <>) of integer;
- type landmark_array is array (natural range <>) of landmark_value;
-
- type information is record
- terrain : biome;
- width : natural;
- height : natural;
- tiles : access tile_array;
- landmarks : access landmark_array;
- end record;
-
- ------------------------------------------------------------------------------------------
-
- map : information;
-
- tiles : core.sprite;
- landmarks : array (landmark_index) of core.sprite;
-
- landmark_limit : constant integer := 7;
-
- trait : constant array (landmark_index) of landmark_trait := (
- (ash, true, 1),
- (swamp, true, 1),
- (cave, true, 4),
- (grass, true, 4),
- (swamp, false, 4),
- (cave, true, 1),
- (snow, true, 4),
- (snow, true, 1),
- (ash, true, 1)
- );
-
- ------------------------------------------------------------------------------------------
-
- procedure configure is
- begin
- core.echo (core.comment, "Configuring world components...");
- --
- tiles := core.import_sprite ("./sprite/world/terrain/terrain.png", 1, 1);
- --
- for index in landmark_index loop
- declare file : constant string := core.lowercase (index'image);
- begin
- landmarks (index) := core.import_sprite ("./sprite/world/landmark/" & file & ".png", trait (index).frames, 1);
- end;
- end loop;
- end configure;
-
- ------------------------------------------------------------------------------------------
-
- procedure make (index : in biome; width, height : in natural) is
- begin
- core.echo (core.comment, "-- Procedurally generating new map...");
- --
- core.echo (core.comment, "-- -- Map type : " & index'image);
- core.echo (core.comment, "-- -- Map width :" & width'image);
- core.echo (core.comment, "-- -- Map height :" & height'image);
- core.echo (core.comment, "-- -- Landmark count :" & landmark_limit'image);
- --
- map.terrain := index;
- map.width := width;
- map.height := height;
- map.tiles := new tile_array (0 .. width - 1, 0 .. height - 1);
- map.landmarks := new landmark_array (1 .. landmark_limit);
- --
- for x in 0 .. width - 1 loop
- for y in 0 .. height - 1 loop
- map.tiles (x, y) := (x * x + x * y + y * y) mod 24;
- end loop;
- end loop;
- --
- for index in 1 .. landmark_limit loop
- map.landmarks (index).index := landmark_index'val (core.random (0, 8));
- map.landmarks (index).x := core.base * core.random (1, 24);
- map.landmarks (index).y := core.base * core.random (1, 24);
- end loop;
- --
- core.echo (core.success, "Finished procedurally generating new map.");
- end make;
-
- ------------------------------------------------------------------------------------------
-
- procedure draw is
- u, v : integer;
- begin
- for move_y in 0 .. core.window_height / core.base / core.zoom + 1 loop
- for move_x in 0 .. core.window_width / core.base / core.zoom + 1 loop
- u := core.base * biome'pos (map.terrain) * 4;
- v := core.base * map.tiles (core.camera.x + move_x, core.camera.y + move_y);
- --
- core.draw (tiles, (move_x - 1) * core.base * core.zoom, (move_y - 1) * core.base * core.zoom, u, v, core.base, core.base);
- end loop;
- end loop;
- --
- --~for index in 1 .. landmark_limit loop
- --~core.draw (landmarks (map.landmarks (index).index),
- --~map.landmarks (index).x - core.camera.x * core.base,
- --~map.landmarks (index).y - core.camera.y * core.base,
- --~x, y, core.base, core.base);
- --~end loop;
- end draw;
-
- ------------------------------------------------------------------------------------------
-
- function width return integer is begin return map.width; end width;
- function height return integer is begin return map.height; end height;
-
- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
- end world;
|