From f1a6eda4805dd150faff0afc5f1ff2554bdea26a Mon Sep 17 00:00:00 2001 From: Miguel Angel Astor Romero Date: Sun, 2 Mar 2014 16:35:14 -0430 Subject: [PATCH] Some testing here and there. --- src/in_game.c | 16 +++++++++++++--- src/main.c | 21 ++++++++++++--------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/in_game.c b/src/in_game.c index 95ec1be..0d3af11 100644 --- a/src/in_game.c +++ b/src/in_game.c @@ -41,11 +41,20 @@ void initInGameState( gs_t * gs) { smooth( &imap, n ); normInt ( &imap, n ); + for ( i = 0; i < n; ++i ) { + free(map[ i ]); + } free(map); } void input(){ + int key = 0; + key = getch(); + + if(key != ERR){ + fprintf(stderr, "\t%s: Caught keycode %d\n", __FILE__, key); + } } gsname_t update(){ @@ -62,11 +71,11 @@ void render(int w, int h){ switch(terrainType( imap[(i + (I_SIZE/4)) % I_SIZE][(j + (I_SIZE/4)) % I_SIZE] )){ case DEEP_WATER: attron(COLOR_PAIR(DW_COLOR)); - printw("~"); + printw("\u2248"); break; case SHALLOW_WATER: attron(COLOR_PAIR(SW_COLOR)); - printw("~"); + printw("\u2248"); break; case SAND: attron(COLOR_PAIR(SN_COLOR)); @@ -74,7 +83,7 @@ void render(int w, int h){ break; case GRASS: attron(COLOR_PAIR(GR_COLOR)); - printw("\u2591"); + printw("n"); break; case FOREST: attron(COLOR_PAIR(FR_COLOR)); @@ -89,6 +98,7 @@ void render(int w, int h){ printw("\u25B2"); break; } + //printw("\u2588"); } } } diff --git a/src/main.c b/src/main.c index 5ed2198..30bdfeb 100644 --- a/src/main.c +++ b/src/main.c @@ -27,10 +27,11 @@ void set_colors(void); void clear_screen(void); void on_resize(int); -static int w = 0, h = 0, resize = 0; +static int w = 0, h = 0; +static bool resize = FALSE; int main() { - int finished = 0; + bool finished = FALSE; #if defined(_WIN32) || defined(_WIN64) || defined(__MINGW32__) char * home_dir = getenv("APPDATA"); #elif defined(__linux__) || defined(__GNUC__) @@ -106,8 +107,6 @@ int main() { /* Start the game loop. */ then = clock(); do{ - clear_screen(); - /* Handle terminal resize. */ if(resize){ endwin(); @@ -117,14 +116,14 @@ int main() { fprintf(stderr, "\tSIGWINCH caught. (W: %d, H: %d)\n", w, h); - resize = 0; + resize = FALSE; signal(SIGWINCH, on_resize); } states[c_state].input(); c_state = states[c_state].update(); - if(c_state == -1) finished = 1; + if(c_state == -1) finished = TRUE; states[c_state].render(w, h); @@ -180,12 +179,11 @@ void manage_signal(int signal){ fprintf(stderr, "\tSIGTERM caught.\n"); exit(EXIT_FAILURE); break; - } } void on_resize(int signal){ - resize = 1; + resize = TRUE; } int start_ncurses(void){ @@ -219,6 +217,11 @@ int start_ncurses(void){ if(ret_code == ERR) return -1; + /* Set delay. */ + ret_code = nodelay(stdscr, TRUE); + if(ret_code == ERR) + return -1; + /* Initialize the screen size variables. */ getmaxyx(stdscr, h, w); @@ -246,7 +249,7 @@ void set_colors(void){ init_pair(SN_COLOR, COLOR_YELLOW, COLOR_BLACK); init_pair(GR_COLOR, COLOR_GREEN, COLOR_BLACK); init_pair(FR_COLOR, COLOR_GREEN, COLOR_BLACK); - init_pair(HL_COLOR, COLOR_RED, COLOR_BLACK); + init_pair(HL_COLOR, COLOR_WHITE, COLOR_BLACK); init_pair(MN_COLOR, COLOR_WHITE, COLOR_BLACK); } }else{