From f4ed01ddb9e07d2dca65839985b1952da59b0c3b Mon Sep 17 00:00:00 2001
From: belkhiritaha <belkhiri.taha53@gmail.com>
Date: Wed, 22 Jun 2022 23:23:26 +0200
Subject: [PATCH] nouvelle animation fire et markov qui marche

---
 travail_de_groupe/chef_oeuvre/markov.txt   | 10 ++---
 travail_de_groupe/chef_oeuvre/src/fire.c   |  8 ++--
 travail_de_groupe/chef_oeuvre/src/render.c | 51 ++++++++++++++++++----
 3 files changed, 51 insertions(+), 18 deletions(-)

diff --git a/travail_de_groupe/chef_oeuvre/markov.txt b/travail_de_groupe/chef_oeuvre/markov.txt
index c4cf894..5a5f989 100644
--- a/travail_de_groupe/chef_oeuvre/markov.txt
+++ b/travail_de_groupe/chef_oeuvre/markov.txt
@@ -1,5 +1,5 @@
-1 0 0 0 0
-0 1 0 0 0
-0 0 1 0 0
-0 0 0 1 0
-0 0 0 0 1
\ No newline at end of file
+90 10 0 0 0
+0 80 20 0 0
+0 10 80 10 0
+0 0 10 50 40
+0 0 0 50 50
\ No newline at end of file
diff --git a/travail_de_groupe/chef_oeuvre/src/fire.c b/travail_de_groupe/chef_oeuvre/src/fire.c
index 9794417..61289d5 100644
--- a/travail_de_groupe/chef_oeuvre/src/fire.c
+++ b/travail_de_groupe/chef_oeuvre/src/fire.c
@@ -170,13 +170,13 @@ void nextFire(listchainfire_t listFire){
         state=(listTemporary->fire).state;
         probability= rand()%101;
 
-        pDead=markov[state][DEAD]*100;
-        pSparkle=(markov[state][SPARKLE]+markov[state][DEAD])*100;
+        pDead=markov[state][DEAD];
+        pSparkle=(markov[state][SPARKLE]+markov[state][DEAD]);
 
-        pMedium=(markov[state][SPARKLE]+markov[state][DEAD]+markov[state][MEDIUM])*100;
+        pMedium=(markov[state][SPARKLE]+markov[state][DEAD]+markov[state][MEDIUM]);
 
         pStrong=(markov[state][SPARKLE]+markov[state][DEAD]+
-                    markov[state][MEDIUM]+markov[state][STRONG])*100;
+                    markov[state][MEDIUM]+markov[state][STRONG]);
 
 
         if ((0<=probability)&&(probability<pDead)){(listTemporary->fire).state=DEAD;}
diff --git a/travail_de_groupe/chef_oeuvre/src/render.c b/travail_de_groupe/chef_oeuvre/src/render.c
index 8b2c1b9..bd59f16 100644
--- a/travail_de_groupe/chef_oeuvre/src/render.c
+++ b/travail_de_groupe/chef_oeuvre/src/render.c
@@ -174,18 +174,48 @@ void drawBackgroundSides(){
 }
 
 void drawFire(){
+    int loop;
+    int step;
     listchainfire_t cour = fireList;
     SDL_Rect rect;
+    rect.h = CELLSIZE;
+    rect.w = CELLSIZE;
     SDL_Rect srcRect;
-    srcRect.w = 24;
-    srcRect.h =32;
-    srcRect.x = srcRect.w * (SDL_GetTicks()/200 % 8);
-    srcRect.y= 0;
     while (cour != NULL){
-        rect.h = CELLSIZE * (cour->fire).state;
-        rect.w = CELLSIZE * (cour->fire).state;
-        rect.x = (cour->fire).x * CELLSIZE + (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2 - rect.w/2;
-        rect.y = (cour->fire).y * CELLSIZE;
+        rect.x = (cour->fire).x * CELLSIZE + (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2;
+        rect.y = (cour->fire).y * CELLSIZE - rect.h/2;
+
+        srcRect.w = 15;
+        srcRect.h =24;
+        srcRect.x = step + srcRect.w * (SDL_GetTicks()/200 % loop);
+        srcRect.y= 0;
+
+        switch ((cour->fire).state)
+        {
+            case SPARKLE:
+                step = 0;
+                loop = 2;
+                break;
+
+            case MEDIUM:
+                step = 2 * srcRect.w;
+                loop = 4;
+                break;
+
+            case STRONG:
+                step = 6 * srcRect.w;
+                loop = 6;
+                break;
+
+            case SPREAD:
+                step = 6 * srcRect.w;
+                loop = 6;
+                break;
+            
+            default:
+                break;
+        }
+
         SDL_RenderCopy(renderer, fireTexture, &srcRect, &rect);
         cour = cour->next;
     }
@@ -271,7 +301,7 @@ void mainLoop(){
     playButtonHoverSurface = IMG_Load("Res/play_button_hover.png");
     playButtonHoverTexture = SDL_CreateTextureFromSurface(renderer, playButtonHoverSurface);
 
-    fireSurface = IMG_Load("Res/fire.png");
+    fireSurface = IMG_Load("Res/fire_spritesheet.png");
     fireTexture = SDL_CreateTextureFromSurface(renderer, fireSurface);
 
     waterSurface = IMG_Load("Res/water.png");
@@ -325,6 +355,9 @@ void mainLoop(){
                     drawMenu();
                     break;
                 case GAME:
+                    if ((int)timer % 20 == 0){
+                        nextFire(fireList);
+                    }
                     drawGame();
                     break;
             }
-- 
GitLab