From 5d6ac0d20e377451035a1158b7a6a19a3dcdb5bf Mon Sep 17 00:00:00 2001 From: Taha Belkhiri <belkhiri.taha53@gmail.com> Date: Wed, 22 Jun 2022 15:05:57 +0200 Subject: [PATCH] rendering fires as trees --- travail_de_groupe/chef_oeuvre/src/fire.c | 5 +++-- travail_de_groupe/chef_oeuvre/src/fire.h | 2 ++ travail_de_groupe/chef_oeuvre/src/main.c | 1 + travail_de_groupe/chef_oeuvre/src/main.h | 1 + travail_de_groupe/chef_oeuvre/src/render.c | 14 ++++++++++++++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/travail_de_groupe/chef_oeuvre/src/fire.c b/travail_de_groupe/chef_oeuvre/src/fire.c index 3a8f4b4..ae254e1 100644 --- a/travail_de_groupe/chef_oeuvre/src/fire.c +++ b/travail_de_groupe/chef_oeuvre/src/fire.c @@ -1,6 +1,7 @@ #include "fire.h" #include "map.h" +listchainfire_t fireList; int markov[SIZEMARKOV][SIZEMARKOV]; listchainfire_t initFire (void) @@ -52,7 +53,7 @@ listchainfire_t startFire(listchainfire_t listFire,int numberFire, int mapSize){ srand(time(NULL)); xFire= rand()%mapSize; srand(time(NULL)); - xFire= rand()%mapSize; + yFire= rand()%mapSize; fire.x= xFire; fire.y= yFire; @@ -70,7 +71,7 @@ booleen_t searchFire(listchainfire_t listFire, int x ,int y) { booleen_t result = false; - while((listFire!=NULL)||!(result)) + while((listFire!=NULL)&&!(result)) { if(((listFire->fire).x==x)&&((listFire->fire).y==y)) // si on trouve la semaine voulue { diff --git a/travail_de_groupe/chef_oeuvre/src/fire.h b/travail_de_groupe/chef_oeuvre/src/fire.h index ce6b5a8..851423f 100644 --- a/travail_de_groupe/chef_oeuvre/src/fire.h +++ b/travail_de_groupe/chef_oeuvre/src/fire.h @@ -27,6 +27,8 @@ typedef struct chain { struct chain *next; }chainfire_t,*listchainfire_t; +extern listchainfire_t fireList; + listchainfire_t initFire(void); booleen_t emptyListFire(listchainfire_t); listchainfire_t insertAheadFire(fire_t, listchainfire_t); diff --git a/travail_de_groupe/chef_oeuvre/src/main.c b/travail_de_groupe/chef_oeuvre/src/main.c index d614bdd..5b23e53 100644 --- a/travail_de_groupe/chef_oeuvre/src/main.c +++ b/travail_de_groupe/chef_oeuvre/src/main.c @@ -8,5 +8,6 @@ int main(){ running = 1; gameState = MENU; readMapFromFile("map.txt"); + fireList = startFire(fireList,10,MAPSIZE); mainLoop(); } \ No newline at end of file diff --git a/travail_de_groupe/chef_oeuvre/src/main.h b/travail_de_groupe/chef_oeuvre/src/main.h index 8c5c517..a898cd4 100644 --- a/travail_de_groupe/chef_oeuvre/src/main.h +++ b/travail_de_groupe/chef_oeuvre/src/main.h @@ -18,6 +18,7 @@ #include "gest_event.h" #include "map.h" #include "player.h" +#include "fire.h" #define MENU 0 diff --git a/travail_de_groupe/chef_oeuvre/src/render.c b/travail_de_groupe/chef_oeuvre/src/render.c index 21fafd8..f543c0e 100644 --- a/travail_de_groupe/chef_oeuvre/src/render.c +++ b/travail_de_groupe/chef_oeuvre/src/render.c @@ -141,11 +141,25 @@ void drawBackgroundSides(){ SDL_RenderCopy(renderer, backgroundSidesTexture, NULL, &rect); } +void drawFire(){ + listchainfire_t cour = fireList; + while (cour != NULL){ + SDL_Rect rect; + rect.h = CELLSIZE; + rect.w = CELLSIZE; + rect.x = (cour->fire).x + (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2; + rect.y = (cour->fire).y ; + SDL_RenderCopy(renderer, treeTexture, NULL, &rect); + cour = cour->next; + } +} + void drawGame(){ SDL_RenderClear(renderer); drawBackgroundSides(); drawMap(); drawPlayer(); + drawFire(); SDL_RenderPresent(renderer); } -- GitLab