#include "arenaEngine.h" #include #include #include "fileHandler.h" //#include "logHelper.h" /* * Arena generate functions */ #define BLOC_SIZE 32 // Taille d'un bloc (carré) en pixels #define NB_BLOCS_LARGEUR 20 #define NB_BLOCS_HAUTEUR 20 #define LARGEUR_FENETRE BLOC_SIZE * NB_BLOCS_LARGEUR #define HAUTEUR_FENETRE BLOC_SIZE * NB_BLOCS_HAUTEUR ARENA_H_TILE* genNewArena(int size_h, int size_w) { ARENA_H_TILE* arenaOrigin = NULL; ARENA_H_TILE* TmpCursor_h = NULL; ARENA_W_TILE* TmpCursor_w = NULL; int i,j; FILE* fichier = NULL; char ligneFichier[NB_BLOCS_LARGEUR * NB_BLOCS_HAUTEUR + 1] = {0}; //int i = 0, j = 0; printf("Chargement du fichier\n"); fichier = fopen("level2-20x20.lvl", "r"); if (fichier == NULL) return 0; fgets(ligneFichier, size_w * size_h + 1, fichier); for(i=0;itype_id = 0; //printf("herbe\n"); break; case '1': TmpCursor_w->type_id = 1; // printf("caillou\n"); break; case '2': TmpCursor_w->type_id = 2; //printf("arbre\n"); break; } if (j!=0) TmpCursor_w = TmpCursor_w->nextColumn; } } return arenaOrigin; } ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile) { ARENA_H_TILE* tile_h = NULL; if (prevHTile == NULL) { tile_h = calloc(1,sizeof(ARENA_H_TILE)); //Using calloc because of resetting all memory allocated to 0 tile_h->type_id = 0; //tile_h->playerOnTile = NULL; tile_h->nextRow = NULL; tile_h->nextColumn = NULL; } else if (prevHTile != NULL) { tile_h = calloc(1,sizeof(ARENA_H_TILE)); prevHTile->nextRow = tile_h; tile_h->type_id = 0; //tile_h->playerOnTile = NULL; tile_h->nextRow = NULL; tile_h->nextColumn = NULL; } return tile_h; } ARENA_W_TILE* createWTile(ARENA_H_TILE* prevHTile, ARENA_W_TILE* prevWTile) { ARENA_W_TILE* tile_w = NULL; if (prevHTile != NULL && prevWTile == NULL) { tile_w = calloc(1,sizeof(ARENA_W_TILE)); prevHTile->nextColumn = tile_w; tile_w->type_id = 0; //tile_w->playerOnTile = NULL; tile_w->nextColumn = NULL; return tile_w; } else if (prevHTile == NULL && prevWTile != NULL) { tile_w = calloc(1,sizeof(ARENA_W_TILE)); prevWTile->nextColumn = tile_w; tile_w->type_id = 0; //tile_w->playerOnTile = NULL; tile_w->nextColumn = NULL; } return NULL; } /* ARENA_H_TILE* genNewArena(int size_h, int size_w) { ARENA_H_TILE* arenaOrigin = NULL; ARENA_H_TILE* TmpCursor_h = NULL; ARENA_W_TILE* TmpCursor_w = NULL; int i,j; for(i=0;inextColumn; } } return arenaOrigin; } */ /* * Arena delete functions */ void deleteWTile(ARENA_W_TILE* WTile) { if (WTile->nextColumn != NULL) { deleteWTile(WTile->nextColumn); } free(WTile); } void deleteHTile(ARENA_H_TILE* HTile) { if (HTile->nextRow != NULL) { deleteHTile(HTile->nextRow); } deleteWTile(HTile->nextColumn); free(HTile); } void deleteArena(ARENA_H_TILE* arena) { deleteHTile(arena); } /* * Arena status functions */ int getTileTypeID(ARENA_H_TILE* arena, int coord_x, int coord_y) { int type_id = -1; int i; if (coord_y == 0) { ARENA_H_TILE* tile_h = NULL; tile_h = arena; if (coord_x != 0) { for (i=0;inextRow; } } type_id = tile_h->type_id; } else { ARENA_W_TILE* tile_w = NULL; ARENA_H_TILE* tile_h = NULL; tile_h = arena; if (coord_x != 0) { for (i=0;inextRow; } } tile_w = tile_h->nextColumn; if (coord_y != 0) { for (i=0;inextColumn; } } type_id = tile_w->type_id; } return type_id; }