2024-04-25 00:27:13 -04:00
|
|
|
-- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic
|
|
|
|
--
|
|
|
|
-- GNU General Public Licence (version 3 or later)
|
|
|
|
|
2024-05-01 14:41:55 -04:00
|
|
|
with core, ui, resource, item, unit, construction, world;
|
2024-02-15 21:03:09 -05:00
|
|
|
|
|
|
|
package body world is
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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-05-05 11:38:15 -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-05-05 11:46:56 -04:00
|
|
|
map.kind := index;
|
|
|
|
map.width := width;
|
|
|
|
map.height := height;
|
|
|
|
--
|
|
|
|
map.tiles := new tile_array (0 .. map.width - 1, 0 .. map.height - 1);
|
|
|
|
map.landmarks := new entity_array (1 .. landmark_limit);
|
|
|
|
map.constructions := new entity_array (1 .. 30);
|
|
|
|
map.items := new entity_array (1 .. 60);
|
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
|
2024-05-05 11:38:15 -04:00
|
|
|
map.landmarks (index).index := core.random (0, 8);
|
2024-05-03 05:28:44 -04:00
|
|
|
map.landmarks (index).x := core.random (0, map.width - 1);
|
|
|
|
map.landmarks (index).y := core.random (0, map.height - 1);
|
2024-02-15 21:03:09 -05:00
|
|
|
end loop;
|
|
|
|
--
|
2024-05-05 11:46:56 -04:00
|
|
|
for index in 1 .. 30 loop
|
|
|
|
map.constructions (index).index := core.random (0, construction.count - 1);
|
|
|
|
map.constructions (index).x := core.random (0, map.width - 1);
|
|
|
|
map.constructions (index).y := core.random (0, map.height - 1);
|
|
|
|
end loop;
|
|
|
|
--
|
|
|
|
for index in 1 .. 60 loop
|
|
|
|
map.items (index).index := core.random (0, item.count - 1);
|
|
|
|
map.items (index).x := core.random (0, map.width - 1);
|
|
|
|
map.items (index).y := core.random (0, map.height - 1);
|
|
|
|
end loop;
|
2024-05-05 11:38:15 -04:00
|
|
|
--
|
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
|
2024-05-05 11:46:56 -04:00
|
|
|
u : integer := 0;
|
|
|
|
v : integer := 0;
|
|
|
|
--
|
2024-05-01 14:41:55 -04:00
|
|
|
offset : core.vector := ((core.window_width - core.base) / 2,
|
|
|
|
(core.window_height - core.base) / 2);
|
2024-05-05 11:46:56 -04:00
|
|
|
--
|
|
|
|
render : core.vector := (map.width - 1,
|
2024-05-03 05:28:44 -04:00
|
|
|
map.height - 1);
|
2024-02-15 21:03:09 -05:00
|
|
|
begin
|
2024-05-03 05:28:44 -04:00
|
|
|
for vertical in 0 .. map.height - 1 loop
|
|
|
|
exit when offset.y + (vertical - core.camera.y) * core.base * core.zoom > core.window_height;
|
2024-05-01 13:27:41 -04:00
|
|
|
--
|
2024-05-03 05:28:44 -04:00
|
|
|
for horizontal in 0 .. map.width - 1 loop
|
|
|
|
exit when offset.x + (horizontal - core.camera.x) * core.base * core.zoom > core.window_width;
|
2024-05-01 13:27:41 -04:00
|
|
|
--
|
2024-04-27 07:03:40 -04:00
|
|
|
u := core.base * biome'pos (map.kind) * 4;
|
2024-05-03 05:28:44 -04:00
|
|
|
v := core.base * map.tiles (horizontal, vertical);
|
2024-02-15 21:03:09 -05:00
|
|
|
--
|
2024-05-01 13:27:41 -04:00
|
|
|
core.draw (data => tiles,
|
2024-05-03 05:28:44 -04:00
|
|
|
x => offset.x + (horizontal - core.camera.x) * core.base * core.zoom,
|
|
|
|
y => offset.y + (vertical - core.camera.y) * core.base * core.zoom,
|
2024-05-01 13:27:41 -04:00
|
|
|
u => u,
|
|
|
|
v => v,
|
2024-05-01 15:28:30 -04:00
|
|
|
width => core.base,
|
|
|
|
height => core.base);
|
2024-05-04 07:12:00 -04:00
|
|
|
--~--MOVE PLAYER TO TILE WHERE YOU CLICKED
|
2024-05-03 06:10:13 -04:00
|
|
|
--~if core.cursor.x > offset.x + (horizontal - core.camera.x ) * core.base * core.zoom
|
|
|
|
--~and core.cursor.x < offset.x + (horizontal - core.camera.x + 1) * core.base * core.zoom
|
2024-05-04 07:12:00 -04:00
|
|
|
--~and core.cursor.y > offset.y + (vertical - core.camera.y ) * core.base * core.zoom
|
|
|
|
--~and core.cursor.y < offset.y + (vertical - core.camera.y + 1) * core.base * core.zoom
|
|
|
|
--~and core.cursor_mode = 1 then
|
2024-05-03 06:10:13 -04:00
|
|
|
--~core.camera.x := horizontal;
|
|
|
|
--~core.camera.y := vertical;
|
|
|
|
--~core.cursor_mode := 0;
|
|
|
|
--~end if;
|
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
|
2024-05-05 11:38:15 -04:00
|
|
|
core.draw (data => landmarks (landmark_index'val (map.landmarks (index).index)),
|
2024-05-01 14:41:55 -04:00
|
|
|
x => offset.x + (map.landmarks (index).x - core.camera.x) * core.base * core.zoom,
|
|
|
|
y => offset.y + (map.landmarks (index).y - core.camera.y) * core.base * core.zoom);
|
2024-04-27 07:03:40 -04:00
|
|
|
end loop;
|
2024-05-05 11:46:56 -04:00
|
|
|
--
|
|
|
|
for index in 1 .. 30 loop
|
|
|
|
construction.draw (construction.enumeration'val (map.constructions (index).index),
|
|
|
|
offset.x + (map.constructions (index).x - core.camera.x) * core.base * core.zoom,
|
|
|
|
offset.y + (map.constructions (index).y - core.camera.y) * core.base * core.zoom);
|
|
|
|
end loop;
|
|
|
|
--
|
|
|
|
for index in 1 .. 60 loop
|
|
|
|
item.draw (item.enumeration'val (map.items (index).index),
|
|
|
|
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 loop;
|
2024-02-15 21:03:09 -05:00
|
|
|
end draw;
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
end world;
|