From 6b7f3246a6f1d2bbb2b9d6e05c4ea7f98e1b59ed Mon Sep 17 00:00:00 2001 From: xolatile Date: Sun, 30 Jun 2024 17:22:49 -0400 Subject: [PATCH] Added various gameplay elements... --- xungeons.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 12 deletions(-) diff --git a/xungeons.c b/xungeons.c index b56977e..3904824 100644 --- a/xungeons.c +++ b/xungeons.c @@ -2,15 +2,16 @@ #include #include #include +#include #include #include #include -#define level_width (256) -#define level_height (256) -#define members ( 6) -#define items ( 36) +#define level_width_limit (120) +#define level_height_limit ( 60) +#define members ( 6) +#define items ( 36) enum { normal = '0', bold = '1', italic = '2', blink = '5', reverse = '7' }; @@ -27,6 +28,14 @@ enum { fighting, blocking, shooting, spellcasting, evoking, trading, healing, lo enum { warrior, mage, thief, priest, archer, alchemist, warlock, merchant, classes }; static struct { + char clip, style, colour, symbol; +} const tiles [] = { + { 1, normal, white, ' ' }, + { 0, bold, grey, '.' }, + { 1, bold, grey, '#' } +}; + +static struct { char * name, damage, condition, value, spell, type, style, colour, symbol; } const weapons [] = { { "Bone Dagger", 1, 11, 5, 0, cut, bold, yellow, '!' }, @@ -75,8 +84,9 @@ static int signal; static int screen_width; static int screen_height; static char * screen; - -static char * map; +static int level_width; +static int level_height; +static char * level; static void screen_add (char style, char colour, char symbol, int x, int y) { char format [] = "\033[ ;3 m \033[0m"; @@ -158,8 +168,8 @@ static void synchronize_screen (void) { default: break; } - player.x = (player.x > level_width) ? (level_width - 1) : ((player.x < 0) ? 0 : player.x); - player.y = (player.y > level_height) ? (level_height - 1) : ((player.y < 0) ? 0 : player.y); + player.x = (char) ((player.x > level_width) ? (level_width) : ((player.x < 0) ? 0 : player.x)); + player.y = (char) ((player.y > level_height) ? (level_height) : ((player.y < 0) ? 0 : player.y)); } static void generate_party (void) { @@ -188,23 +198,56 @@ static void generate_party (void) { } static void generate_level (void) { + int room, i, j, x, y, width, height; + level_width = rand () % level_width_limit / 2 + level_width_limit / 2; + level_height = rand () % level_height_limit / 2 + level_height_limit / 2; + + level = calloc ((unsigned long int) (level_width * level_height), sizeof (* level)); + + for (room = rand () % 12 + 6; room > 1; --room) { + width = rand () % 24 + 12; + height = rand () % 24 + 12; + x = rand () % (level_width - width); + y = rand () % (level_height - height); + for (i = 1; i < height - 1; ++i) { + for (j = 1; j < width - 1; ++j) { + level [(i + y) * level_width + (j + x)] = 1; + } + } + for (i = 0; i < height; ++i) { + level [(i + y) * level_width + x] = 2; + level [(i + y) * level_width + x + width - 1] = 2; + } + for (j = 0; j < width; ++j) { + level [y * level_width + j + x] = 2; + level [(y + height - 1) * level_width + j + x] = 2; + } + } } int main (void) { - int x, y; + int i, x, y; initialize_screen (); + srand ((unsigned long) time (NULL)); + generate_party (); generate_level (); while (signal != 'Q') { for (y = 0; y < screen_height; ++y) { - for (x = 0; x < screen_width - 1; ++x) { - screen_add (bold, grey, '.', x, y); + for (x = 0; x < screen_width; ++x) { + screen_add (tiles [0].style, tiles [0].colour, tiles [0].symbol, x, y); + } + } + + for (y = 0; (y < level_height) && (y < screen_height); ++y) { + for (x = 0; (x < level_width) && (x < screen_width); ++x) { + i = (int) level [y * level_width + x]; + screen_add (tiles [i].style, tiles [i].colour, tiles [i].symbol, x, y); } - screen_add (bold, red, '#', x, y); } screen_add (bold, cyan, '@', player.x, player.y); @@ -212,7 +255,11 @@ int main (void) { synchronize_screen (); } + free (level); + deinitialize_screen (); + printf ("L: %i x %i\n", level_width, level_height); + return (0); }