|
|
@@ -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 <xolatile/xurses.h> |
|
|
|
#include <xolatile/xurses.c> |
|
|
|
|
|
|
|
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); |
|
|
|
} |