From 0539ec2bb3e1603ffd5fa29b3095dc1c8cea18b2 Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Sun, 17 Jun 2018 13:11:04 +0200 Subject: [PATCH 1/2] createTile and genNewArena basic function --- arenaEngine.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++---- arenaEngine.h | 19 ++++++++---- menuGUI.c | 5 ---- 3 files changed, 92 insertions(+), 15 deletions(-) diff --git a/arenaEngine.c b/arenaEngine.c index ff5695b..dcf2d23 100644 --- a/arenaEngine.c +++ b/arenaEngine.c @@ -5,14 +5,87 @@ #include #include -int initResources(tilesList) { - resOpen(); +int initResources() { + //resOpen(); return 0; } -void genNewArena(int w, int h, ARENA_TILE* a[][]) { - a = malloc(sizeof(ARENA_TILE) * w * h); +ARENA_H_TILE* createHTile(ARENA_H_TILE* prevHTile) { + ARENA_H_TILE* tile_h = NULL; - for + 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->isGround = 1; + tile_h->canBeMined = 0; + tile_h->nextRow = NULL; + tile_h->nextColumn = NULL; + + return tile_h; + } else if (prevHTile != NULL) { + tile_h = calloc(1,sizeof(ARENA_H_TILE)); + prevHTile->nextRow = tile_h; + tile_h->type_id = 0; + tile_h->isGround = 1; + tile_h->canBeMined = 0; + tile_h->nextRow = NULL; + tile_h->nextColumn = NULL; + } + + return NULL; +} + +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->isGround = 1; + tile_w->canBeMined = 0; + 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->isGround = 1; + tile_w->canBeMined = 0; + tile_w->nextColumn = NULL; + } + + return NULL; +} + +ARENA_H_TILE* genNewArena(int w, int h) { + ARENA_H_TILE* arenaOrigin = NULL; + ARENA_H_TILE* TmpCursor_h = NULL; + ARENA_W_TILE* TmpCursor_w = NULL; + int i,j; + + for(i=0;inextColumn; + } + + if (i!=0) TmpCursor_h = TmpCursor_h->nextRow; + } + + return arenaOrigin; } diff --git a/arenaEngine.h b/arenaEngine.h index d7729f7..c9fe930 100644 --- a/arenaEngine.h +++ b/arenaEngine.h @@ -9,16 +9,25 @@ typedef struct items{ //texture? int isFlat; int minedId; - struct items; + struct items *nextItem; }ITEMS; */ -typedef struct a_tile{ +typedef struct arena_h_tile{ //Rows chained list int type_id; //texture? - int isFlat; + int isGround; int canBeMined; - //struct a_tile nextTile; -}ARENA_TILE; + struct arena_h_tile *nextRow; + struct arena_w_tile *nextColumn; +}ARENA_H_TILE; + +typedef struct arena_w_tile{ //Columns chained list + int type_id; + //texture? + int isGround; + int canBeMined; + struct arena_w_tile *nextColumn; +}ARENA_W_TILE; #endif diff --git a/menuGUI.c b/menuGUI.c index 0545de3..f7456a1 100644 --- a/menuGUI.c +++ b/menuGUI.c @@ -10,11 +10,6 @@ void initDisplayLib() { } int createMainWindows() { - if (SDL_Init(SDL_INIT_VIDEO) != 0) { - printf("Erreur chargement librairie SDL ! %s\n",SDL_GetError()); - exit(EXIT_FAILURE); - } - SDL_Window *main_test; main_test = SDL_CreateWindow("My test windows", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 140, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS); SDL_Delay(5000); From 6b713cd64bbf06a7564e99b42bec0e512424410e Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Sun, 17 Jun 2018 15:11:34 +0200 Subject: [PATCH 2/2] Deleted old files and fix call function --- IAEngine.c | 2 +- arenaEngine.c | 6 ++++-- gameMenu.c | 23 ----------------------- gameMenu.h | 6 ------ main.c | 2 ++ menuGUI.c | 8 +++++++- playerInterface.c | 7 ------- 7 files changed, 14 insertions(+), 40 deletions(-) delete mode 100644 gameMenu.c delete mode 100644 gameMenu.h diff --git a/IAEngine.c b/IAEngine.c index 1c74784..d26a2ca 100644 --- a/IAEngine.c +++ b/IAEngine.c @@ -39,7 +39,7 @@ void AttackPlayer( PLAYER *player1, PLAYER *player2); -int main(void) +int init(void) { PLAYER* List=NULL; PLAYER* Element=NULL; diff --git a/arenaEngine.c b/arenaEngine.c index dcf2d23..9f9acb2 100644 --- a/arenaEngine.c +++ b/arenaEngine.c @@ -2,8 +2,6 @@ #include #include #include "fileHandler.h" -#include -#include int initResources() { //resOpen(); @@ -89,3 +87,7 @@ ARENA_H_TILE* genNewArena(int w, int h) { return arenaOrigin; } + +int deleteArena(ARENA_H_TILE* genNewArena) { + +} diff --git a/gameMenu.c b/gameMenu.c deleted file mode 100644 index 05e051e..0000000 --- a/gameMenu.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "SDL2/SDL.h" - -void initDisplayLib() { - if (SDL_Init(SDL_INIT_VIDEO) != 0) { - printf("Erreur chargement librairie SDL ! %s\n",SDL_GetError()); - exit(EXIT_FAILURE); - } -} - -int createMainWindows() { - if (SDL_Init(SDL_INIT_VIDEO) != 0) { - printf("Erreur chargement librairie SDL ! %s\n",SDL_GetError()); - exit(EXIT_FAILURE); - } - - SDL_Window *main_test; - main_test = SDL_CreateWindow("My test windows", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 140, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS); - SDL_Delay(5000); - SDL_DestroyWindow(main_test); - - SDL_Quit(); - return EXIT_SUCCESS; -} diff --git a/gameMenu.h b/gameMenu.h deleted file mode 100644 index fe92f33..0000000 --- a/gameMenu.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef GAMEMENU_H_ -#define GAMEMENU_H_ - - - -#endif diff --git a/main.c b/main.c index e94628a..5755fb1 100644 --- a/main.c +++ b/main.c @@ -2,6 +2,8 @@ #include #include "logHelper.h" #include "SDL2/SDL.h" +#include "SDL2/SDL_thread.h" +#include "SDL2/SDL_mutex.h" #include "arenaEngine.h" #define A_WIDTH 100 //Real value is A_X + 1 diff --git a/menuGUI.c b/menuGUI.c index f7456a1..b433bec 100644 --- a/menuGUI.c +++ b/menuGUI.c @@ -9,7 +9,12 @@ void initDisplayLib() { } } -int createMainWindows() { +int createGameMenuWindows() { + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + printf("Erreur chargement librairie SDL ! %s\n",SDL_GetError()); + exit(EXIT_FAILURE); + } + SDL_Window *main_test; main_test = SDL_CreateWindow("My test windows", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 140, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS); SDL_Delay(5000); @@ -18,3 +23,4 @@ int createMainWindows() { SDL_Quit(); return EXIT_SUCCESS; } + diff --git a/playerInterface.c b/playerInterface.c index 1760300..b336573 100644 --- a/playerInterface.c +++ b/playerInterface.c @@ -4,13 +4,6 @@ #include "logHelper.h" #include "SDL2/SDL.h" -void initDisplayLib() { - if (SDL_Init(SDL_INIT_VIDEO) != 0) { - printf("Erreur chargement librairie SDL ! %s\n",SDL_GetError()); - exit(EXIT_FAILURE); - } -} - void displayScreen(int scr_id) { SDL_Window *main_test; main_test = SDL_CreateWindow("My test windows", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 140, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);