Removed useless headers. Playing with the render.

This commit is contained in:
2014-03-02 18:56:56 -04:30
parent f1a6eda480
commit 073407c752
4 changed files with 47 additions and 10 deletions

View File

@@ -26,4 +26,3 @@ obj/in_game.o: src/in_game.c include/in_game.h include/game_state.h
clean: clean:
$(RM) $(TARGET) $(OBJECTS) $(RM) $(TARGET) $(OBJECTS)

View File

@@ -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 "game_state.h"
#include "in_game.h" #include "in_game.h"

View File

@@ -1,4 +1,10 @@
/**
* Copyright (c) 2014, Miguel Angel Astor Romero. All rights reserved.
* See the file LICENSE for more details.
*/
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include <ncursesw/ncurses.h> #include <ncursesw/ncurses.h>
#include <island.h> #include <island.h>
@@ -7,13 +13,16 @@
static const int I_SIZE = 257; static const int I_SIZE = 257;
static int ** imap; static int ** imap;
static bool ** wmap;
static bool w_mov = FALSE;
static clock_t then;
void input(); void input();
gsname_t update(); gsname_t update();
void render(int, int); void render(int, int);
void initInGameState( gs_t * gs) { void initInGameState( gs_t * gs) {
int n, i; int n, i, j;
float ** map; float ** map;
gs->name = IN_GAME; gs->name = IN_GAME;
@@ -23,6 +32,8 @@ void initInGameState( gs_t * gs) {
n = I_SIZE; n = I_SIZE;
srand(time(NULL));
map = ( float ** ) malloc ( sizeof ( float * ) * n); map = ( float ** ) malloc ( sizeof ( float * ) * n);
for ( i = 0; i < n; ++i ) { for ( i = 0; i < n; ++i ) {
map[ i ] = ( float * ) calloc ( n, sizeof ( float ) ); map[ i ] = ( float * ) calloc ( n, sizeof ( float ) );
@@ -33,6 +44,14 @@ void initInGameState( gs_t * gs) {
imap[ i ] = ( int * ) calloc ( n, sizeof ( int ) ); 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 ); ds ( &map, n );
island ( &imap, n ); island ( &imap, n );
normInt ( &imap, n ); normInt ( &imap, n );
@@ -62,8 +81,16 @@ gsname_t update(){
} }
void render(int w, int h){ void render(int w, int h){
clock_t now, delta;
int i, j; 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(i = 0; i < w; i++){
for(j = 0; j < h; j++){ for(j = 0; j < h; j++){
move(j, i); 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] )){ 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));
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"); printw("\u2248");
else
printw("~");
break; break;
case SHALLOW_WATER: case SHALLOW_WATER:
attron(COLOR_PAIR(SW_COLOR)); attron(COLOR_PAIR(SW_COLOR));
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"); printw("\u2248");
else
printw("~");
break; break;
case SAND: case SAND:
attron(COLOR_PAIR(SN_COLOR)); attron(COLOR_PAIR(SN_COLOR));
@@ -101,4 +138,5 @@ void render(int w, int h){
//printw("\u2588"); //printw("\u2588");
} }
} }
w_mov = FALSE;
} }

View File

@@ -6,16 +6,12 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <ncursesw/ncurses.h> #include <ncursesw/ncurses.h>
#include <termios.h>
#include <locale.h> #include <locale.h>
#include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/ioctl.h>
#include "constants.h" #include "constants.h"
#include "game_state.h" #include "game_state.h"
@@ -37,7 +33,7 @@ int main() {
#elif defined(__linux__) || defined(__GNUC__) #elif defined(__linux__) || defined(__GNUC__)
char * home_dir = getenv("HOME"); char * home_dir = getenv("HOME");
#else #else
#error "Unrecoginized compiler." #error "Unrecognized system."
#endif #endif
FILE * f; /* To avoid a warning. */ FILE * f; /* To avoid a warning. */
clock_t then, now, delta; clock_t then, now, delta;
@@ -83,7 +79,6 @@ int main() {
fprintf(stderr, "\tdata_dir is: %s\n", data_dir); fprintf(stderr, "\tdata_dir is: %s\n", data_dir);
}else{ }else{
/* The directory already exits. */ /* The directory already exits. */
//init_scores(data_dir);
} }
} }
}else{ }else{