xabina/main.adb

142 lines
6.4 KiB
Ada
Raw Normal View History

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Copyright (c) 2023 - Ognjen 'xolatile' Milan Robovic
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Xabina is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either
-- version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
-- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Experimental minimal terminal rogue-like game in Ada programming language. I used to write a lot of Ada programs some time ago, then went in full C and assembly mode, and came
-- back to Ada, but realized that I keep my folders messy... Since it's bothersome to find my old Ada projects and share them here, I decided that the most easy thing to do is to
-- write a new program in Ada, a tiny game. Work in progress, it's messy and ugly for now...
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
with ada.text_io;
use ada.text_io;
with core, item, plant, animal, monster;
use core, item, plant, animal, monster;
function main return integer is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Menu
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Map
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
type map_list is (
MAP_STONE_WALL, MAP_WOODEN_WALL, MAP_STONE_FLOOR, MAP_WOODEN_FLOOR, MAP_WATER_SHALLOW, MAP_WATER_DEEP, MAP_SWAMP_SHALLOW, MAP_SWAMP_DEEP
);
------------------------------------------------------------------------------------------
type map_mark is mod 72;
type map_width is mod 120;
type map_height is mod 40;
type map_constant_type is new entity_constant_type with
record
collide : boolean := false;
condition_limit : natural := 0;
end record;
type map_variable_type is new entity_variable_type with
record
entity : entity_list := ENTITY_NULL;
identifier : natural := 0;
end record;
type map_matrical_type is
record
map : map_list := MAP_STONE_FLOOR;
condition : natural := 0;
end record;
type map_constant_list is array (map_list) of map_constant_type;
type map_variable_list is array (map_mark) of map_variable_type;
type map_matrical_list is array (map_height, map_width) of map_matrical_type;
------------------------------------------------------------------------------------------
map_constant_data : constant map_constant_list := (
(ENTITY_MAP, "Stone Wall ", '#', COLOUR_GREY, EFFECT_BOLD, true, 59),
(ENTITY_MAP, "Wooden Wall ", '#', COLOUR_YELLOW, EFFECT_NORMAL, false, 23),
(ENTITY_MAP, "Stone Floor ", '.', COLOUR_GREY, EFFECT_BOLD, true, 47),
(ENTITY_MAP, "Wooden Floor ", '.', COLOUR_YELLOW, EFFECT_NORMAL, false, 11),
(ENTITY_MAP, "Water (shallow) ", '~', COLOUR_BLUE, EFFECT_NORMAL, false, 0),
(ENTITY_MAP, "Water (deep) ", '~', COLOUR_BLUE, EFFECT_BOLD, true, 0),
(ENTITY_MAP, "Swamp (shallow) ", '~', COLOUR_GREEN, EFFECT_NORMAL, false, 0),
(ENTITY_MAP, "Swamp (deep) ", '~', COLOUR_GREEN, EFFECT_BOLD, true, 0)
);
map_variable_data : map_variable_list;
map_matrical_data : map_matrical_list;
------------------------------------------------------------------------------------------
procedure generate_map is
begin
for y in map_height
loop
for x in map_width
loop
map_matrical_data (y, x) := (MAP_WOODEN_FLOOR, map_constant_data (MAP_WOODEN_FLOOR).condition_limit);
end loop;
end loop;
end generate_map;
procedure render_map is
symbol : character := ' ';
colour : character := COLOUR_WHITE;
effect : character := EFFECT_NORMAL;
begin
for y in screen_height
loop
for x in screen_width
loop
symbol := map_constant_data (map_matrical_data (map_height (y), map_width (x)).map).symbol;
colour := map_constant_data (map_matrical_data (map_height (y), map_width (x)).map).colour;
effect := map_constant_data (map_matrical_data (map_height (y), map_width (x)).map).effect;
render_character (symbol, colour, effect, y, x);
end loop;
end loop;
end render_map;
begin
------------------------------------------------------------------------------------------
bind ('q', action_exit'access);
bind ('w', action_move_up'access);
bind ('s', action_move_down'access);
bind ('a', action_move_left'access);
bind ('d', action_move_right'access);
render_screen_delete;
render_screen_offset;
render_cursor_hide;
generate_map;
------------------------------------------------------------------------------------------
loop
signal := CANCEL;
render_map;
render_player;
render_screen;
get_immediate (signal);
action_list (character'pos (signal)).all;
exit when active = false;
end loop;
------------------------------------------------------------------------------------------
render_cursor_show;
return 0;
end main;