Minor changes before going to bed...

This commit is contained in:
Ognjen Milan Robovic 2024-04-26 19:46:09 -04:00
parent 8afc4fb6ef
commit 2f62c204bf
18 changed files with 91 additions and 97 deletions

View File

@ -22,7 +22,7 @@ package body item is
folder : constant string := core.lowercase (slot'image (trait (index).kind));
file : constant string := core.lowercase (enumeration'image (index));
begin
sprite (index) := core.import_sprite ("./sprite/item/" & folder & "/" & file & ".png", 1, 1);
sprite (index) := core.import_sprite ("./sprite/item/" & folder & "/" & file & ".png", 4, 6);
end;
end loop;
end configure;

View File

@ -144,8 +144,8 @@ begin
--
ui.active := (if core.cursor_mode = 3 then ui.default else ui.steam);
--
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);
core.camera.x := core.clip (core.camera.x, 0, world.width - preview_width / core.base);
core.camera.y := core.clip (core.camera.y, 0, world.height - preview_height / core.base);
--
world.draw (preview_x, preview_y, preview_width - 2 * preview_x, preview_height - 2 * preview_y - 32);
--

View File

@ -8,24 +8,54 @@ package body world is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
type sprite_array is array (natural range <>) of core.sprite;
type landmark_index is (
dead_tree, mossy_rock, palm_tree, pine_tree, reeds, rock, snowed_pine_tree, snowed_rock, spiky_rock
);
type world_array is array (natural range <>) of access information;
type landmark_trait is record
spawn : biome;
clip : boolean;
frames : integer;
end record;
type limit_array is array (enumeration) of integer;
type landmark_value is record
index : landmark_index;
x : integer;
y : integer;
end record;
type landmark_sprite_array is array (enumeration) of access sprite_array;
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;
------------------------------------------------------------------------------------------
blocks : core.sprite;
landmarks : landmark_sprite_array := (others => null);
map : information;
limit : constant limit_array := (2, 2, 2, 2, 2, 2);
tiles : core.sprite;
landmarks : array (landmark_index) of core.sprite;
landmark_limit : constant integer := 140;
construction_limit : constant integer := 40;
item_limit : constant integer := 40;
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)
);
------------------------------------------------------------------------------------------
@ -33,27 +63,19 @@ package body world is
begin
core.echo (core.comment, "Configuring world components...");
--
blocks := core.import_sprite ("./sprite/world/terrain/terrain.png", 1, 1);
tiles := core.import_sprite ("./sprite/world/terrain/terrain.png", 1, 1);
--
for index in enumeration
loop
landmarks (index) := new sprite_array (0 .. limit (index) - 1);
--
for value in 0 .. limit (index) - 1
loop
declare
folder : constant string := core.lowercase (enumeration'image (index));
file : constant string := value'image;
begin
landmarks (index) (value) := core.import_sprite ("./sprite/world/landmark/" & folder & "/" & file & ".png", 1, 1);
end;
end loop;
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 enumeration; width, height : in natural) is
procedure make (index : in biome; width, height : in natural) is
begin
core.echo (core.comment, "-- Procedurally generating new map...");
--
@ -61,30 +83,23 @@ package body world is
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);
core.echo (core.comment, "-- -- Construction count :" & construction_limit'image);
core.echo (core.comment, "-- -- Item count :" & item_limit'image);
--
map.terrain := index;
map.width := width;
map.height := height;
map.block := new block_array (0 .. width - 1, 0 .. height - 1);
map.landmark := new entity_array (0 .. landmark_limit);
map.construction := new entity_array (0 .. construction_limit);
map.item := new entity_array (0 .. item_limit);
map.terrain := index;
map.width := width;
map.height := height;
map.tiles := new tile_array (1 .. width, 1 .. height);
map.landmarks := new landmark_array (1 .. landmark_limit);
--
for x in 0 .. width - 1
loop
for y in 0 .. height - 1
loop
map.block (x, y) := (x * x + x * y + y * y) mod 24;
for x in 1 .. width loop
for y in 1 .. height loop
map.tiles (x, y) := (x * x + x * y + y * y) mod 24;
end loop;
end loop;
--
for object in 0 .. landmark_limit
loop
map.landmark (object).index := core.random (0, limit (index) - 1);
map.landmark (object).x := core.base * core.random (1, map.width - 1);
map.landmark (object).y := core.base * core.random (1, map.height - 1);
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, 12);
map.landmarks (index).y := core.base * core.random (1, 12);
end loop;
--
core.echo (core.success, "Finished procedurally generating new map.");
@ -97,44 +112,45 @@ package body world is
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
loop
u := core.base * enumeration'pos (map.terrain) * 4;
v := core.base * map.block (core.camera.x + move_x, core.camera.y + move_y);
for move_y in 1 .. height / core.base loop
for move_x in 1 .. width / core.base 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 (blocks, x + move_x * core.base, y + move_y * core.base, u, v, core.base, core.base);
core.draw (tiles, 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);
u := core.base * biome'pos (map.terrain) * 4;
v := core.base * map.tiles (width / core.base, core.camera.y + move_y);
--
core.draw (blocks, x + width - crop_width, y + move_y * core.base, u, v, crop_width, core.base);
core.draw (tiles, 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
loop
u := core.base * enumeration'pos (map.terrain) * 4;
v := core.base * map.block (core.camera.x + move_x, height / core.base);
for move_x in 1 .. width / core.base loop
u := core.base * biome'pos (map.terrain) * 4;
v := core.base * map.tiles (core.camera.x + move_x, height / core.base);
--
core.draw (blocks, x + move_x * core.base, y + height - crop_height, u, v, core.base, crop_height);
core.draw (tiles, 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);
u := core.base * biome'pos (map.terrain) * 4;
v := core.base * map.tiles (width / core.base, height / core.base);
--
core.draw (blocks, x + width - crop_width, y + height - crop_height, u, v, crop_width, crop_height);
core.draw (tiles, x + width - crop_width, y + height - crop_height, u, v, crop_width, crop_height);
--
for object in 0 .. landmark_limit
loop
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,
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, width, height);
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;

View File

@ -8,43 +8,21 @@ package world is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
type enumeration is (
type biome is (
ash, cave, grass, rough, snow, swamp
);
------------------------------------------------------------------------------------------
type entity is
record
index, x, y : integer;
end record;
type block_array is array (natural range <>, natural range <>) of integer;
type entity_array is array (natural range <>) of entity;
type information is
record
terrain : enumeration;
width : natural;
height : natural;
block : access block_array;
landmark : access entity_array;
construction : access entity_array;
item : access entity_array;
end record;
------------------------------------------------------------------------------------------
map : information;
------------------------------------------------------------------------------------------
procedure configure;
procedure make (index : in enumeration; width, height : in natural);
procedure make (index : in biome; width, height : in natural);
procedure draw (x, y, width, height : in integer);
function width return integer;
function height return integer;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
end world;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 288 B

View File

Before

Width:  |  Height:  |  Size: 288 B

After

Width:  |  Height:  |  Size: 288 B

View File

Before

Width:  |  Height:  |  Size: 239 B

After

Width:  |  Height:  |  Size: 239 B

View File

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

Before

Width:  |  Height:  |  Size: 190 B

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 215 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 190 B

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 217 B

After

Width:  |  Height:  |  Size: 217 B

View File

Before

Width:  |  Height:  |  Size: 215 B

After

Width:  |  Height:  |  Size: 215 B