2024-04-25 00:27:13 -04:00
|
|
|
-- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic
|
|
|
|
--
|
|
|
|
-- GNU General Public Licence (version 3 or later)
|
|
|
|
|
2024-02-22 03:29:04 -05:00
|
|
|
with core, resource, item, unit, construction, world;
|
2024-02-15 21:03:09 -05:00
|
|
|
|
|
|
|
package body world is
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2024-04-26 19:46:09 -04:00
|
|
|
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;
|
2024-04-27 07:03:40 -04:00
|
|
|
x, y : integer;
|
2024-04-26 19:46:09 -04:00
|
|
|
end record;
|
|
|
|
|
|
|
|
type tile_array is array (natural range <>, natural range <>) of integer;
|
|
|
|
type landmark_array is array (natural range <>) of landmark_value;
|
|
|
|
|
2024-04-27 03:49:02 -04:00
|
|
|
type information is record
|
2024-04-27 07:03:40 -04:00
|
|
|
kind : biome;
|
|
|
|
width : natural;
|
|
|
|
height : natural;
|
|
|
|
tiles : access tile_array;
|
|
|
|
landmarks : access landmark_array;
|
2024-04-26 19:46:09 -04:00
|
|
|
end record;
|
2024-02-15 21:03:09 -05:00
|
|
|
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
2024-04-26 19:46:09 -04:00
|
|
|
map : information;
|
2024-02-15 21:03:09 -05:00
|
|
|
|
2024-04-26 19:46:09 -04:00
|
|
|
tiles : core.sprite;
|
|
|
|
landmarks : array (landmark_index) of core.sprite;
|
2024-02-15 21:03:09 -05:00
|
|
|
|
2024-04-27 07:03:40 -04:00
|
|
|
landmark_limit : constant integer := 40;
|
2024-04-26 19:46:09 -04:00
|
|
|
|
|
|
|
trait : constant array (landmark_index) of landmark_trait := (
|
2024-04-27 07:03:40 -04:00
|
|
|
dead_tree => (ash, true, 1),
|
|
|
|
mossy_rock => (swamp, true, 1),
|
2024-04-27 09:04:47 -04:00
|
|
|
palm_tree => (sand, true, 4),
|
2024-04-27 07:03:40 -04:00
|
|
|
pine_tree => (grass, true, 4),
|
|
|
|
reeds => (swamp, false, 4),
|
2024-04-27 09:04:47 -04:00
|
|
|
rock => (sand, true, 1),
|
2024-04-27 07:03:40 -04:00
|
|
|
snowed_pine_tree => (snow, true, 4),
|
|
|
|
snowed_rock => (snow, true, 1),
|
|
|
|
spiky_rock => (ash, true, 1)
|
2024-04-26 19:46:09 -04:00
|
|
|
);
|
2024-02-16 07:53:36 -05:00
|
|
|
|
2024-02-15 21:03:09 -05:00
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
procedure configure is
|
|
|
|
begin
|
2024-03-11 08:42:25 -04:00
|
|
|
core.echo (core.comment, "Configuring world components...");
|
|
|
|
--
|
2024-04-26 19:46:09 -04:00
|
|
|
tiles := core.import_sprite ("./sprite/world/terrain/terrain.png", 1, 1);
|
2024-02-15 21:03:09 -05:00
|
|
|
--
|
2024-04-26 19:46:09 -04:00
|
|
|
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;
|
2024-02-15 21:03:09 -05:00
|
|
|
end loop;
|
|
|
|
end configure;
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
2024-04-26 19:46:09 -04:00
|
|
|
procedure make (index : in biome; width, height : in natural) is
|
2024-02-15 21:03:09 -05:00
|
|
|
begin
|
2024-03-21 18:28:26 -04:00
|
|
|
core.echo (core.comment, "-- Procedurally generating new map...");
|
2024-04-25 04:14:45 -04:00
|
|
|
--
|
2024-04-23 16:33:07 -04:00
|
|
|
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);
|
2024-03-21 18:28:26 -04:00
|
|
|
--
|
2024-04-27 07:03:40 -04:00
|
|
|
map.kind := index;
|
2024-04-26 19:46:09 -04:00
|
|
|
map.width := width;
|
|
|
|
map.height := height;
|
2024-04-27 03:49:02 -04:00
|
|
|
map.tiles := new tile_array (0 .. width - 1, 0 .. height - 1);
|
2024-04-26 19:46:09 -04:00
|
|
|
map.landmarks := new landmark_array (1 .. landmark_limit);
|
2024-02-15 21:03:09 -05:00
|
|
|
--
|
2024-04-27 03:49:02 -04:00
|
|
|
for x in 0 .. width - 1 loop
|
|
|
|
for y in 0 .. height - 1 loop
|
2024-04-27 09:04:47 -04:00
|
|
|
map.tiles (x, y) := (core.random (0, 23) * core.random (0, 23)) mod 24;
|
2024-02-15 21:03:09 -05:00
|
|
|
end loop;
|
|
|
|
end loop;
|
|
|
|
--
|
2024-04-26 19:46:09 -04:00
|
|
|
for index in 1 .. landmark_limit loop
|
|
|
|
map.landmarks (index).index := landmark_index'val (core.random (0, 8));
|
2024-04-27 07:03:40 -04:00
|
|
|
map.landmarks (index).x := core.base * core.random (1, 90);
|
|
|
|
map.landmarks (index).y := core.base * core.random (1, 60);
|
2024-02-15 21:03:09 -05:00
|
|
|
end loop;
|
|
|
|
--
|
2024-03-21 18:28:26 -04:00
|
|
|
core.echo (core.success, "Finished procedurally generating new map.");
|
2024-02-15 21:03:09 -05:00
|
|
|
end make;
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
2024-04-27 03:49:02 -04:00
|
|
|
procedure draw is
|
|
|
|
u, v : integer;
|
2024-02-15 21:03:09 -05:00
|
|
|
begin
|
2024-04-27 03:49:02 -04:00
|
|
|
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
|
2024-04-27 07:03:40 -04:00
|
|
|
u := core.base * biome'pos (map.kind) * 4;
|
2024-04-26 19:46:09 -04:00
|
|
|
v := core.base * map.tiles (core.camera.x + move_x, core.camera.y + move_y);
|
2024-02-15 21:03:09 -05:00
|
|
|
--
|
2024-04-27 14:38:16 -04:00
|
|
|
core.draw (tiles, move_x * core.base * core.zoom, move_y * core.base * core.zoom, u, v, core.base, core.base);
|
2024-02-15 21:03:09 -05:00
|
|
|
end loop;
|
|
|
|
end loop;
|
|
|
|
--
|
2024-04-27 07:03:40 -04:00
|
|
|
for index in 1 .. landmark_limit loop
|
|
|
|
core.draw (data => landmarks (map.landmarks (index).index),
|
2024-04-27 14:38:16 -04:00
|
|
|
x => (map.landmarks (index).x - core.camera.x * core.base) * core.zoom,
|
|
|
|
y => (map.landmarks (index).y - core.camera.y * core.base) * core.zoom);
|
2024-04-27 07:03:40 -04:00
|
|
|
end loop;
|
2024-02-15 21:03:09 -05:00
|
|
|
end draw;
|
|
|
|
|
2024-04-26 19:46:09 -04:00
|
|
|
------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
function width return integer is begin return map.width; end width;
|
|
|
|
function height return integer is begin return map.height; end height;
|
|
|
|
|
2024-02-15 21:03:09 -05:00
|
|
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
end world;
|