From 9d5760b0d53d10a59e9a197826ae93fb1d90c33f Mon Sep 17 00:00:00 2001 From: xolatile Date: Wed, 20 Sep 2023 07:51:31 -0400 Subject: [PATCH] Uploading modification of Xera... --- compile.sh | 7 ++++ install.sh | 7 ++++ xero.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 compile.sh create mode 100644 install.sh create mode 100644 xero.c diff --git a/compile.sh b/compile.sh new file mode 100644 index 0000000..e8aa3da --- /dev/null +++ b/compile.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -xe + +gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -o xero xero.c + +exit diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..b505e1b --- /dev/null +++ b/install.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -xe + +cp xero /usr/bin/xero + +exit diff --git a/xero.c b/xero.c new file mode 100644 index 0000000..74931b6 --- /dev/null +++ b/xero.c @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic + * + * Xero is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation. + * And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version. + * It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3. + */ + +#include +#include + +enum { + ENTITY_TYPE_NONE, + ENTITY_TYPE_FOOD, + ENTITY_TYPE_COUNT +}; + +enum { + ENTITY_NULL, + ENTITY_APPLE, + ENTITY_LEMON, + ENTITY_WATERMELON, + ENTITY_PLAYER, + ENTITY_COUNT +}; + +static int map_width = 0; +static int map_height = 0; +static int * map = NULL; + +static int player_x = 0; +static int player_y = 0; + +static struct { + int type; + char symbol; + char symbol_alternative [3]; + int effect; + int colour; + char * name; + int value; + int logic; +} const entity_data [ENTITY_COUNT] = { + { ENTITY_TYPE_NONE, '.', " ", EFFECT_NORMAL, COLOUR_WHITE, "-", 0, 0 }, + { ENTITY_TYPE_FOOD, 'o', " ", EFFECT_BOLD, COLOUR_RED, "Apple", 2, 0 }, + { ENTITY_TYPE_FOOD, 'o', " ", EFFECT_BOLD, COLOUR_YELLOW, "Lemon", 3, 0 }, + { ENTITY_TYPE_FOOD, 'O', " ", EFFECT_BOLD, COLOUR_GREEN, "Watermelon", 5, 0 }, + { ENTITY_TYPE_NONE, '@', " ", EFFECT_BOLD, COLOUR_BLUE, "I", 0, 1 } +}; + +static void player_move_up (void) { --player_y; limit (& player_y, 0, map_height - 1); } +static void player_move_down (void) { ++player_y; limit (& player_y, 0, map_height - 1); } +static void player_move_left (void) { --player_x; limit (& player_x, 0, map_width - 1); } +static void player_move_right (void) { ++player_x; limit (& player_x, 0, map_width - 1); } + +static void map_render (void) { + int i = 0; + int j = 0; + + map [player_y * map_width + player_x] = ENTITY_PLAYER; + + for (i = 0; i != map_height; ++i) { + for (j = 0; j != map_width; ++j) { + int index = map [i * map_width + j]; + + char symbol = entity_data [index]. symbol; + int effect = entity_data [index]. effect; + int colour = entity_data [index]. colour; + + curses_render_character (symbol, colour, effect, j, i); + } + } +} + +int main (void) { + terminal_show_cursor (0); + + curses_initialize (); + + map_width = curses_screen_width; + map_height = curses_screen_height; + + map = allocate (map_width * map_height * (int) sizeof (* map)); + + curses_bind ('Q', curses_exit); + curses_bind ('w', player_move_up); + curses_bind ('s', player_move_down); + curses_bind ('a', player_move_left); + curses_bind ('d', player_move_right); + + while (curses_active != 0) { + map_render (); + + curses_synchronize (); + } + + curses_deinitialize (); + + map = deallocate (map); + + terminal_show_cursor (1); + + echo ("Good byte hero! (:\n"); + + return (EXIT_SUCCESS); +}