------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -- 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... ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ package body core is ------------------------------------------------------------------------------------------ procedure bind (symbol : character := CANCEL; action : procedure_pointer := action_idle'access) is begin action_list (character'pos (symbol)) := action; end bind; procedure unbind (symbol : character := CANCEL) is begin action_list (character'pos (symbol)) := action_idle'access; end unbind; 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; procedure render_screen_delete is begin put (ESCAPE & "[2J"); end render_screen_delete; procedure render_screen_offset is begin put (ESCAPE & "[H"); end render_screen_offset; procedure render_cursor_hide is begin put (ESCAPE & "[?25l"); end render_cursor_hide; procedure render_cursor_show is begin put (ESCAPE & "[?25h"); end render_cursor_show; procedure render_realignment is begin put (CARRIAGE_RETURN & LINE_FEED); end render_realignment; procedure render_character (symbol : character := ' '; colour : character := '7'; effect : character := '0'; y : screen_height := 0; x : screen_width := 0) is begin screen_symbol (y, x) := symbol; screen_colour (y, x) := colour; screen_effect (y, x) := effect; end render_character; procedure render_screen is format : string (1 .. 12) := ESCAPE & "[E;3CmS" & ESCAPE & "[0m"; begin render_screen_offset; for y in screen_height loop for x in screen_width loop format (8) := screen_symbol (y, x); format (6) := screen_colour (y, x); format (3) := screen_effect (y, x); put (format); end loop; render_realignment; end loop; end render_screen; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -- Player ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ procedure render_player is begin render_character ('@', core.colour.cyan, core.effect.bold, screen_height (player.y), screen_width (player.x)); end render_player; end core;