Added seen areas.
This commit is contained in:
115
src/in_game.c
115
src/in_game.c
@@ -18,6 +18,7 @@ typedef struct PLAYER {
|
|||||||
} player_t;
|
} player_t;
|
||||||
|
|
||||||
static bool **vis;
|
static bool **vis;
|
||||||
|
static bool **seen;
|
||||||
static bool ** wmap;
|
static bool ** wmap;
|
||||||
static bool w_mov = FALSE;
|
static bool w_mov = FALSE;
|
||||||
static bool uK, dK, lK, rK;
|
static bool uK, dK, lK, rK;
|
||||||
@@ -34,8 +35,7 @@ void render(int, int);
|
|||||||
void drawGui(int, int);
|
void drawGui(int, int);
|
||||||
void setPlayerStart();
|
void setPlayerStart();
|
||||||
void initObjects();
|
void initObjects();
|
||||||
void drawNeon(int, int);
|
void drawNeon(int, int, floor_t);
|
||||||
void drawBar(int, int);
|
|
||||||
void apply(void *, int, int, int, int, void *);
|
void apply(void *, int, int, int, int, void *);
|
||||||
bool opaque(void *, int, int);
|
bool opaque(void *, int, int);
|
||||||
|
|
||||||
@@ -61,10 +61,13 @@ void initInGameState( gs_t * gs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
vis = ( bool ** ) malloc ( sizeof ( bool * ) * MAX_MAP_SIZE);
|
vis = ( bool ** ) malloc ( sizeof ( bool * ) * MAX_MAP_SIZE);
|
||||||
|
seen = ( bool ** ) malloc ( sizeof ( bool * ) * MAX_MAP_SIZE);
|
||||||
for ( i = 0; i < MAX_MAP_SIZE; ++i ) {
|
for ( i = 0; i < MAX_MAP_SIZE; ++i ) {
|
||||||
vis[ i ] = ( bool * ) calloc ( MAX_MAP_SIZE, sizeof ( bool ) );
|
vis[ i ] = ( bool * ) calloc ( MAX_MAP_SIZE, sizeof ( bool ) );
|
||||||
|
seen[ i ] = ( bool * ) calloc ( MAX_MAP_SIZE, sizeof ( bool ) );
|
||||||
for(j = 0; j < MAX_MAP_SIZE; ++j){
|
for(j = 0; j < MAX_MAP_SIZE; ++j){
|
||||||
vis[i][j] = TRUE;
|
vis[i][j] = TRUE;
|
||||||
|
seen[i][j] = FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +169,7 @@ void render(int w, int h){
|
|||||||
if( di < 0 || di >= mW || dj < 0 || dj >= mH ){
|
if( di < 0 || di >= mW || dj < 0 || dj >= mH ){
|
||||||
printw(" ");
|
printw(" ");
|
||||||
}else{
|
}else{
|
||||||
if(vis[dj][di]){
|
if(vis[dj][di] || seen[dj][di]){
|
||||||
switch(map[dj][di].f){
|
switch(map[dj][di].f){
|
||||||
case WATER:
|
case WATER:
|
||||||
attron(COLOR_PAIR(DW_COLOR));
|
attron(COLOR_PAIR(DW_COLOR));
|
||||||
@@ -179,42 +182,48 @@ void render(int w, int h){
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VOID:
|
case VOID:
|
||||||
attron(COLOR_PAIR(MN_COLOR));
|
if(!vis[dj][di]) attron(COLOR_PAIR(DW_COLOR));
|
||||||
|
else attron(COLOR_PAIR(MN_COLOR));
|
||||||
printw(" ");
|
printw(" ");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EMPTY_FLOOR:
|
case EMPTY_FLOOR:
|
||||||
attron(COLOR_PAIR(MN_COLOR));
|
if(!vis[dj][di]) attron(COLOR_PAIR(DW_COLOR));
|
||||||
|
else attron(COLOR_PAIR(MN_COLOR));
|
||||||
printw(" ");
|
printw(" ");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RUG:
|
case RUG:
|
||||||
attron(COLOR_PAIR(SN_COLOR));
|
if(!vis[dj][di]) attron(COLOR_PAIR(DW_COLOR));
|
||||||
|
else attron(COLOR_PAIR(SN_COLOR));
|
||||||
printw("\u2592");
|
printw("\u2592");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WINDOW_WALL:
|
case WINDOW_WALL:
|
||||||
attron(COLOR_PAIR(SW_COLOR));
|
if(!vis[dj][di]) attron(COLOR_PAIR(DW_COLOR));
|
||||||
|
else attron(COLOR_PAIR(SW_COLOR));
|
||||||
printw("\u2591");
|
printw("\u2591");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CLEAR_WALL:
|
case CLEAR_WALL:
|
||||||
attron(COLOR_PAIR(SW_COLOR));
|
if(!vis[dj][di]) attron(COLOR_PAIR(DW_COLOR));
|
||||||
|
else attron(COLOR_PAIR(SW_COLOR));
|
||||||
printw("\u2588");
|
printw("\u2588");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SECRET_WALL:
|
case SECRET_WALL:
|
||||||
case SOLID_WALL:
|
case SOLID_WALL:
|
||||||
attron(COLOR_PAIR(MN_COLOR));
|
if(!vis[dj][di]) attron(COLOR_PAIR(DW_COLOR));
|
||||||
|
else attron(COLOR_PAIR(MN_COLOR));
|
||||||
printw("\u2588");
|
printw("\u2588");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NEON_WALL:
|
case NEON_WALL:
|
||||||
drawNeon(dj, di);
|
drawNeon(dj, di, NEON_WALL);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BAR:
|
case BAR:
|
||||||
drawBar(dj, di);
|
drawNeon(dj, di, BAR);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
@@ -239,76 +248,28 @@ void render(int w, int h){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawNeon(int i, int j){
|
void drawNeon(int i, int j, floor_t floor){
|
||||||
|
int r;
|
||||||
bool n, s, e, w;
|
bool n, s, e, w;
|
||||||
|
|
||||||
|
if(floor == NEON_WALL){
|
||||||
|
if(!vis[i][j]) attron(COLOR_PAIR(DW_COLOR));
|
||||||
|
else{
|
||||||
|
r = rand() % 1000;
|
||||||
|
if(r < 998)
|
||||||
attron(COLOR_PAIR(FR_COLOR));
|
attron(COLOR_PAIR(FR_COLOR));
|
||||||
|
else
|
||||||
n = map[i ][j - 1 < 0 ? mH - 1 : j - 1].f == NEON_WALL;
|
attron(COLOR_PAIR(MN_COLOR));
|
||||||
s = map[i ][(j + 1) % mH ].f == NEON_WALL;
|
}
|
||||||
e = map[i - 1 < 0 ? mW - 1 : i - 1][j ].f == NEON_WALL;
|
}else if(floor == BAR){
|
||||||
w = map[(i + 1) % mW ][j ].f == NEON_WALL;
|
if(!vis[i][j]) attron(COLOR_PAIR(DW_COLOR));
|
||||||
|
else attron(COLOR_PAIR(SN_COLOR));
|
||||||
if((n && s && e) && (!w)){
|
|
||||||
printw("\u2560");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if((n || s) && (!e && !w)){
|
n = map[i ][j - 1 < 0 ? mH - 1 : j - 1].f == floor;
|
||||||
printw("\u2550");
|
s = map[i ][(j + 1) % mH ].f == floor;
|
||||||
return;
|
e = map[i - 1 < 0 ? mW - 1 : i - 1][j ].f == floor;
|
||||||
}
|
w = map[(i + 1) % mW ][j ].f == floor;
|
||||||
|
|
||||||
if((e || w) && (!n && !s)){
|
|
||||||
printw("\u2551");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((e && n) && (!s && !w)){
|
|
||||||
printw("\u255D");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((w && n) && (!s && !e)){
|
|
||||||
printw("\u2557");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((e && s) && (!n && !w)){
|
|
||||||
printw("\u255A");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((w && s) && (!n && !e)){
|
|
||||||
printw("\u2554");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((s && e && w) && (!n)){
|
|
||||||
printw("\u2560");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if((n && w && e) && (!s)){
|
|
||||||
printw("\u2563");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(n && s && e && w){
|
|
||||||
printw("\u256C");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawBar(int i, int j){
|
|
||||||
bool n, s, e, w;
|
|
||||||
|
|
||||||
attron(COLOR_PAIR(SN_COLOR));
|
|
||||||
|
|
||||||
n = map[i ][j - 1 < 0 ? mH - 1 : j - 1].f == BAR;
|
|
||||||
s = map[i ][(j + 1) % mH ].f == BAR;
|
|
||||||
e = map[i - 1 < 0 ? mW - 1 : i - 1][j ].f == BAR;
|
|
||||||
w = map[(i + 1) % mW ][j ].f == BAR;
|
|
||||||
|
|
||||||
if((n && s && e) && (!w)){
|
if((n && s && e) && (!w)){
|
||||||
printw("\u2560");
|
printw("\u2560");
|
||||||
@@ -444,7 +405,9 @@ void initObjects(){
|
|||||||
void apply(void *map, int x, int y, int dx, int dy, void *src){
|
void apply(void *map, int x, int y, int dx, int dy, void *src){
|
||||||
if(x < 0 || x >= MAX_MAP_SIZE) return;
|
if(x < 0 || x >= MAX_MAP_SIZE) return;
|
||||||
if(y < 0 || y >= MAX_MAP_SIZE) return;
|
if(y < 0 || y >= MAX_MAP_SIZE) return;
|
||||||
|
|
||||||
vis[y][x] = TRUE;
|
vis[y][x] = TRUE;
|
||||||
|
seen[y][x] = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool opaque(void *m, int x, int y){
|
bool opaque(void *m, int x, int y){
|
||||||
|
Reference in New Issue
Block a user