General reimplementation and simplification...

This commit is contained in:
Ognjen Milan Robovic 2023-10-11 12:39:17 -04:00
parent a2a7ccbc9e
commit b35a1d0c85

View File

@ -23,60 +23,6 @@ function xabina return integer is
-- System -- System
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SIGNAL_A : constant character := 'a';
SIGNAL_B : constant character := 'b';
SIGNAL_C : constant character := 'c';
SIGNAL_D : constant character := 'd';
SIGNAL_E : constant character := 'e';
SIGNAL_F : constant character := 'f';
SIGNAL_G : constant character := 'g';
SIGNAL_H : constant character := 'h';
SIGNAL_I : constant character := 'i';
SIGNAL_J : constant character := 'j';
SIGNAL_K : constant character := 'k';
SIGNAL_L : constant character := 'l';
SIGNAL_M : constant character := 'm';
SIGNAL_N : constant character := 'n';
SIGNAL_O : constant character := 'o';
SIGNAL_P : constant character := 'p';
SIGNAL_Q : constant character := 'q';
SIGNAL_R : constant character := 'r';
SIGNAL_S : constant character := 's';
SIGNAL_T : constant character := 't';
SIGNAL_U : constant character := 'u';
SIGNAL_V : constant character := 'v';
SIGNAL_W : constant character := 'w';
SIGNAL_X : constant character := 'x';
SIGNAL_Y : constant character := 'y';
SIGNAL_Z : constant character := 'z';
SIGNAL_0 : constant character := '0';
SIGNAL_1 : constant character := '1';
SIGNAL_2 : constant character := '2';
SIGNAL_3 : constant character := '3';
SIGNAL_4 : constant character := '4';
SIGNAL_5 : constant character := '5';
SIGNAL_6 : constant character := '6';
SIGNAL_7 : constant character := '7';
SIGNAL_8 : constant character := '8';
SIGNAL_9 : constant character := '9';
SIGNAL_DOT : constant character := '.';
SIGNAL_COMMA : constant character := ',';
SIGNAL_SEMICOLON : constant character := ';';
SIGNAL_SLASH : constant character := '/';
SIGNAL_BACKSLASH : constant character := '\';
SIGNAL_QUOTE : constant character := ''';
SIGNAL_BACKQUOTE : constant character := '`';
SIGNAL_SPACE : constant character := ' ';
SIGNAL_BACKSPACE : constant character := character'val ( 8);
SIGNAL_TABULATOR : constant character := character'val ( 9);
SIGNAL_LINE_FEED : constant character := character'val (13);
SIGNAL_IDLE : constant character := character'val (24);
type signal_list is mod 128;
COLOUR_GREY : constant character := '0'; COLOUR_GREY : constant character := '0';
COLOUR_RED : constant character := '1'; COLOUR_RED : constant character := '1';
COLOUR_GREEN : constant character := '2'; COLOUR_GREEN : constant character := '2';
@ -98,11 +44,9 @@ function xabina return integer is
LINE_FEED : constant character := character'val (13); LINE_FEED : constant character := character'val (13);
ESCAPE : constant character := character'val (27); ESCAPE : constant character := character'val (27);
function format_symbol ( function format_symbol (symbol : character := ' ';
symbol : character := ' '; colour : character := COLOUR_WHITE;
colour : character := COLOUR_WHITE; effect : character := EFFECT_NORMAL) return string is
effect : character := EFFECT_NORMAL
) return string is
format : string (1 .. 12) := escape & "[E;3CmS" & escape & "[0m"; format : string (1 .. 12) := escape & "[E;3CmS" & escape & "[0m";
begin begin
format (8) := symbol; format (8) := symbol;
@ -144,6 +88,9 @@ function xabina return integer is
-- -- Map data is only constant, not variable, since X and Y coordinates are determined by player, camera or global position. -- -- Map data is only constant, not variable, since X and Y coordinates are determined by player, camera or global position.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
type map_width is mod 120;
type map_height is mod 40;
type map_list is ( type map_list is (
STONE_WALL, WOODEN_WALL, STONE_FLOOR, WOODEN_FLOOR, WATER_SHALLOW, WATER_DEEP, SWAMP_SHALLOW, SWAMP_DEEP STONE_WALL, WOODEN_WALL, STONE_FLOOR, WOODEN_FLOOR, WATER_SHALLOW, WATER_DEEP, SWAMP_SHALLOW, SWAMP_DEEP
); );
@ -521,56 +468,72 @@ function xabina return integer is
-- Player -- Player
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
type player_data is
record
x : map_width := 0;
y : map_height := 0;
health : natural := 0;
armour : natural := 0;
mana : natural := 0;
stamina : natural := 0;
end record;
player : player_data;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Gameplay -- Gameplay
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ procedure action_idle;
-- Terminal
-- -- Currently constant, gonna use either my xurses library or <termios.h> C bindings.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
type procedure_pointer is access procedure; type procedure_pointer is access procedure;
type ascii_range is mod 2 ** 8;
type action_data is array (signal_list) of procedure_pointer; type action_data is array (ascii_range) of procedure_pointer;
active : boolean := true; active : boolean := true;
signal : character := SIGNAL_IDLE; signal : character := ' ';
width : natural := 120;
height : natural := 40;
buffer : unbounded_string := null_unbounded_string;
procedure action_idle is
begin
null;
end action_idle;
procedure action_exit is
begin
active := false;
end action_exit;
action_list : action_data := (others => action_idle'access); action_list : action_data := (others => action_idle'access);
procedure bind ( procedure bind (symbol : character := CANCEL;
key : character := SIGNAL_IDLE; action : procedure_pointer := action_idle'access) is
act : procedure_pointer := action_idle'access
) is
begin begin
action_list (character'pos (key)) := act; action_list (character'pos (symbol)) := action;
end bind; end bind;
procedure unbind ( procedure unbind (symbol : character := CANCEL) is
key : character := SIGNAL_IDLE
) is
begin begin
action_list (character'pos (key)) := action_idle'access; action_list (character'pos (symbol)) := action_idle'access;
end unbind; end unbind;
procedure action_draw is procedure action_idle is begin null; end action_idle;
procedure action_exit is begin active := false; end action_exit;
procedure action_move_up is begin player.y := player.y - 1; end action_move_up;
procedure action_move_down is begin player.y := player.y + 1; end action_move_down;
procedure action_move_left is begin player.x := player.x - 1; end action_move_left;
procedure action_move_right is begin player.x := player.x + 1; end action_move_right;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Render
-- -- Currently constant, gonna use either my xurses library or <termios.h> C bindings.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--~buffer_constant_data : string (1 .. 3 + 12 * 120 * 40 + 2 * 40);
--~buffer_constant_data : string (1 .. 3 + 12 * map_width * map_height + 2 * map_height);
--~buffer_variable_data : string (1 .. 3 + 12 * map_width * map_height + 2 * map_height);
procedure render is
begin begin
buffer := buffer & format_symbol ('@', COLOUR_RED, EFFECT_BOLD); put (ESCAPE & "[H");
end action_draw; for y in map_height
loop
for x in map_width
loop
put (format_symbol ('~', COLOUR_RED, EFFECT_BOLD));
end loop;
put (CARRIAGE_RETURN & LINE_FEED);
end loop;
end render;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Main -- Main
@ -578,68 +541,16 @@ function xabina return integer is
begin begin
bind (SIGNAL_Q, action_exit'access); bind ('q', action_exit'access);
bind (SIGNAL_E, action_draw'access);
loop loop
exit when active = false; exit when active = false;
buffer := to_unbounded_string (escape & "[H");
signal := CANCEL; signal := CANCEL;
for y in 1 .. height render;
loop
for x in 1 .. width
loop
buffer := buffer & format_symbol ('X', COLOUR_GREY, EFFECT_BOLD);
end loop;
buffer := buffer & carriage_return & line_feed;
end loop;
put (to_string (buffer)); -- still reachable
get_immediate (signal); get_immediate (signal);
action_list (character'pos (signal)).all; action_list (character'pos (signal)).all;
end loop; end loop;
--~for this in magic_list
--~loop
--~put_line (format_symbol (magic_constant_data (this).symbol, magic_constant_data (this).colour, magic_constant_data (this).effect)
--~& " "
--~& to_string (magic_constant_data (this).name));
--~end loop;
--~for this in item_list
--~loop
--~put_line (format_symbol (item_constant_data (this).symbol, item_constant_data (this).colour, item_constant_data (this).effect)
--~& " "
--~& to_string (item_constant_data (this).name));
--~end loop;
--~for this in ammunition_list
--~loop
--~put_line (format_symbol (ammunition_constant_data (this).symbol, ammunition_constant_data (this).colour, ammunition_constant_data (this).effect)
--~& " "
--~& to_string (ammunition_constant_data (this).name));
--~end loop;
--~for this in weapon_list
--~loop
--~put_line (format_symbol (weapon_constant_data (this).symbol, weapon_constant_data (this).colour, weapon_constant_data (this).effect)
--~& " "
--~& to_string (weapon_constant_data (this).name));
--~end loop;
--~for this in armour_list
--~loop
--~put_line (format_symbol (armour_constant_data (this).symbol, armour_constant_data (this).colour, armour_constant_data (this).effect)
--~& " "
--~& to_string (armour_constant_data (this).name));
--~end loop;
--~for this in plant_list
--~loop
--~put_line (format_symbol (plant_constant_data (this).symbol, plant_constant_data (this).colour, plant_constant_data (this).effect)
--~& " "
--~& to_string (plant_constant_data (this).name));
--~end loop;
return 0; return 0;
end xabina; end xabina;