From 073407c752098f6cb4cb060c5f00c99c5ba49d45 Mon Sep 17 00:00:00 2001 From: Miguel Angel Astor Romero Date: Sun, 2 Mar 2014 18:56:56 -0430 Subject: [PATCH] Removed useless headers. Playing with the render. --- Makefile | 1 - src/game_state.c | 5 +++++ src/in_game.c | 44 +++++++++++++++++++++++++++++++++++++++++--- src/main.c | 7 +------ 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index a0ef6b4..ff64137 100644 --- a/Makefile +++ b/Makefile @@ -26,4 +26,3 @@ obj/in_game.o: src/in_game.c include/in_game.h include/game_state.h clean: $(RM) $(TARGET) $(OBJECTS) - diff --git a/src/game_state.c b/src/game_state.c index 088d0bd..b838173 100644 --- a/src/game_state.c +++ b/src/game_state.c @@ -1,3 +1,8 @@ +/** + * Copyright (c) 2014, Miguel Angel Astor Romero. All rights reserved. + * See the file LICENSE for more details. + */ + #include "game_state.h" #include "in_game.h" diff --git a/src/in_game.c b/src/in_game.c index 0d3af11..f303431 100644 --- a/src/in_game.c +++ b/src/in_game.c @@ -1,4 +1,10 @@ +/** + * Copyright (c) 2014, Miguel Angel Astor Romero. All rights reserved. + * See the file LICENSE for more details. + */ + #include +#include #include #include @@ -7,13 +13,16 @@ static const int I_SIZE = 257; static int ** imap; +static bool ** wmap; +static bool w_mov = FALSE; +static clock_t then; void input(); gsname_t update(); void render(int, int); void initInGameState( gs_t * gs) { - int n, i; + int n, i, j; float ** map; gs->name = IN_GAME; @@ -23,6 +32,8 @@ void initInGameState( gs_t * gs) { n = I_SIZE; + srand(time(NULL)); + map = ( float ** ) malloc ( sizeof ( float * ) * n); for ( i = 0; i < n; ++i ) { map[ i ] = ( float * ) calloc ( n, sizeof ( float ) ); @@ -33,6 +44,14 @@ void initInGameState( gs_t * gs) { imap[ i ] = ( int * ) calloc ( n, sizeof ( int ) ); } + 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; + } + } + ds ( &map, n ); island ( &imap, n ); normInt ( &imap, n ); @@ -62,8 +81,16 @@ gsname_t update(){ } void render(int w, int h){ + clock_t now, delta; int i, j; + now = clock(); + delta = now - then; + if((float)delta / (float)CLOCKS_PER_SEC >= 0.25f){ + then = now; + w_mov = TRUE; + } + for(i = 0; i < w; i++){ for(j = 0; j < h; j++){ move(j, i); @@ -71,11 +98,21 @@ 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("\u2248"); + if(w_mov) + wmap[(i + (I_SIZE/4)) % I_SIZE][(j + (I_SIZE/4)) % I_SIZE] = !wmap[(i + (I_SIZE/4)) % I_SIZE][(j + (I_SIZE/4)) % I_SIZE]; + if(wmap[(i + (I_SIZE/4)) % I_SIZE][(j + (I_SIZE/4)) % I_SIZE]) + printw("\u2248"); + else + printw("~"); break; case SHALLOW_WATER: attron(COLOR_PAIR(SW_COLOR)); - printw("\u2248"); + if(w_mov) + wmap[(i + (I_SIZE/4)) % I_SIZE][(j + (I_SIZE/4)) % I_SIZE] = !wmap[(i + (I_SIZE/4)) % I_SIZE][(j + (I_SIZE/4)) % I_SIZE]; + if(wmap[(i + (I_SIZE/4)) % I_SIZE][(j + (I_SIZE/4)) % I_SIZE]) + printw("\u2248"); + else + printw("~"); break; case SAND: attron(COLOR_PAIR(SN_COLOR)); @@ -101,4 +138,5 @@ void render(int w, int h){ //printw("\u2588"); } } + w_mov = FALSE; } diff --git a/src/main.c b/src/main.c index 30bdfeb..471ca50 100644 --- a/src/main.c +++ b/src/main.c @@ -6,16 +6,12 @@ #include #include #include -#include #include #include #include #include -#include #include -#include #include -#include #include "constants.h" #include "game_state.h" @@ -37,7 +33,7 @@ int main() { #elif defined(__linux__) || defined(__GNUC__) char * home_dir = getenv("HOME"); #else -#error "Unrecoginized compiler." +#error "Unrecognized system." #endif FILE * f; /* To avoid a warning. */ clock_t then, now, delta; @@ -83,7 +79,6 @@ int main() { fprintf(stderr, "\tdata_dir is: %s\n", data_dir); }else{ /* The directory already exits. */ - //init_scores(data_dir); } } }else{