Skip to content
Snippets Groups Projects
Commit f4ed01dd authored by belkhiritaha's avatar belkhiritaha
Browse files

nouvelle animation fire et markov qui marche

parent d54e2e6c
Branches
No related tags found
No related merge requests found
1 0 0 0 0 90 10 0 0 0
0 1 0 0 0 0 80 20 0 0
0 0 1 0 0 0 10 80 10 0
0 0 0 1 0 0 0 10 50 40
0 0 0 0 1 0 0 0 50 50
\ No newline at end of file \ No newline at end of file
...@@ -170,13 +170,13 @@ void nextFire(listchainfire_t listFire){ ...@@ -170,13 +170,13 @@ void nextFire(listchainfire_t listFire){
state=(listTemporary->fire).state; state=(listTemporary->fire).state;
probability= rand()%101; probability= rand()%101;
pDead=markov[state][DEAD]*100; pDead=markov[state][DEAD];
pSparkle=(markov[state][SPARKLE]+markov[state][DEAD])*100; 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]+ 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;} if ((0<=probability)&&(probability<pDead)){(listTemporary->fire).state=DEAD;}
......
...@@ -174,18 +174,48 @@ void drawBackgroundSides(){ ...@@ -174,18 +174,48 @@ void drawBackgroundSides(){
} }
void drawFire(){ void drawFire(){
int loop;
int step;
listchainfire_t cour = fireList; listchainfire_t cour = fireList;
SDL_Rect rect; SDL_Rect rect;
rect.h = CELLSIZE;
rect.w = CELLSIZE;
SDL_Rect srcRect; SDL_Rect srcRect;
srcRect.w = 24;
srcRect.h =32;
srcRect.x = srcRect.w * (SDL_GetTicks()/200 % 8);
srcRect.y= 0;
while (cour != NULL){ while (cour != NULL){
rect.h = CELLSIZE * (cour->fire).state; rect.x = (cour->fire).x * CELLSIZE + (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2;
rect.w = CELLSIZE * (cour->fire).state; rect.y = (cour->fire).y * CELLSIZE - rect.h/2;
rect.x = (cour->fire).x * CELLSIZE + (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2 - rect.w/2;
rect.y = (cour->fire).y * CELLSIZE; 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); SDL_RenderCopy(renderer, fireTexture, &srcRect, &rect);
cour = cour->next; cour = cour->next;
} }
...@@ -271,7 +301,7 @@ void mainLoop(){ ...@@ -271,7 +301,7 @@ void mainLoop(){
playButtonHoverSurface = IMG_Load("Res/play_button_hover.png"); playButtonHoverSurface = IMG_Load("Res/play_button_hover.png");
playButtonHoverTexture = SDL_CreateTextureFromSurface(renderer, playButtonHoverSurface); playButtonHoverTexture = SDL_CreateTextureFromSurface(renderer, playButtonHoverSurface);
fireSurface = IMG_Load("Res/fire.png"); fireSurface = IMG_Load("Res/fire_spritesheet.png");
fireTexture = SDL_CreateTextureFromSurface(renderer, fireSurface); fireTexture = SDL_CreateTextureFromSurface(renderer, fireSurface);
waterSurface = IMG_Load("Res/water.png"); waterSurface = IMG_Load("Res/water.png");
...@@ -325,6 +355,9 @@ void mainLoop(){ ...@@ -325,6 +355,9 @@ void mainLoop(){
drawMenu(); drawMenu();
break; break;
case GAME: case GAME:
if ((int)timer % 20 == 0){
nextFire(fireList);
}
drawGame(); drawGame();
break; break;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment