Movement offset, camera to world projection...
This commit is contained in:
parent
dfe83eae72
commit
fef67ce320
78
xungeons.c
78
xungeons.c
@ -7,12 +7,15 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#define level_width_limit (120)
|
#define level_width_limit (128)
|
||||||
#define level_height_limit ( 60)
|
#define level_height_limit ( 64)
|
||||||
#define members ( 6)
|
#define members ( 6)
|
||||||
#define items ( 36)
|
#define items ( 36)
|
||||||
|
|
||||||
#define random(from, to) (rand () % (to - from + 1) + from)
|
#define random(from, to) (rand () % (to - from + 1) + from)
|
||||||
|
#define minimum(a, b) ((a < b) ? a : b)
|
||||||
|
#define maximum(a, b) ((a > b) ? a : b)
|
||||||
|
#define clamp(x, a, b) ((x < a) ? a : (x > b) ? b : x)
|
||||||
|
|
||||||
enum { normal = '0', bold = '1', italic = '2', blink = '5', reverse = '7' };
|
enum { normal = '0', bold = '1', italic = '2', blink = '5', reverse = '7' };
|
||||||
|
|
||||||
@ -177,33 +180,8 @@ static void synchronize_screen (void) {
|
|||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.x = (char) ((player.x > level_width) ? (level_width) : ((player.x < 0) ? 0 : player.x));
|
player.x = clamp (player.x, 0, (char) level_width);
|
||||||
player.y = (char) ((player.y > level_height) ? (level_height) : ((player.y < 0) ? 0 : player.y));
|
player.y = clamp (player.y, 0, (char) level_height);
|
||||||
}
|
|
||||||
|
|
||||||
static void generate_party (void) {
|
|
||||||
int i, j;
|
|
||||||
|
|
||||||
player.x = 0;
|
|
||||||
player.y = 0;
|
|
||||||
player.coins = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < items; ++i) {
|
|
||||||
player.inventory [i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < members; ++i) {
|
|
||||||
player.weapon [i] = random (0, 3);
|
|
||||||
player.armour [i] = random (0, 3);
|
|
||||||
for (j = 0; j < points; ++j) {
|
|
||||||
player.point [i] [j] = random (12, 24);
|
|
||||||
}
|
|
||||||
for (j = 0; j < attributes; ++j) {
|
|
||||||
player.attribute [i] [j] = random (1, 4);
|
|
||||||
}
|
|
||||||
player.skill [i] = rand () % skills;
|
|
||||||
player.class [i] = rand () % classes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void generate_level (void) {
|
static void generate_level (void) {
|
||||||
@ -215,8 +193,8 @@ static void generate_level (void) {
|
|||||||
level = calloc ((unsigned long int) (level_width * level_height), sizeof (* level));
|
level = calloc ((unsigned long int) (level_width * level_height), sizeof (* level));
|
||||||
|
|
||||||
for (room = random (6, 18); room > 1; --room) {
|
for (room = random (6, 18); room > 1; --room) {
|
||||||
width = random (level_width / 6, level_width / 2);
|
width = random (5, level_width / 2);
|
||||||
height = random (level_height / 6, level_height / 2);
|
height = random (5, level_height / 2);
|
||||||
x = random (1, level_width - width - 1);
|
x = random (1, level_width - width - 1);
|
||||||
y = random (1, level_height - height - 1);
|
y = random (1, level_height - height - 1);
|
||||||
for (i = 1; i < height - 1; ++i) {
|
for (i = 1; i < height - 1; ++i) {
|
||||||
@ -244,6 +222,34 @@ static void generate_level (void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void generate_party (void) {
|
||||||
|
int i, j;
|
||||||
|
|
||||||
|
player.coins = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < items; ++i) {
|
||||||
|
player.inventory [i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < members; ++i) {
|
||||||
|
player.weapon [i] = random (0, 3);
|
||||||
|
player.armour [i] = random (0, 3);
|
||||||
|
for (j = 0; j < points; ++j) {
|
||||||
|
player.point [i] [j] = random (12, 24);
|
||||||
|
}
|
||||||
|
for (j = 0; j < attributes; ++j) {
|
||||||
|
player.attribute [i] [j] = random (1, 4);
|
||||||
|
}
|
||||||
|
player.skill [i] = rand () % skills;
|
||||||
|
player.class [i] = rand () % classes;
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
player.x = (char) (rand () % level_width);
|
||||||
|
player.y = (char) (rand () % level_height);
|
||||||
|
} while (level [player.y * level_width + player.x] != 1);
|
||||||
|
}
|
||||||
|
|
||||||
int main (void) {
|
int main (void) {
|
||||||
int i, x, y;
|
int i, x, y;
|
||||||
|
|
||||||
@ -251,8 +257,8 @@ int main (void) {
|
|||||||
|
|
||||||
initialize_screen ();
|
initialize_screen ();
|
||||||
|
|
||||||
generate_party ();
|
|
||||||
generate_level ();
|
generate_level ();
|
||||||
|
generate_party ();
|
||||||
|
|
||||||
while (signal != 'Q') {
|
while (signal != 'Q') {
|
||||||
for (y = 0; y < screen_height; ++y) {
|
for (y = 0; y < screen_height; ++y) {
|
||||||
@ -261,14 +267,14 @@ int main (void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (y = 0; (y < level_height) && (y < screen_height); ++y) {
|
for (y = 0; (y < screen_height) && (y + player.y < level_height - 1); ++y) {
|
||||||
for (x = 0; (x < level_width) && (x < screen_width); ++x) {
|
for (x = 0; (x < screen_width) && (x + player.x < level_width - 1); ++x) {
|
||||||
i = (int) level [y * level_width + x];
|
i = (int) level [(y + player.y) * level_width + (x + player.x)];
|
||||||
screen_put (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_put (bold, cyan, '@', player.x, player.y);
|
screen_put (bold, cyan, '@', screen_width / 2, screen_height / 2);
|
||||||
|
|
||||||
screen_print (bold, grey, "Warrior", screen_width - 24, 0, 24);
|
screen_print (bold, grey, "Warrior", screen_width - 24, 0, 24);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user