Map successfully rendered.
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
void initStateArray(gs_t ** s){
|
void initStateArray(gs_t ** s){
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < NUM_STATES; i++){
|
/*for(i = 0; i < NUM_STATES; i++){*/
|
||||||
initInGameState(&((*s)[i]));
|
initInGameState(&((*s)[2]));
|
||||||
}
|
/*}*/
|
||||||
}
|
}
|
||||||
|
|||||||
303
src/in_game.c
303
src/in_game.c
@@ -6,7 +6,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <ncursesw/ncurses.h>
|
#include <ncursesw/ncurses.h>
|
||||||
#include <island.h>
|
|
||||||
|
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "in_game.h"
|
#include "in_game.h"
|
||||||
@@ -17,8 +16,6 @@ typedef struct PLAYER {
|
|||||||
unsigned short y;
|
unsigned short y;
|
||||||
} player_t;
|
} player_t;
|
||||||
|
|
||||||
static const int I_SIZE = 513;
|
|
||||||
static int ** imap;
|
|
||||||
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,87 +31,46 @@ 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 drawBar(int, int);
|
||||||
|
|
||||||
void initInGameState( gs_t * gs) {
|
void initInGameState( gs_t * gs) {
|
||||||
int n, i, j;
|
int i, j;
|
||||||
float ** fmap;
|
|
||||||
|
|
||||||
gs->name = IN_GAME;
|
gs->name = IN_GAME;
|
||||||
gs->input = &input;
|
gs->input = &input;
|
||||||
gs->update = &update;
|
gs->update = &update;
|
||||||
gs->render = &render;
|
gs->render = &render;
|
||||||
|
|
||||||
n = I_SIZE;
|
map = ( map_cell_t ** ) malloc ( sizeof ( map_cell_t * ) * MAX_MAP_SIZE);
|
||||||
|
for ( i = 0; i < MAX_MAP_SIZE; ++i ) {
|
||||||
srand(time(NULL));
|
map[ i ] = ( map_cell_t * ) calloc ( MAX_MAP_SIZE , sizeof ( map_cell_t ) );
|
||||||
|
|
||||||
fmap = ( float ** ) malloc ( sizeof ( float * ) * n);
|
|
||||||
for ( i = 0; i < n; ++i ) {
|
|
||||||
fmap[ i ] = ( float * ) calloc ( n, sizeof ( float ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
imap = ( int ** ) malloc ( sizeof ( int * ) * n);
|
wmap = ( bool ** ) malloc ( sizeof ( bool * ) * MAX_MAP_SIZE);
|
||||||
for ( i = 0; i < n; ++i ) {
|
for ( i = 0; i < MAX_MAP_SIZE; ++i ) {
|
||||||
imap[ i ] = ( int * ) calloc ( n, sizeof ( int ) );
|
wmap[ i ] = ( bool * ) calloc ( MAX_MAP_SIZE, sizeof ( bool ) );
|
||||||
}
|
for(j = 0; j < MAX_MAP_SIZE; ++j){
|
||||||
|
|
||||||
wmap = ( bool ** ) malloc ( sizeof ( bool * ) * n);
|
|
||||||
for ( i = 0; i < n; ++i ) {
|
|
||||||
wmap[ i ] = ( bool * ) calloc ( n, sizeof ( bool ) );
|
|
||||||
for(j = 0; j < n; ++j){
|
|
||||||
wmap[i][j] = rand() % 2;
|
wmap[i][j] = rand() % 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ds ( &fmap, n );
|
|
||||||
island ( &imap, n );
|
|
||||||
normInt ( &imap, n );
|
|
||||||
norm ( &fmap, n );
|
|
||||||
mult ( &fmap, &imap, n );
|
|
||||||
smooth( &imap, n );
|
|
||||||
normInt ( &imap, n );
|
|
||||||
|
|
||||||
for ( i = 0; i < n; ++i ) {
|
|
||||||
free(fmap[ i ]);
|
|
||||||
}
|
|
||||||
free(fmap);
|
|
||||||
|
|
||||||
setPlayerStart();
|
|
||||||
uK = dK = lK = rK = FALSE;
|
|
||||||
|
|
||||||
/*map = ( map_cell_t ** ) malloc ( sizeof ( map_cell_t * ) * 32);
|
|
||||||
for ( i = 0; i < 32; ++i ) {
|
|
||||||
map[ i ] = ( map_cell_t * ) calloc ( 32 , sizeof ( map_cell_t ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
initObjects();
|
initObjects();
|
||||||
|
|
||||||
errcode_t rc = readMapData("map_file.map", &map, &mW, &mH);
|
errcode_t rc = readMapData("map_file.map", &map, &mW, &mH);
|
||||||
|
if(rc != NO_ERROR){
|
||||||
fprintf(stderr, "\t%s: readMapData() returned %d\n", __FILE__, rc);
|
fprintf(stderr, "\t%s: readMapData() returned %d\n", __FILE__, rc);
|
||||||
fprintf(stderr, "\t%s: Map size is (%d, %d).\n", __FILE__, mW, mH);
|
exit(rc);
|
||||||
|
}
|
||||||
|
|
||||||
game_obj_t * objsP = objs;
|
game_obj_t * objsP = objs;
|
||||||
rc = readMapObjects("map_file.map", &objsP, &nO);
|
rc = readMapObjects("map_file.map", &objsP, &nO);
|
||||||
fprintf(stderr, "\t%s: readMapObjects() returned %d\n", __FILE__, rc);
|
if(rc != NO_ERROR){
|
||||||
fprintf(stderr, "\t%s: Number of objects is %d.\n", __FILE__, nO);
|
fprintf(stderr, "\t%s: readMapObjects() returned %d\n", __FILE__, rc);
|
||||||
|
exit(rc);
|
||||||
for(i = 0; i < nO; i++){
|
|
||||||
fprintf(stderr, "\t%s: Object %d\n", __FILE__, i);
|
|
||||||
fprintf(stderr, "\t\t Type %d\n", (int)objs[i].type);
|
|
||||||
fprintf(stderr, "\t\t x: %d -- y: %d -- eX: %d -- eY: %d -- sX: %d -- sY: %d\n", objs[i].x, objs[i].x, objs[i].eX, objs[i].eY, objs[i].sX, objs[i].sY);
|
|
||||||
fprintf(stderr, "\t\t iD: %d -- dId %d\n", objs[i].id, objs[i].dId);
|
|
||||||
fprintf(stderr, "\t\t name: %s\n", objs[i].name);
|
|
||||||
fprintf(stderr, "\t\t target: %s\n", objs[i].target);
|
|
||||||
fprintf(stderr, "\t\t dialog: %s\n", objs[i].dialog);
|
|
||||||
fprintf(stderr, "\t\t unlocked: %d\n", objs[i].unlocked);
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( i = 0; i < 32; ++i ) {
|
setPlayerStart();
|
||||||
free(map[ i ]);
|
|
||||||
}
|
|
||||||
free(map);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void input(){
|
void input(){
|
||||||
@@ -132,23 +88,32 @@ void input(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
gsname_t update(){
|
gsname_t update(){
|
||||||
|
int iX, iY;
|
||||||
|
|
||||||
|
iX = player.x;
|
||||||
|
iY = player.y;
|
||||||
|
|
||||||
if(uK){
|
if(uK){
|
||||||
if(terrainType( imap[player.x][player.y - 1] ) != DEEP_WATER && terrainType( imap[player.x][player.y - 1] ) != MOUNTAIN) player.y -= 1;
|
iY = iY - 1 < 0 ? mH - 1 : iY - 1;
|
||||||
|
if((map[iY][iX].f > WINDOW_WALL && map[iY][iX].f <= WATER) || map[iY][iX].f == SECRET_WALL) player.y = iY;
|
||||||
uK = FALSE;
|
uK = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dK){
|
if(dK){
|
||||||
if(terrainType( imap[player.x][player.y + 1]) != DEEP_WATER && terrainType( imap[player.x][player.y + 1]) != MOUNTAIN ) player.y += 1;
|
iY = (iY + 1) % mH;
|
||||||
|
if((map[iY][iX].f > WINDOW_WALL && map[iY][iX].f <= WATER) || map[iY][iX].f == SECRET_WALL) player.y = iY;
|
||||||
dK = FALSE;
|
dK = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lK){
|
if(lK){
|
||||||
if(terrainType( imap[player.x - 1][player.y]) != DEEP_WATER && terrainType( imap[player.x - 1][player.y]) != MOUNTAIN) player.x -= 1;
|
iX = iX - 1 < 0 ? mW - 1 : iX - 1;
|
||||||
|
if((map[iY][iX].f > WINDOW_WALL && map[iY][iX].f <= WATER) || map[iY][iX].f == SECRET_WALL) player.x = iX;
|
||||||
lK = FALSE;
|
lK = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rK){
|
if(rK){
|
||||||
if(terrainType( imap[player.x + 1][player.y]) != DEEP_WATER && terrainType( imap[player.x + 1][player.y]) != MOUNTAIN) player.x += 1;
|
iX = (iX + 1) % mW;
|
||||||
|
if((map[iY][iX].f > WINDOW_WALL && map[iY][iX].f <= WATER) || map[iY][iX].f == SECRET_WALL) player.x = iX;
|
||||||
rK = FALSE;
|
rK = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,47 +144,57 @@ void render(int w, int h){
|
|||||||
di = i - 27 + player.x - ioff;
|
di = i - 27 + player.x - ioff;
|
||||||
dj = j - 1 + player.y - joff;
|
dj = j - 1 + player.y - joff;
|
||||||
|
|
||||||
if( di < 0 || di >= I_SIZE){
|
if( di < 0 || di >= mW || dj < 0 || dj >= mH ){
|
||||||
printw(" ");
|
printw(" ");
|
||||||
}else{
|
}else{
|
||||||
switch(terrainType( imap[di][dj] )){
|
switch(map[dj][di].f){
|
||||||
case DEEP_WATER:
|
case WATER:
|
||||||
attron(COLOR_PAIR(DW_COLOR));
|
attron(COLOR_PAIR(DW_COLOR));
|
||||||
if(w_mov)
|
if(w_mov)
|
||||||
wmap[di][dj] = !wmap[di][dj];
|
wmap[dj][di] = !wmap[dj][di];
|
||||||
if(wmap[di][dj])
|
if(wmap[dj][di])
|
||||||
printw("\u2248");
|
printw("\u2248");
|
||||||
else
|
else
|
||||||
printw("~");
|
printw("~");
|
||||||
break;
|
break;
|
||||||
case SHALLOW_WATER:
|
|
||||||
attron(COLOR_PAIR(SW_COLOR));
|
case VOID:
|
||||||
if(w_mov)
|
attron(COLOR_PAIR(MN_COLOR));
|
||||||
wmap[di][dj] = !wmap[di][dj];
|
printw(" ");
|
||||||
if(wmap[di][dj])
|
|
||||||
printw("\u2248");
|
|
||||||
else
|
|
||||||
printw("~");
|
|
||||||
break;
|
break;
|
||||||
case SAND:
|
|
||||||
|
case EMPTY_FLOOR:
|
||||||
|
attron(COLOR_PAIR(MN_COLOR));
|
||||||
|
printw(" ");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RUG:
|
||||||
attron(COLOR_PAIR(SN_COLOR));
|
attron(COLOR_PAIR(SN_COLOR));
|
||||||
printw(".");
|
printw("\u2592");
|
||||||
break;
|
break;
|
||||||
case GRASS:
|
|
||||||
attron(COLOR_PAIR(GR_COLOR));
|
case WINDOW_WALL:
|
||||||
printw("n");
|
attron(COLOR_PAIR(SW_COLOR));
|
||||||
|
printw("\u2591");
|
||||||
break;
|
break;
|
||||||
case FOREST:
|
|
||||||
attron(COLOR_PAIR(FR_COLOR));
|
case CLEAR_WALL:
|
||||||
printw("\u2660");
|
attron(COLOR_PAIR(SW_COLOR));
|
||||||
|
printw("\u2588");
|
||||||
break;
|
break;
|
||||||
case HILL:
|
|
||||||
attron(COLOR_PAIR(HL_COLOR));
|
case SECRET_WALL:
|
||||||
printw("\u2302");
|
case SOLID_WALL:
|
||||||
break;
|
|
||||||
case MOUNTAIN:
|
|
||||||
attron(COLOR_PAIR(MN_COLOR));
|
attron(COLOR_PAIR(MN_COLOR));
|
||||||
printw("\u25B2");
|
printw("\u2588");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NEON_WALL:
|
||||||
|
drawNeon(dj, di);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BAR:
|
||||||
|
drawBar(dj, di);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -234,6 +209,128 @@ void render(int w, int h){
|
|||||||
drawGui(w, h);
|
drawGui(w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawNeon(int i, int j){
|
||||||
|
bool n, s, e, w;
|
||||||
|
|
||||||
|
attron(COLOR_PAIR(FR_COLOR));
|
||||||
|
|
||||||
|
n = map[i ][j - 1 < 0 ? mH - 1 : j - 1].f == NEON_WALL;
|
||||||
|
s = map[i ][(j + 1) % mH ].f == NEON_WALL;
|
||||||
|
e = map[i - 1 < 0 ? mW - 1 : i - 1][j ].f == NEON_WALL;
|
||||||
|
w = map[(i + 1) % mW ][j ].f == NEON_WALL;
|
||||||
|
|
||||||
|
if((n && s && e) && (!w)){
|
||||||
|
printw("\u2560");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((n || s) && (!e && !w)){
|
||||||
|
printw("\u2550");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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)){
|
||||||
|
printw("\u2560");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if((n || s) && (!e && !w)){
|
||||||
|
printw("\u2550");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 drawGui(int w, int h){
|
void drawGui(int w, int h){
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
@@ -283,19 +380,15 @@ void drawGui(int w, int h){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setPlayerStart(){
|
void setPlayerStart(){
|
||||||
int x, y;
|
int i;
|
||||||
bool posFound = false;
|
|
||||||
|
|
||||||
while(!posFound){
|
for(i = 0; i < nO; i++){
|
||||||
x = (I_SIZE / 4) + (rand() % (I_SIZE / 2));
|
if(objs[i].type == PLAYER_START){
|
||||||
y = (I_SIZE / 4) + (rand() % (I_SIZE / 2));
|
player.y = objs[i].sX;
|
||||||
|
player.x = objs[i].sY;
|
||||||
if(terrainType(imap[x][y]) == GRASS){
|
break;
|
||||||
player.x = x;
|
}
|
||||||
player.y = y;
|
}
|
||||||
posFound = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void initObjects(){
|
void initObjects(){
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ void set_colors(void){
|
|||||||
init_pair(SW_COLOR, COLOR_CYAN, COLOR_BLACK);
|
init_pair(SW_COLOR, COLOR_CYAN, COLOR_BLACK);
|
||||||
init_pair(SN_COLOR, COLOR_YELLOW, COLOR_BLACK);
|
init_pair(SN_COLOR, COLOR_YELLOW, COLOR_BLACK);
|
||||||
init_pair(GR_COLOR, COLOR_GREEN, COLOR_BLACK);
|
init_pair(GR_COLOR, COLOR_GREEN, COLOR_BLACK);
|
||||||
init_pair(FR_COLOR, COLOR_GREEN, COLOR_BLACK);
|
init_pair(FR_COLOR, COLOR_RED, COLOR_BLACK);
|
||||||
init_pair(HL_COLOR, COLOR_WHITE, COLOR_BLACK);
|
init_pair(HL_COLOR, COLOR_WHITE, COLOR_BLACK);
|
||||||
init_pair(MN_COLOR, COLOR_WHITE, COLOR_BLACK);
|
init_pair(MN_COLOR, COLOR_WHITE, COLOR_BLACK);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user