Further generation updates...
This commit is contained in:
parent
6b7f3246a6
commit
e8cf8033e3
58
xungeons.c
58
xungeons.c
@ -2,7 +2,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
@ -13,6 +12,8 @@
|
||||
#define members ( 6)
|
||||
#define items ( 36)
|
||||
|
||||
#define random(from, to) (rand () % (to - from + 1) + from)
|
||||
|
||||
enum { normal = '0', bold = '1', italic = '2', blink = '5', reverse = '7' };
|
||||
|
||||
enum { grey = '0', red = '1', green = '2', yellow = '3', blue = '4', pink = '5', cyan = '6', white = '7' };
|
||||
@ -88,7 +89,7 @@ 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) {
|
||||
static void screen_put (char style, char colour, char symbol, int x, int y) {
|
||||
char format [] = "\033[ ;3 m \033[0m";
|
||||
|
||||
format [2] = style;
|
||||
@ -98,6 +99,14 @@ static void screen_add (char style, char colour, char symbol, int x, int y) {
|
||||
strncpy (& screen [(y * screen_width + x) * 12 + 3], format, sizeof (format) - 1);
|
||||
}
|
||||
|
||||
static void screen_print (char style, char colour, char * text, int x, int y, int limit) {
|
||||
int i;
|
||||
|
||||
for (i = 0; (text [i] != '\0') && (i < limit); ++i) {
|
||||
screen_put (style, colour, text [i], x + i, y);
|
||||
}
|
||||
}
|
||||
|
||||
static void initialize_screen (void) {
|
||||
struct winsize screen_dimension;
|
||||
|
||||
@ -184,13 +193,13 @@ static void generate_party (void) {
|
||||
}
|
||||
|
||||
for (i = 0; i < members; ++i) {
|
||||
player.weapon [i] = rand () % 3;
|
||||
player.armour [i] = rand () % 3;
|
||||
player.weapon [i] = random (0, 3);
|
||||
player.armour [i] = random (0, 3);
|
||||
for (j = 0; j < points; ++j) {
|
||||
player.point [i] [j] = rand () % 12 + 12;
|
||||
player.point [i] [j] = random (12, 24);
|
||||
}
|
||||
for (j = 0; j < attributes; ++j) {
|
||||
player.attribute [i] [j] = rand () % 6 + 1;
|
||||
player.attribute [i] [j] = random (1, 4);
|
||||
}
|
||||
player.skill [i] = rand () % skills;
|
||||
player.class [i] = rand () % classes;
|
||||
@ -200,16 +209,16 @@ 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_width = random (level_width_limit / 2, level_width_limit);
|
||||
level_height = random (level_height_limit / 2, level_height_limit);
|
||||
|
||||
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 (room = random (6, 18); room > 1; --room) {
|
||||
width = random (12, 36);
|
||||
height = random (12, 36);
|
||||
x = random (1, level_width - width - 1);
|
||||
y = random (1, level_height - height - 1);
|
||||
for (i = 1; i < height - 1; ++i) {
|
||||
for (j = 1; j < width - 1; ++j) {
|
||||
level [(i + y) * level_width + (j + x)] = 1;
|
||||
@ -224,14 +233,23 @@ static void generate_level (void) {
|
||||
level [(y + height - 1) * level_width + j + x] = 2;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 1; i < level_height - 1; ++i) {
|
||||
for (j = 1; j < level_width - 1; ++j) {
|
||||
if (((level [i * level_width + (j - 1)] == 1) && (level [i * level_width + j] == 2) && (level [i * level_width + (j + 1)] == 1)) ||
|
||||
((level [(i - 1) * level_width + j] == 1) && (level [i * level_width + j] == 2) && (level [(i + 1) * level_width + j] == 1))) {
|
||||
level [i * level_width + j] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main (void) {
|
||||
int i, x, y;
|
||||
|
||||
initialize_screen ();
|
||||
srand (time (0));
|
||||
|
||||
srand ((unsigned long) time (NULL));
|
||||
initialize_screen ();
|
||||
|
||||
generate_party ();
|
||||
generate_level ();
|
||||
@ -239,18 +257,20 @@ int main (void) {
|
||||
while (signal != 'Q') {
|
||||
for (y = 0; y < screen_height; ++y) {
|
||||
for (x = 0; x < screen_width; ++x) {
|
||||
screen_add (tiles [0].style, tiles [0].colour, tiles [0].symbol, x, y);
|
||||
screen_put (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_put (tiles [i].style, tiles [i].colour, tiles [i].symbol, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
screen_add (bold, cyan, '@', player.x, player.y);
|
||||
screen_put (bold, cyan, '@', player.x, player.y);
|
||||
|
||||
screen_print (bold, grey, "Warrior", screen_width - 24, 0, 24);
|
||||
|
||||
synchronize_screen ();
|
||||
}
|
||||
@ -259,7 +279,5 @@ int main (void) {
|
||||
|
||||
deinitialize_screen ();
|
||||
|
||||
printf ("L: %i x %i\n", level_width, level_height);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user