Some testing here and there.
This commit is contained in:
@@ -41,11 +41,20 @@ void initInGameState( gs_t * gs) {
|
|||||||
smooth( &imap, n );
|
smooth( &imap, n );
|
||||||
normInt ( &imap, n );
|
normInt ( &imap, n );
|
||||||
|
|
||||||
|
for ( i = 0; i < n; ++i ) {
|
||||||
|
free(map[ i ]);
|
||||||
|
}
|
||||||
free(map);
|
free(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void input(){
|
void input(){
|
||||||
|
int key = 0;
|
||||||
|
|
||||||
|
key = getch();
|
||||||
|
|
||||||
|
if(key != ERR){
|
||||||
|
fprintf(stderr, "\t%s: Caught keycode %d\n", __FILE__, key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gsname_t update(){
|
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] )){
|
switch(terrainType( imap[(i + (I_SIZE/4)) % I_SIZE][(j + (I_SIZE/4)) % I_SIZE] )){
|
||||||
case DEEP_WATER:
|
case DEEP_WATER:
|
||||||
attron(COLOR_PAIR(DW_COLOR));
|
attron(COLOR_PAIR(DW_COLOR));
|
||||||
printw("~");
|
printw("\u2248");
|
||||||
break;
|
break;
|
||||||
case SHALLOW_WATER:
|
case SHALLOW_WATER:
|
||||||
attron(COLOR_PAIR(SW_COLOR));
|
attron(COLOR_PAIR(SW_COLOR));
|
||||||
printw("~");
|
printw("\u2248");
|
||||||
break;
|
break;
|
||||||
case SAND:
|
case SAND:
|
||||||
attron(COLOR_PAIR(SN_COLOR));
|
attron(COLOR_PAIR(SN_COLOR));
|
||||||
@@ -74,7 +83,7 @@ void render(int w, int h){
|
|||||||
break;
|
break;
|
||||||
case GRASS:
|
case GRASS:
|
||||||
attron(COLOR_PAIR(GR_COLOR));
|
attron(COLOR_PAIR(GR_COLOR));
|
||||||
printw("\u2591");
|
printw("n");
|
||||||
break;
|
break;
|
||||||
case FOREST:
|
case FOREST:
|
||||||
attron(COLOR_PAIR(FR_COLOR));
|
attron(COLOR_PAIR(FR_COLOR));
|
||||||
@@ -89,6 +98,7 @@ void render(int w, int h){
|
|||||||
printw("\u25B2");
|
printw("\u25B2");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
//printw("\u2588");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/main.c
21
src/main.c
@@ -27,10 +27,11 @@ void set_colors(void);
|
|||||||
void clear_screen(void);
|
void clear_screen(void);
|
||||||
void on_resize(int);
|
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 main() {
|
||||||
int finished = 0;
|
bool finished = FALSE;
|
||||||
#if defined(_WIN32) || defined(_WIN64) || defined(__MINGW32__)
|
#if defined(_WIN32) || defined(_WIN64) || defined(__MINGW32__)
|
||||||
char * home_dir = getenv("APPDATA");
|
char * home_dir = getenv("APPDATA");
|
||||||
#elif defined(__linux__) || defined(__GNUC__)
|
#elif defined(__linux__) || defined(__GNUC__)
|
||||||
@@ -106,8 +107,6 @@ int main() {
|
|||||||
/* Start the game loop. */
|
/* Start the game loop. */
|
||||||
then = clock();
|
then = clock();
|
||||||
do{
|
do{
|
||||||
clear_screen();
|
|
||||||
|
|
||||||
/* Handle terminal resize. */
|
/* Handle terminal resize. */
|
||||||
if(resize){
|
if(resize){
|
||||||
endwin();
|
endwin();
|
||||||
@@ -117,14 +116,14 @@ int main() {
|
|||||||
|
|
||||||
fprintf(stderr, "\tSIGWINCH caught. (W: %d, H: %d)\n", w, h);
|
fprintf(stderr, "\tSIGWINCH caught. (W: %d, H: %d)\n", w, h);
|
||||||
|
|
||||||
resize = 0;
|
resize = FALSE;
|
||||||
signal(SIGWINCH, on_resize);
|
signal(SIGWINCH, on_resize);
|
||||||
}
|
}
|
||||||
|
|
||||||
states[c_state].input();
|
states[c_state].input();
|
||||||
c_state = states[c_state].update();
|
c_state = states[c_state].update();
|
||||||
|
|
||||||
if(c_state == -1) finished = 1;
|
if(c_state == -1) finished = TRUE;
|
||||||
|
|
||||||
states[c_state].render(w, h);
|
states[c_state].render(w, h);
|
||||||
|
|
||||||
@@ -180,12 +179,11 @@ void manage_signal(int signal){
|
|||||||
fprintf(stderr, "\tSIGTERM caught.\n");
|
fprintf(stderr, "\tSIGTERM caught.\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_resize(int signal){
|
void on_resize(int signal){
|
||||||
resize = 1;
|
resize = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int start_ncurses(void){
|
int start_ncurses(void){
|
||||||
@@ -219,6 +217,11 @@ int start_ncurses(void){
|
|||||||
if(ret_code == ERR)
|
if(ret_code == ERR)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
/* Set delay. */
|
||||||
|
ret_code = nodelay(stdscr, TRUE);
|
||||||
|
if(ret_code == ERR)
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* Initialize the screen size variables. */
|
/* Initialize the screen size variables. */
|
||||||
getmaxyx(stdscr, h, w);
|
getmaxyx(stdscr, h, w);
|
||||||
|
|
||||||
@@ -246,7 +249,7 @@ void set_colors(void){
|
|||||||
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_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);
|
init_pair(MN_COLOR, COLOR_WHITE, COLOR_BLACK);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
Reference in New Issue
Block a user