-- Copyright (c) 2024 - Ognjen 'xolatile' Milan Robovic -- -- GNU General Public Licence (version 3 or later) with core, ui, resource, item, unit, construction, world; package body world is ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 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.kind := index; map.width := width; map.height := height; map.tiles := new tile_array (0 .. map.width - 1, 0 .. map.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) := (core.random (0, 23) * core.random (0, 23)) 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.random (0, map.width - 1); map.landmarks (index).y := core.random (0, map.height - 1); end loop; -- core.echo (core.success, "Finished procedurally generating new map."); end make; ------------------------------------------------------------------------------------------ procedure draw is u : integer := 0; v : integer := 0; offset : core.vector := ((core.window_width - core.base) / 2, (core.window_height - core.base) / 2); render : core.vector := (map.width - 1, map.height - 1); begin for vertical in 0 .. map.height - 1 loop exit when offset.y + (vertical - core.camera.y) * core.base * core.zoom > core.window_height; -- for horizontal in 0 .. map.width - 1 loop exit when offset.x + (horizontal - core.camera.x) * core.base * core.zoom > core.window_width; -- u := core.base * biome'pos (map.kind) * 4; v := core.base * map.tiles (horizontal, vertical); -- core.draw (data => tiles, x => offset.x + (horizontal - core.camera.x) * core.base * core.zoom, y => offset.y + (vertical - core.camera.y) * core.base * core.zoom, u => u, v => v, width => core.base, height => core.base); --~--MOVE PLAYER TO TILE WHERE YOU CLICKED --~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 --~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 --~core.camera.x := horizontal; --~core.camera.y := vertical; --~core.cursor_mode := 0; --~end if; end loop; end loop; -- for index in 1 .. landmark_limit loop core.draw (data => landmarks (map.landmarks (index).index), 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); end loop; end draw; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ end world;