diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2014-10-26 18:20:28 +0000 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2014-10-26 18:20:54 +0000 |
commit | e816f16a5007798968f4c9003b3159a45485e88f (patch) | |
tree | 86be1ca571b383ba1d532fa655991d099903732a /magies.c | |
parent | f290b8cd7e40ed8688175fba312697f7da96a34e (diff) |
game: remove useless checks
it is safe to pass a null pointer to SDL_FreeSurface()
BTW: change the format of the files from dos to unix
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'magies.c')
-rw-r--r-- | magies.c | 510 |
1 files changed, 255 insertions, 255 deletions
@@ -1,255 +1,255 @@ -#include <stdlib.h>
-#include <stdio.h>
-#include <SDL/SDL.h>
-#include "structures.h"
-#include "constantes.h"
-#include "prototypes.h"
-
-int Fmagieelement (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis, int element,int *Vtour)
-{
- int max;
- int min;
- unsigned int continuer = 1;
- int degats;
- int selection = 0;
- int delay=1;
- unsigned int Bdegats=DEGATS;
- int clan=ENNEMI;
- SDL_Event event;
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
- while(ennemis[selection].etat==MORT)
- selection++;
- Fchangercurseurennemis (surfaces,positions,selection,ennemis);
- while (continuer)
- {
- SDL_Flip (surfaces->Pecran);
- SDL_WaitEvent (&event);
- switch (event.type)
- {
- case SDL_KEYDOWN:
- switch (event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- continuer = 0;
- if(clan==ENNEMI)
- {
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);
- }
- else
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);
- SDL_Flip (surfaces->Pecran);
- break;
- SELECTION_CIBLE()
- case SDLK_RETURN:
- continuer=0;
- max=Fcalculerdegats(persos,Vtourallie,&min,ennemis,selection,clan,TYPE_MAGIE);
- degats=(rand()%(max-min+1))+min;
- if(degats<0)
- degats=0;
- if(element!=NON_ELEMENTAIRE)
- {
- if (ennemis[selection].resistance[element]==ACTIVE)
- degats/=2;
- else if(ennemis[selection].sensibilite[element]==ACTIVE)
- degats*=2;
- else if(ennemis[selection].invulnerabilite[element]==ACTIVE)
- degats=0;
- else if(ennemis[selection].absorbtion[element]==ACTIVE)
- inverse(&Bdegats);
- }
- if(clan==ENNEMI)
- {
- if(Bdegats==DEGATS)
- ennemis[selection].pv-=degats;
- else
- ennemis[selection].pv+=degats;
- if(ennemis[selection].pv<=0)
- {
- ennemis[selection].pv=0;
- ennemis[selection].etat=MORT;
- positions->Vpositionmort.x=positions->Vpositionennemis[selection].x+surfaces->Tennemi[selection]->w/2-surfaces->Pmort->w/2;
- positions->Vpositionmort.y=positions->Vpositionennemis[selection].y+surfaces->Tennemi[selection]->h/2-surfaces->Pmort->h/2;
- SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort);
- }
- else if(ennemis[selection].pv>ennemis[selection].pvinitiaux)
- ennemis[selection].pv=ennemis[selection].pvinitiaux;
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);
- }
- else
- {
- if(Bdegats==DEGATS)
- persos[selection].pv-=degats;
- else
- persos[selection].pv+=degats;
- if(persos[selection].pv<=0)
- {
- persos[selection].pv=0;
- persos[selection].etat=MORT;
- positions->Vpositionmort.x=positions->Vpositionpersos[selection].x+surfaces->Tperso[selection]->w/2-surfaces->Pmort->w/2;
- positions->Vpositionmort.y=positions->Vpositionpersos[selection].y+surfaces->Tperso[selection]->h/2-surfaces->Pmort->h/2;
- SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort);
- }
- else if(persos[selection].pv>persos[selection].pvinitiaux)
- persos[selection].pv=persos[selection].pvinitiaux;
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);
- }
- if(Bdegats==DEGATS)
- Fafficherdegats (surfaces,positions,degats,clan,selection,persos);
- else
- Faffichersoins (surfaces,positions,degats,clan,selection,persos);
- if(clan==ENNEMI)
- {
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
- SDL_Flip (surfaces->Pecran);
- }
- if (*Vtourallie==2)
- {
- inverse(Vtour);
- *Vtourallie=0;
- }
- else
- {
- (*Vtourallie)++;
- Fblitterpersos(surfaces,positions,persos);
- Fblitcoloredselection(surfaces,positions,*Vtourallie,persos);
- }
- break;
- }
- break;
- }
- }
- if (delay)
- SDL_Delay(1000);
- SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats);
- SDL_Flip(surfaces->Pecran);
- return continuer;
- return 0;
-}
-
-int Fmagiesoin(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int *Vtour)
-{
- unsigned int continuer=1;
- SDL_Event event;
- int max;
- int min;
- int soins;
- int clan=ALLIE;
- int delay=1;
- int selection=0;
- int Bdegats=SOINS;
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
- while(persos[selection].etat==MORT)
- selection++;
- Fchangercurseurpersos (surfaces,positions,selection,persos);
- while(continuer)
- {
- SDL_WaitEvent(&event);
- switch(event.type)
- {
- case SDL_KEYDOWN:
- switch(event.key.keysym.sym)
- {
- case SDLK_ESCAPE:
- continuer = 0;
- if(clan==ENNEMI)
- {
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);
- }
- else
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);
- SDL_Flip (surfaces->Pecran);
- break;
- SELECTION_CIBLE()
- case SDLK_RETURN:
- max=Fcalculersoins(persos,Vtourallie,&min,ennemis,selection);
- soins=(rand()%(max-min+1))+min;
- if(soins<0)
- soins=0;
- if(clan==ENNEMI)
- {
- if(Bdegats==DEGATS)
- ennemis[selection].pv-=soins;
- else
- ennemis[selection].pv+=soins;
- if(ennemis[selection].pv<=0)
- {
- ennemis[selection].pv=0;
- ennemis[selection].etat=MORT;
- positions->Vpositionmort.x=positions->Vpositionennemis[selection].x+surfaces->Tennemi[selection]->w/2-surfaces->Pmort->w/2;
- positions->Vpositionmort.y=positions->Vpositionennemis[selection].y+surfaces->Tennemi[selection]->h/2-surfaces->Pmort->h/2;
- SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort);
- }
- else if(ennemis[selection].pv>ennemis[selection].pvinitiaux)
- ennemis[selection].pv=ennemis[selection].pvinitiaux;
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);
- }
- else
- {
- if(Bdegats==DEGATS)
- persos[selection].pv-=soins;
- else
- persos[selection].pv+=soins;
- if(persos[selection].pv<=0)
- {
- persos[selection].pv=0;
- persos[selection].etat=MORT;
- positions->Vpositionmort.x=positions->Vpositionpersos[selection].x+surfaces->Tperso[selection]->w/2-surfaces->Pmort->w/2;
- positions->Vpositionmort.y=positions->Vpositionpersos[selection].y+surfaces->Tperso[selection]->h/2-surfaces->Pmort->h/2;
- SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort);
- }
- else if(persos[selection].pv>persos[selection].pvinitiaux)
- persos[selection].pv=persos[selection].pvinitiaux;
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);
- }
- if(Bdegats==DEGATS)
- Fafficherdegats (surfaces,positions,soins,clan,selection,persos);
- else
- Faffichersoins (surfaces,positions,soins,clan,selection,persos);
- if(clan==ENNEMI)
- {
- SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
- SDL_Flip (surfaces->Pecran);
- }
- if (*Vtourallie==2)
- {
- *Vtourallie=0;
- inverse(Vtour);
- }
- else
- {
- (*Vtourallie)++;
- Fblitterpersos(surfaces,positions,persos);
- Fblitcoloredselection(surfaces,positions,*Vtourallie,persos);
- }
- continuer=0;
- break;
- }
- break;
- }
- }
- if (delay)
- SDL_Delay(1000);
- SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats);
- SDL_Flip(surfaces->Pecran);
- return continuer;
-}
-
-int Fcalculersoins(PERSONNAGES persos[],int *Vtourallie,int *min,ENNEMIS ennemis[],int selection)
-{
- unsigned int soins;
- int max;
- int taux;
-
- soins=persos[*Vtourallie].magie*20;
- taux=soins/4;
- max=soins+taux;
- *min=soins-taux;
-
- return max;
-}
-
-
-
-
+#include <stdlib.h> +#include <stdio.h> +#include <SDL/SDL.h> +#include "structures.h" +#include "constantes.h" +#include "prototypes.h" + +int Fmagieelement (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis, int element,int *Vtour) +{ + int max; + int min; + unsigned int continuer = 1; + int degats; + int selection = 0; + int delay=1; + unsigned int Bdegats=DEGATS; + int clan=ENNEMI; + SDL_Event event; + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); + while(ennemis[selection].etat==MORT) + selection++; + Fchangercurseurennemis (surfaces,positions,selection,ennemis); + while (continuer) + { + SDL_Flip (surfaces->Pecran); + SDL_WaitEvent (&event); + switch (event.type) + { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_ESCAPE: + continuer = 0; + if(clan==ENNEMI) + { + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); + } + else + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); + SDL_Flip (surfaces->Pecran); + break; + SELECTION_CIBLE() + case SDLK_RETURN: + continuer=0; + max=Fcalculerdegats(persos,Vtourallie,&min,ennemis,selection,clan,TYPE_MAGIE); + degats=(rand()%(max-min+1))+min; + if(degats<0) + degats=0; + if(element!=NON_ELEMENTAIRE) + { + if (ennemis[selection].resistance[element]==ACTIVE) + degats/=2; + else if(ennemis[selection].sensibilite[element]==ACTIVE) + degats*=2; + else if(ennemis[selection].invulnerabilite[element]==ACTIVE) + degats=0; + else if(ennemis[selection].absorbtion[element]==ACTIVE) + inverse(&Bdegats); + } + if(clan==ENNEMI) + { + if(Bdegats==DEGATS) + ennemis[selection].pv-=degats; + else + ennemis[selection].pv+=degats; + if(ennemis[selection].pv<=0) + { + ennemis[selection].pv=0; + ennemis[selection].etat=MORT; + positions->Vpositionmort.x=positions->Vpositionennemis[selection].x+surfaces->Tennemi[selection]->w/2-surfaces->Pmort->w/2; + positions->Vpositionmort.y=positions->Vpositionennemis[selection].y+surfaces->Tennemi[selection]->h/2-surfaces->Pmort->h/2; + SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); + } + else if(ennemis[selection].pv>ennemis[selection].pvinitiaux) + ennemis[selection].pv=ennemis[selection].pvinitiaux; + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); + } + else + { + if(Bdegats==DEGATS) + persos[selection].pv-=degats; + else + persos[selection].pv+=degats; + if(persos[selection].pv<=0) + { + persos[selection].pv=0; + persos[selection].etat=MORT; + positions->Vpositionmort.x=positions->Vpositionpersos[selection].x+surfaces->Tperso[selection]->w/2-surfaces->Pmort->w/2; + positions->Vpositionmort.y=positions->Vpositionpersos[selection].y+surfaces->Tperso[selection]->h/2-surfaces->Pmort->h/2; + SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); + } + else if(persos[selection].pv>persos[selection].pvinitiaux) + persos[selection].pv=persos[selection].pvinitiaux; + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); + } + if(Bdegats==DEGATS) + Fafficherdegats (surfaces,positions,degats,clan,selection,persos); + else + Faffichersoins (surfaces,positions,degats,clan,selection,persos); + if(clan==ENNEMI) + { + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); + SDL_Flip (surfaces->Pecran); + } + if (*Vtourallie==2) + { + inverse(Vtour); + *Vtourallie=0; + } + else + { + (*Vtourallie)++; + Fblitterpersos(surfaces,positions,persos); + Fblitcoloredselection(surfaces,positions,*Vtourallie,persos); + } + break; + } + break; + } + } + if (delay) + SDL_Delay(1000); + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); + SDL_Flip(surfaces->Pecran); + return continuer; + return 0; +} + +int Fmagiesoin(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int *Vtour) +{ + unsigned int continuer=1; + SDL_Event event; + int max; + int min; + int soins; + int clan=ALLIE; + int delay=1; + int selection=0; + int Bdegats=SOINS; + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); + while(persos[selection].etat==MORT) + selection++; + Fchangercurseurpersos (surfaces,positions,selection,persos); + while(continuer) + { + SDL_WaitEvent(&event); + switch(event.type) + { + case SDL_KEYDOWN: + switch(event.key.keysym.sym) + { + case SDLK_ESCAPE: + continuer = 0; + if(clan==ENNEMI) + { + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); + } + else + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); + SDL_Flip (surfaces->Pecran); + break; + SELECTION_CIBLE() + case SDLK_RETURN: + max=Fcalculersoins(persos,Vtourallie,&min,ennemis,selection); + soins=(rand()%(max-min+1))+min; + if(soins<0) + soins=0; + if(clan==ENNEMI) + { + if(Bdegats==DEGATS) + ennemis[selection].pv-=soins; + else + ennemis[selection].pv+=soins; + if(ennemis[selection].pv<=0) + { + ennemis[selection].pv=0; + ennemis[selection].etat=MORT; + positions->Vpositionmort.x=positions->Vpositionennemis[selection].x+surfaces->Tennemi[selection]->w/2-surfaces->Pmort->w/2; + positions->Vpositionmort.y=positions->Vpositionennemis[selection].y+surfaces->Tennemi[selection]->h/2-surfaces->Pmort->h/2; + SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); + } + else if(ennemis[selection].pv>ennemis[selection].pvinitiaux) + ennemis[selection].pv=ennemis[selection].pvinitiaux; + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); + } + else + { + if(Bdegats==DEGATS) + persos[selection].pv-=soins; + else + persos[selection].pv+=soins; + if(persos[selection].pv<=0) + { + persos[selection].pv=0; + persos[selection].etat=MORT; + positions->Vpositionmort.x=positions->Vpositionpersos[selection].x+surfaces->Tperso[selection]->w/2-surfaces->Pmort->w/2; + positions->Vpositionmort.y=positions->Vpositionpersos[selection].y+surfaces->Tperso[selection]->h/2-surfaces->Pmort->h/2; + SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); + } + else if(persos[selection].pv>persos[selection].pvinitiaux) + persos[selection].pv=persos[selection].pvinitiaux; + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); + } + if(Bdegats==DEGATS) + Fafficherdegats (surfaces,positions,soins,clan,selection,persos); + else + Faffichersoins (surfaces,positions,soins,clan,selection,persos); + if(clan==ENNEMI) + { + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); + SDL_Flip (surfaces->Pecran); + } + if (*Vtourallie==2) + { + *Vtourallie=0; + inverse(Vtour); + } + else + { + (*Vtourallie)++; + Fblitterpersos(surfaces,positions,persos); + Fblitcoloredselection(surfaces,positions,*Vtourallie,persos); + } + continuer=0; + break; + } + break; + } + } + if (delay) + SDL_Delay(1000); + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); + SDL_Flip(surfaces->Pecran); + return continuer; +} + +int Fcalculersoins(PERSONNAGES persos[],int *Vtourallie,int *min,ENNEMIS ennemis[],int selection) +{ + unsigned int soins; + int max; + int taux; + + soins=persos[*Vtourallie].magie*20; + taux=soins/4; + max=soins+taux; + *min=soins-taux; + + return max; +} + + + + |