#include #include #include #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: case SDLK_a: 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: case SDLK_f: 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_boolean(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_boolean(*Vtour); *Vtourallie=0; } else { (*Vtourallie)++; Fblitterpersos(surfaces,positions,persos); Fblitcoloredselection(surfaces,positions,*Vtourallie,persos); } break; default: 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: case SDLK_a: 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: case SDLK_f: 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_boolean(*Vtour); } else { (*Vtourallie)++; Fblitterpersos(surfaces,positions,persos); Fblitcoloredselection(surfaces,positions,*Vtourallie,persos); } continuer=0; break; default: 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; }