From e816f16a5007798968f4c9003b3159a45485e88f Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Sun, 26 Oct 2014 18:20:28 +0000 Subject: 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 --- actions.c | 1072 ++++++++++++++++++++++++++--------------------------- blits.c | 800 +++++++++++++++++++-------------------- competences.c | 240 ++++++------ constantes.h | 338 ++++++++--------- ia.c | 132 +++---- jouer.c | 444 +++++++++++----------- magies.c | 510 ++++++++++++------------- main.c | 732 +++++++++++++++++------------------- map.c | 260 ++++++------- menuchoixpersos.c | 308 +++++++-------- menuoptions.c | 20 +- menuprincipal.c | 172 ++++----- prototypes.h | 122 +++--- structures.h | 238 ++++++------ 14 files changed, 2678 insertions(+), 2710 deletions(-) diff --git a/actions.c b/actions.c index ebf3af8..e14bc09 100644 --- a/actions.c +++ b/actions.c @@ -1,536 +1,536 @@ -#include -#include "structures.h" -#include "constantes.h" -#include "prototypes.h" -#include -#include - -void Fattaquer(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int *Vtour) -{ - int max; - int min; - unsigned int continuer = 1; - int degats; - unsigned int Bdegats=DEGATS; - int clan=ENNEMI; - int selection = 0; - SDL_Event event; - int delay=1; - 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: - delay=0; - 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_ATTAQUE); - degats=(rand()%(max-min+1))+min; - if(degats<0) - degats=0; - if(clan==ENNEMI) // si l'action se fait sur un ennemi - { - if(Bdegats==DEGATS) // si on inflige des degats - ennemis[selection].pv-=degats; // on vire des pv - else // si c'est un soin pour x raison - ennemis[selection].pv+=degats; // on rajoute des pv - 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 // sinon si on actionne sur un allié - { - 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) // si l'ennemi est visé - { - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); - SDL_Flip (surfaces->Pecran); // on supprime le cadre cible de l'ecran - } - 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); -} - -int Fcalculerdegats(PERSONNAGES persos[],int *Vtourallie,int *min,ENNEMIS ennemis[],int selection,int camp,int type) -{ - unsigned int degats; - int max; - int taux; - - if(type==TYPE_ATTAQUE) - { - if(camp==ENNEMI) - degats=persos[*Vtourallie].force*60-ennemis[selection].defense*50; - else - degats=persos[*Vtourallie].force*60-persos[selection].defense*50; - } - else - { - if(camp==ENNEMI) - degats=persos[*Vtourallie].magie*60-ennemis[selection].defensemagique*50; - else - degats=persos[*Vtourallie].magie*60-persos[selection].defensemagique*50; - } - taux=degats/4; - max=degats+taux; - *min=degats-taux; - - return max; -} - -void Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int *Vtour) -{ - SDL_Event event; - unsigned int continuer=1; - int nbactions=5; - unsigned int element; - int page=0; - int selection=0; - - while (continuer) - { - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_NOIRE,NULL); - SDL_WaitEvent (&event); - switch (event.type) - { - case SDL_KEYDOWN: - switch (event.key.keysym.sym) - { - case SDLK_ESCAPE: - continuer=0; - break; - case SDLK_UP: - if(selection!=0) - selection--; - else - selection=nbactions-1; - page=selection/3; - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_NOIRE,NULL); - break; - case SDLK_DOWN: - if (selection!=nbactions-1) - selection++; - else - selection=0; - page=selection/3; - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_NOIRE,NULL); - break; - case SDLK_RETURN: - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip(surfaces->Pecran); - continuer=Fmagieelement(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,selection,Vtour); - break; - } - } - } -} - -void Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int *Vtour) -{ - int continuer=1; - int nbactions=1; - int page=0; - int selection=0; - SDL_Event event; - - while (continuer) - { - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_BLANCHE,NULL); - SDL_WaitEvent (&event); - switch (event.type) - { - case SDL_KEYDOWN: - switch (event.key.keysym.sym) - { - case SDLK_ESCAPE: - continuer=0; - break; - case SDLK_UP: - if (selection!=0) - selection--; - else - selection=nbactions-1; - page=selection/3; - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_BLANCHE,NULL); - break; - case SDLK_DOWN: - if(selection!=nbactions-1) - selection++; - else - selection=0; - page=selection/3; - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_BLANCHE,NULL); - break; - case SDLK_RETURN: - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip(surfaces->Pecran); - if(selection==SOIN) - continuer=Fmagiesoin(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,Vtour); - break; - } - } - } -} - -void Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int*Vtour) -{ - SDL_Event event; - unsigned int continuer=1; - int nbactions=4; - int page=0; - int selection=0; - - while (continuer) - { - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS,objets); - SDL_WaitEvent (&event); - switch (event.type) - { - case SDL_KEYDOWN: - switch (event.key.keysym.sym) - { - case SDLK_ESCAPE: - continuer=0; - break; - case SDLK_UP: - if(selection!=0) - selection--; - else - selection=nbactions-1; - page=selection/3; - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS,objets); - break; - case SDLK_DOWN: - if (selection!=nbactions-1) - selection++; - else - selection=0; - page=selection/3; - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS,objets); - break; - case SDLK_RETURN: - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip(surfaces->Pecran); - if(page==0) - { - if(selection==POTION) - continuer=Fpotion(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,objets,selection,Vtour); - else if(selection==ETHER) - continuer=Fether(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,objets,selection,Vtour); - else if(selection==POTIONPLUS) - continuer=Fpotion(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,objets,selection,Vtour); - } - else if(page==1) - { - if(selection==ETHERPLUS) - continuer=Fether(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,objets,selection,Vtour); - } - break; - } - } - } -} - -int Fpotion(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type,int*Vtour) -{ - if(type==POTION&&objets->potions<=0) - return 1; - else if(type==POTIONPLUS&&objets->potionsplus<=0) - return 1; - else - { - int continuer=1; - SDL_Event event; - int selection=0; - int delay=1; - int soins=0; - int Bdegats=SOINS; - int clan=ALLIE; - 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: - delay=0; - 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: - if(type==POTION) - soins=1000; - else if(type==POTIONPLUS) - soins=4000; - 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 - { - Fblitcoloredselection(surfaces,positions,*Vtourallie,persos); - (*Vtourallie)++; - } - continuer=0; - if(type==POTION) - objets->potions--; - else if(type==POTIONPLUS) - objets->potionsplus--; - break; - } - break; - } - } - if (delay) - SDL_Delay(1000); - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip(surfaces->Pecran); - return continuer; - } -} - -int Fether(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type,int *Vtour) -{ - if(type==ETHER&&objets->ethers<=0) - return 1; - else if(type==ETHERPLUS&&objets->ethersplus<=0) - return 1; - else - { - int continuer=1; - SDL_Event event; - int delay=1; - int selection=0; - int soins=0; - int Bdegats=SOINS; - int clan=ALLIE; - 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: - delay=0; - 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: - if(type==ETHER) - soins=10; - else if(type==ETHERPLUS) - soins=40; - if(clan==ENNEMI) - { - if(Bdegats==DEGATS) - ennemis[selection].pm-=soins; - else - ennemis[selection].pm+=soins; - if(ennemis[selection].pm<=0) - { - ennemis[selection].pm=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].pm>ennemis[selection].pminitiaux) - ennemis[selection].pm=ennemis[selection].pminitiaux; - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); - } - else - { - if(Bdegats==DEGATS) - persos[selection].pm-=soins; - else - persos[selection].pm+=soins; - if(persos[selection].pm<=0) - { - persos[selection].pm=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].pm>persos[selection].pminitiaux) - persos[selection].pm=persos[selection].pminitiaux; - 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)++; - Fblitcoloredselection(surfaces,positions,*Vtourallie,persos); - } - continuer=0; - if(type==ETHER) - objets->ethers--; - else if(type==ETHERPLUS) - objets->ethersplus--; - break; - } - break; - } - } - if (delay) - SDL_Delay(1000); - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip(surfaces->Pecran); - return continuer; - } -} - - - +#include +#include "structures.h" +#include "constantes.h" +#include "prototypes.h" +#include +#include + +void Fattaquer(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int *Vtour) +{ + int max; + int min; + unsigned int continuer = 1; + int degats; + unsigned int Bdegats=DEGATS; + int clan=ENNEMI; + int selection = 0; + SDL_Event event; + int delay=1; + 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: + delay=0; + 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_ATTAQUE); + degats=(rand()%(max-min+1))+min; + if(degats<0) + degats=0; + if(clan==ENNEMI) // si l'action se fait sur un ennemi + { + if(Bdegats==DEGATS) // si on inflige des degats + ennemis[selection].pv-=degats; // on vire des pv + else // si c'est un soin pour x raison + ennemis[selection].pv+=degats; // on rajoute des pv + 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 // sinon si on actionne sur un allié + { + 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) // si l'ennemi est visé + { + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); + SDL_Flip (surfaces->Pecran); // on supprime le cadre cible de l'ecran + } + 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); +} + +int Fcalculerdegats(PERSONNAGES persos[],int *Vtourallie,int *min,ENNEMIS ennemis[],int selection,int camp,int type) +{ + unsigned int degats; + int max; + int taux; + + if(type==TYPE_ATTAQUE) + { + if(camp==ENNEMI) + degats=persos[*Vtourallie].force*60-ennemis[selection].defense*50; + else + degats=persos[*Vtourallie].force*60-persos[selection].defense*50; + } + else + { + if(camp==ENNEMI) + degats=persos[*Vtourallie].magie*60-ennemis[selection].defensemagique*50; + else + degats=persos[*Vtourallie].magie*60-persos[selection].defensemagique*50; + } + taux=degats/4; + max=degats+taux; + *min=degats-taux; + + return max; +} + +void Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int *Vtour) +{ + SDL_Event event; + unsigned int continuer=1; + int nbactions=5; + unsigned int element; + int page=0; + int selection=0; + + while (continuer) + { + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_NOIRE,NULL); + SDL_WaitEvent (&event); + switch (event.type) + { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_ESCAPE: + continuer=0; + break; + case SDLK_UP: + if(selection!=0) + selection--; + else + selection=nbactions-1; + page=selection/3; + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_NOIRE,NULL); + break; + case SDLK_DOWN: + if (selection!=nbactions-1) + selection++; + else + selection=0; + page=selection/3; + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_NOIRE,NULL); + break; + case SDLK_RETURN: + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); + SDL_Flip(surfaces->Pecran); + continuer=Fmagieelement(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,selection,Vtour); + break; + } + } + } +} + +void Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int *Vtour) +{ + int continuer=1; + int nbactions=1; + int page=0; + int selection=0; + SDL_Event event; + + while (continuer) + { + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_BLANCHE,NULL); + SDL_WaitEvent (&event); + switch (event.type) + { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_ESCAPE: + continuer=0; + break; + case SDLK_UP: + if (selection!=0) + selection--; + else + selection=nbactions-1; + page=selection/3; + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_BLANCHE,NULL); + break; + case SDLK_DOWN: + if(selection!=nbactions-1) + selection++; + else + selection=0; + page=selection/3; + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_BLANCHE,NULL); + break; + case SDLK_RETURN: + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); + SDL_Flip(surfaces->Pecran); + if(selection==SOIN) + continuer=Fmagiesoin(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,Vtour); + break; + } + } + } +} + +void Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int*Vtour) +{ + SDL_Event event; + unsigned int continuer=1; + int nbactions=4; + int page=0; + int selection=0; + + while (continuer) + { + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS,objets); + SDL_WaitEvent (&event); + switch (event.type) + { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_ESCAPE: + continuer=0; + break; + case SDLK_UP: + if(selection!=0) + selection--; + else + selection=nbactions-1; + page=selection/3; + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS,objets); + break; + case SDLK_DOWN: + if (selection!=nbactions-1) + selection++; + else + selection=0; + page=selection/3; + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS,objets); + break; + case SDLK_RETURN: + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); + SDL_Flip(surfaces->Pecran); + if(page==0) + { + if(selection==POTION) + continuer=Fpotion(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,objets,selection,Vtour); + else if(selection==ETHER) + continuer=Fether(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,objets,selection,Vtour); + else if(selection==POTIONPLUS) + continuer=Fpotion(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,objets,selection,Vtour); + } + else if(page==1) + { + if(selection==ETHERPLUS) + continuer=Fether(surfaces,positions,persos,Vtourallie,ennemis,Vnbennemis,objets,selection,Vtour); + } + break; + } + } + } +} + +int Fpotion(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type,int*Vtour) +{ + if(type==POTION&&objets->potions<=0) + return 1; + else if(type==POTIONPLUS&&objets->potionsplus<=0) + return 1; + else + { + int continuer=1; + SDL_Event event; + int selection=0; + int delay=1; + int soins=0; + int Bdegats=SOINS; + int clan=ALLIE; + 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: + delay=0; + 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: + if(type==POTION) + soins=1000; + else if(type==POTIONPLUS) + soins=4000; + 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 + { + Fblitcoloredselection(surfaces,positions,*Vtourallie,persos); + (*Vtourallie)++; + } + continuer=0; + if(type==POTION) + objets->potions--; + else if(type==POTIONPLUS) + objets->potionsplus--; + break; + } + break; + } + } + if (delay) + SDL_Delay(1000); + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); + SDL_Flip(surfaces->Pecran); + return continuer; + } +} + +int Fether(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type,int *Vtour) +{ + if(type==ETHER&&objets->ethers<=0) + return 1; + else if(type==ETHERPLUS&&objets->ethersplus<=0) + return 1; + else + { + int continuer=1; + SDL_Event event; + int delay=1; + int selection=0; + int soins=0; + int Bdegats=SOINS; + int clan=ALLIE; + 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: + delay=0; + 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: + if(type==ETHER) + soins=10; + else if(type==ETHERPLUS) + soins=40; + if(clan==ENNEMI) + { + if(Bdegats==DEGATS) + ennemis[selection].pm-=soins; + else + ennemis[selection].pm+=soins; + if(ennemis[selection].pm<=0) + { + ennemis[selection].pm=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].pm>ennemis[selection].pminitiaux) + ennemis[selection].pm=ennemis[selection].pminitiaux; + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); + } + else + { + if(Bdegats==DEGATS) + persos[selection].pm-=soins; + else + persos[selection].pm+=soins; + if(persos[selection].pm<=0) + { + persos[selection].pm=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].pm>persos[selection].pminitiaux) + persos[selection].pm=persos[selection].pminitiaux; + 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)++; + Fblitcoloredselection(surfaces,positions,*Vtourallie,persos); + } + continuer=0; + if(type==ETHER) + objets->ethers--; + else if(type==ETHERPLUS) + objets->ethersplus--; + break; + } + break; + } + } + if (delay) + SDL_Delay(1000); + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); + SDL_Flip(surfaces->Pecran); + return continuer; + } +} + + + diff --git a/blits.c b/blits.c index 7722a9a..34d8180 100644 --- a/blits.c +++ b/blits.c @@ -1,400 +1,400 @@ -#include -#include -#include -#include "structures.h" -#include "constantes.h" -#include "prototypes.h" -#include -#include -#include - -void Fblitterennemis (SURFACES *surfaces, POSITIONS *positions,ENNEMIS ennemis[],int Vnbennemis) -{ - int i; - Finitialiserpositionsennemis (surfaces,positions,Vnbennemis); - for (i = 0;i <= Vnbennemis;i++) - SDL_BlitSurface (surfaces->Tennemi[i],NULL,surfaces->Pecran,&positions->Vpositionennemis[i]); - SDL_Flip (surfaces->Pecran); -} - -void Fblitterpersos (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[]) -{ - int i; - for(i=0;i<3;i++) - { - if(persos[i].classe==PALADIN) - SDL_BlitSurface(surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionpersos[i]); - else if(persos[i].classe==PRETRE) - SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionpersos[i]); - else if(persos[i].classe==VOLEUR) - SDL_BlitSurface(surfaces->Pvoleur,NULL,surfaces->Pecran,&positions->Vpositionpersos[i]); - if(persos[i].etat==MORT) - { - positions->Vpositionmort.x=positions->Vpositionpersos[i].x+surfaces->Tperso[i]->w/2-surfaces->Pmort->w/2; - positions->Vpositionmort.y=positions->Vpositionpersos[i].y+surfaces->Tperso[i]->h/2-surfaces->Pmort->h/2; - SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); - } - Fblitterpmpvpersos(surfaces,positions,persos,i); - } -} - -void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions,int selection,ENNEMIS ennemis[]) -{ - SDL_Color couleur={120,0,0,0}; - TTF_Font *police=NULL; - char chaine[100]; - if (surfaces->Pnomcible!=NULL) - { - SDL_FreeSurface (surfaces->Pnomcible); - surfaces->Pnomcible=NULL; - } - police=TTF_OpenFont("C://Windows//Fonts//times.ttf",20); - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); - SELECTION (0,ENNEMI) - SELECTION (1,ENNEMI) - SELECTION (2,ENNEMI) - SELECTION (3,ENNEMI) - SELECTION (4,ENNEMI) - if (ennemis[selection].classe==GUERRIER_GOBELIN) - sprintf(chaine,"GUERRIER GOBELIN"); - surfaces->Pnomcible = TTF_RenderText_Blended (police,chaine,couleur); - positions->Vpositionnomcible.x = positions->Vpositioncadrecible.x+surfaces->Pcadrecible->w/2-surfaces->Pnomcible->w/2; - positions->Vpositionnomcible.y = positions->Vpositioncadrecible.y + 10; - Fblitteractivedesactive (surfaces,positions,ennemis,selection); - Fblitterpvcible (surfaces,positions,ennemis,selection); - Fblitterpmcible (surfaces,positions,ennemis,selection); - SDL_BlitSurface (surfaces->Pnomcible,NULL,surfaces->Pecran,&positions->Vpositionnomcible); - SDL_Flip (surfaces->Pecran); - TTF_CloseFont(police); -} - -void Fchangercurseurpersos (SURFACES *surfaces, POSITIONS *positions,int selection,PERSONNAGES persos[]) -{ - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); - SDL_Flip (surfaces->Pecran); - SELECTION (0,ALLIE) - SELECTION (1,ALLIE) - SELECTION (2,ALLIE) - SELECTION (3,ALLIE) - SELECTION (4,ALLIE) - SDL_Flip (surfaces->Pecran); -} - -void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions,int type,OBJET *objets) -{ - int i; - TTF_Font *police=NULL; - SDL_Color couleur={0,0,0,0}; - char chaine[3][50]; - police=TTF_OpenFont ("C://Windows//Fonts//TIMESBI.TTF",20); - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); - SDL_BlitSurface (surfaces->Pcadreactions,NULL,surfaces->Pecran,&positions->Vpositioncadreactions); - for(i=0;iPactionselectionnee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[selection-page*3]); - } - for(i=0;i<3;i++) - { - if(surfaces->Pnomactions[i]!=NULL) - { - SDL_FreeSurface(surfaces->Pnomactions[i]); - surfaces->Pnomactions[i]=NULL; - } - } - if(type==ACTIONS) - { - if(page==0) - { - ECRIRE("ATTAQUE",0); - ECRIRE("MAGIE BLANCHE",1); - ECRIRE("MAGIE NOIRE",2); - } - else if(page==1) - { - ECRIRE("TECHNIQUES",0); - ECRIRE("OBJETS",1); - } - } - else if(type==MAGIE_BLANCHE) - { - if (page==0) - { - ECRIRE("SOIN",0); - } - } - else if(type==MAGIE_NOIRE) - { - if(page==0) - { - ECRIRE("FEU",0); - ECRIRE("GLACE",1); - ECRIRE("EAU",2); - } - else if(page==1) - { - ECRIRE("TONNERRE",0); - ECRIRE("CHOC",1); - } - } - else if(type==OBJETS) - { - if(page==0) - { - ECRIRE("POTION",0); - ECRIRE("ETHER",1); - ECRIRE("POTION +",2); - sprintf(chaine[0],"%d",objets->potions); - surfaces->Pquantite[0]=TTF_RenderText_Blended(police,chaine[0],couleur); - sprintf(chaine[1],"%d",objets->ethers); - surfaces->Pquantite[1]=TTF_RenderText_Blended(police,chaine[1],couleur); - sprintf(chaine[2],"%d",objets->potionsplus); - surfaces->Pquantite[2]=TTF_RenderText_Blended(police,chaine[2],couleur); - SDL_BlitSurface(surfaces->Pquantite[0],NULL,surfaces->Pecran,&positions->Vpositionquantite[0]); - SDL_BlitSurface(surfaces->Pquantite[1],NULL,surfaces->Pecran,&positions->Vpositionquantite[1]); - SDL_BlitSurface(surfaces->Pquantite[2],NULL,surfaces->Pecran,&positions->Vpositionquantite[2]); - } - else if(page==1) - { - ECRIRE("ETHER +",0); - sprintf(chaine[0],"%d",objets->ethersplus); - surfaces->Pquantite[0]=TTF_RenderText_Blended(police,chaine[0],couleur); - SDL_BlitSurface(surfaces->Pquantite[0],NULL,surfaces->Pecran,&positions->Vpositionquantite[0]); - } - } - if (page==nbactions/3) - { - if(3*(page+1)-nbactions==1) - SDL_BlitSurface (surfaces->Pactiondesactivee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[2]); - if(3*(page+1)-nbactions==2) - { - SDL_BlitSurface (surfaces->Pactiondesactivee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[2]); - SDL_BlitSurface (surfaces->Pactiondesactivee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[1]); - } - } - SDL_Flip(surfaces->Pecran); - TTF_CloseFont (police); -} - -void Fafficherdegats (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible,PERSONNAGES persos[]) -{ - char chaine[10]; - TTF_Font *police = NULL; - SDL_Color fg = {210,0,0,0}; - if(surfaces->Pnbdegats != NULL) - { - SDL_FreeSurface (surfaces->Pnbdegats); - surfaces->Pnbdegats=NULL; - } - sprintf (chaine,"%d ", degats); - police = TTF_OpenFont ("C://Windows//Fonts//TIMES.TTF", 30 -); - TTF_SetFontStyle(police,TTF_STYLE_BOLD); - surfaces->Pnbdegats = TTF_RenderText_Blended(police,chaine,fg); - if(clan==ENNEMI) - { - positions->Vpositiondegats.x=positions->Vpositionennemis[cible].x-30-surfaces->Pnbdegats->w; - positions->Vpositiondegats.y=positions->Vpositionennemis[cible].y+surfaces->Tennemi[cible]->h/2-surfaces->Pnbdegats->h/2; - } - else - { - positions->Vpositiondegats.x=positions->Vpositionpersos[cible].x+surfaces->Tperso[cible]->w+30; - positions->Vpositiondegats.y=positions->Vpositionpersos[cible].y+surfaces->Tperso[cible]->h/2-surfaces->Pnbdegats->h/2; - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositionpvpersos[cible],surfaces->Pecran,&positions->Vpositionpvpersos[cible]); - Fblitterpersos(surfaces,positions,persos); - } - positions->Vpositiondegats.w=surfaces->Pnbdegats->w; - positions->Vpositiondegats.h=surfaces->Pnbdegats->h; - SDL_BlitSurface (surfaces->Pnbdegats,NULL,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip (surfaces->Pecran); - TTF_CloseFont (police); -} - -void Faffichersoins (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible,PERSONNAGES persos[]) -{ - char chaine[10]; - TTF_Font *police = NULL; - SDL_Color fg = {80,255,80,0}; - - if (surfaces->Pnbdegats != NULL) - { - SDL_FreeSurface (surfaces->Pnbdegats); - surfaces->Pnbdegats=NULL; - } - sprintf (chaine,"%d", degats); - police = TTF_OpenFont ("C://Windows//Fonts//TIMES.TTF", 30); - TTF_SetFontStyle(police,TTF_STYLE_BOLD); - surfaces->Pnbdegats = TTF_RenderText_Blended (police,chaine,fg); - if(clan==ENNEMI) - { - positions->Vpositiondegats.x=positions->Vpositionennemis[cible].x-30-surfaces->Pnbdegats->w; - positions->Vpositiondegats.y=positions->Vpositionennemis[cible].y+surfaces->Tennemi[cible]->h/2-surfaces->Pnbdegats->h/2; - } - else - { - positions->Vpositiondegats.x=positions->Vpositionpersos[cible].x+surfaces->Tperso[cible]->w+30; - positions->Vpositiondegats.y=positions->Vpositionpersos[cible].y+surfaces->Tperso[cible]->h/2-surfaces->Pnbdegats->h/2; - - } - positions->Vpositiondegats.w=surfaces->Pnbdegats->w; - positions->Vpositiondegats.h=surfaces->Pnbdegats->h; - SDL_BlitSurface (surfaces->Pnbdegats,NULL,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip (surfaces->Pecran); - - TTF_CloseFont (police); -} - -void Fblitteractivedesactive (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection) -{ - int i; - - for (i=0;i<4;i++) - { - if(ennemis[selection].sensibilite[i] == ACTIVE) - SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i]); - else - SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i]); - } - for (i=0;i<4;i++) - { - if(ennemis[selection].resistance[i] == ACTIVE) - SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+4]); - else - SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+4]); - } - for(i=0;i<4;i++) - { - if (ennemis[selection].invulnerabilite[i] == ACTIVE) - SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+8]); - else - SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+8]); - } - for (i=0;i<4;i++) - { - if (ennemis[selection].absorbtion[i] == ACTIVE) - SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+12]); - else - SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+12]); - } -} - -void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection) -{ - TTF_Font *police = NULL; - SDL_Color couleur = {132,215,107,0}; - char chaine[50]; - - if (surfaces->Ppvcible != NULL) - { - SDL_FreeSurface (surfaces->Ppvcible); - surfaces->Ppvcible=NULL; - } - if (ennemis[selection].pv<0) - ennemis[selection].pv=0; - sprintf (chaine,"%d/%d",ennemis[selection].pv,ennemis[selection].pvinitiaux); - police=TTF_OpenFont ("C://Windows//Fonts//TIMESBI.TTF",18); - surfaces->Ppvcible=TTF_RenderText_Blended (police,chaine,couleur); - SDL_BlitSurface (surfaces->Ppvcible,NULL,surfaces->Pecran,&positions->Vpositionpvcible); - TTF_CloseFont (police); -} - -void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection) -{ - TTF_Font *police = NULL; - SDL_Color couleur = {132,215,107,0}; - char chaine[50]; - - if (surfaces->Ppmcible != NULL) - { - SDL_FreeSurface (surfaces->Ppmcible); - surfaces->Ppvcible=NULL; - } - sprintf (chaine,"%d/%d",ennemis[selection].pm,ennemis[selection].pminitiaux); - police=TTF_OpenFont ("C://Windows//Fonts//TIMESBI.TTF",18); - surfaces->Ppmcible=TTF_RenderText_Blended (police,chaine,couleur); - SDL_BlitSurface (surfaces->Ppmcible,NULL,surfaces->Pecran,&positions->Vpositionpmcible); - TTF_CloseFont (police); -} - -void Fblitterpmpvpersos(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int selection) -{ - TTF_Font *police=NULL; - SDL_Color fg={132,215,107,0},bg={100,0,0,0}; - char chaine[2][50]; - police=TTF_OpenFont("C://WINDOWS//Fonts//TIMESBI.TTF",18); - sprintf(chaine[0],"PV %d/%d ",persos[selection].pv,persos[selection].pvinitiaux); - surfaces->Ppvpersos=TTF_RenderText_Shaded(police,chaine[0],fg,bg); - sprintf(chaine[1],"PM %d/%d ",persos[selection].pm,persos[selection].pminitiaux); - surfaces->Ppmpersos=TTF_RenderText_Shaded(police,chaine[1],fg,bg); - positions->Vpositionpvpersos[selection].x=(positions->Vpositionpersos[selection].x+surfaces->Tperso[selection]->w/2-surfaces->Ppvpersos->w/2); - positions->Vpositionpmpersos[selection].x=(positions->Vpositionpersos[selection].x+surfaces->Tperso[selection]->w/2-surfaces->Ppmpersos->w/2); - positions->Vpositionpvpersos[selection].y=(positions->Vpositionpersos[selection].y+surfaces->Tperso[selection]->h-surfaces->Ppvpersos->h-surfaces->Ppmpersos->h); - positions->Vpositionpmpersos[selection].y=(positions->Vpositionpersos[selection].y+surfaces->Tperso[selection]->h-surfaces->Ppmpersos->h); - SDL_BlitSurface(surfaces->Ppvpersos,NULL,surfaces->Pecran,&positions->Vpositionpvpersos[selection]); - SDL_BlitSurface(surfaces->Ppmpersos,NULL,surfaces->Pecran,&positions->Vpositionpmpersos[selection]); - positions->Vpositionpvpersos[selection].w=surfaces->Ppvpersos->w; - positions->Vpositionpvpersos[selection].h=surfaces->Ppvpersos->h; - positions->Vpositionpmpersos[selection].w=surfaces->Ppmpersos->w; - positions->Vpositionpmpersos[selection].h=surfaces->Ppmpersos->h; - - TTF_CloseFont(police); -} - -void Fblitterfond(SURFACES* surfaces) -{ - SDL_Rect position; - position.x=0; - position.y=0; - surfaces->Pfondjeu=IMG_Load("images/jeu/textures/background.jpg"); - SDL_BlitSurface(surfaces->Pfondjeu,NULL,surfaces->Pecran,&position); - SDL_Flip(surfaces->Pecran); -} - -void Fcolourselection(SURFACES* surfaces, PERSONNAGES persos[],int Vtourallie,POSITIONS* positions) -{ - int x=0; - int i; - int y=0; - int tampon; - Uint32 pixel; - Uint8 r,g,b,a; - int ajout=30; - for(i=0;i<3;i++) - { - tampon=0; - SDL_LockSurface(surfaces->Tperso[i]); - for(y=0;yTperso[i]->h;y++) - { - for(x=0;xTperso[i]->w;x++) - { - pixel=obtenirPixel(surfaces->Tperso[i],x,y); - SDL_GetRGBA(pixel,surfaces->Pecran->format,&r,&g,&b,&a); - tampon=(int)r+ajout; - if(tampon>255) - tampon=255; - else if(tampon<0) - tampon=0; - r=(Uint8)tampon; - pixel=SDL_MapRGBA(surfaces->Pecran->format,r,g,b,a); - definirPixel(surfaces->Tperso[i],x,y,pixel); - } - } - SDL_UnlockSurface(surfaces->Tperso[i]); - SDL_SetColorKey(surfaces->Tperso[i],SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,r,g,b)); - } - SDL_Flip(surfaces->Pecran); - -} - -void Fblitcoloredselection (SURFACES surfaces[],POSITIONS positions[],int Vtourallie,PERSONNAGES persos[]) -{ - SDL_BlitSurface(surfaces->Tperso[Vtourallie],NULL,surfaces->Pecran,&positions->Vpositionpersos[Vtourallie]); - Fblitterpmpvpersos(surfaces,positions,persos,Vtourallie); - SDL_Flip(surfaces->Pecran); -} - - - - - - +#include +#include +#include +#include "structures.h" +#include "constantes.h" +#include "prototypes.h" +#include +#include +#include + +void Fblitterennemis (SURFACES *surfaces, POSITIONS *positions,ENNEMIS ennemis[],int Vnbennemis) +{ + int i; + Finitialiserpositionsennemis (surfaces,positions,Vnbennemis); + for (i = 0;i <= Vnbennemis;i++) + SDL_BlitSurface (surfaces->Tennemi[i],NULL,surfaces->Pecran,&positions->Vpositionennemis[i]); + SDL_Flip (surfaces->Pecran); +} + +void Fblitterpersos (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[]) +{ + int i; + for(i=0;i<3;i++) + { + if(persos[i].classe==PALADIN) + SDL_BlitSurface(surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionpersos[i]); + else if(persos[i].classe==PRETRE) + SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionpersos[i]); + else if(persos[i].classe==VOLEUR) + SDL_BlitSurface(surfaces->Pvoleur,NULL,surfaces->Pecran,&positions->Vpositionpersos[i]); + if(persos[i].etat==MORT) + { + positions->Vpositionmort.x=positions->Vpositionpersos[i].x+surfaces->Tperso[i]->w/2-surfaces->Pmort->w/2; + positions->Vpositionmort.y=positions->Vpositionpersos[i].y+surfaces->Tperso[i]->h/2-surfaces->Pmort->h/2; + SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); + } + Fblitterpmpvpersos(surfaces,positions,persos,i); + } +} + +void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions,int selection,ENNEMIS ennemis[]) +{ + SDL_Color couleur={120,0,0,0}; + TTF_Font *police=NULL; + char chaine[100]; + if (surfaces->Pnomcible!=NULL) + { + SDL_FreeSurface (surfaces->Pnomcible); + surfaces->Pnomcible=NULL; + } + police=TTF_OpenFont("C://Windows//Fonts//times.ttf",20); + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); + SELECTION (0,ENNEMI) + SELECTION (1,ENNEMI) + SELECTION (2,ENNEMI) + SELECTION (3,ENNEMI) + SELECTION (4,ENNEMI) + if (ennemis[selection].classe==GUERRIER_GOBELIN) + sprintf(chaine,"GUERRIER GOBELIN"); + surfaces->Pnomcible = TTF_RenderText_Blended (police,chaine,couleur); + positions->Vpositionnomcible.x = positions->Vpositioncadrecible.x+surfaces->Pcadrecible->w/2-surfaces->Pnomcible->w/2; + positions->Vpositionnomcible.y = positions->Vpositioncadrecible.y + 10; + Fblitteractivedesactive (surfaces,positions,ennemis,selection); + Fblitterpvcible (surfaces,positions,ennemis,selection); + Fblitterpmcible (surfaces,positions,ennemis,selection); + SDL_BlitSurface (surfaces->Pnomcible,NULL,surfaces->Pecran,&positions->Vpositionnomcible); + SDL_Flip (surfaces->Pecran); + TTF_CloseFont(police); +} + +void Fchangercurseurpersos (SURFACES *surfaces, POSITIONS *positions,int selection,PERSONNAGES persos[]) +{ + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); + SDL_Flip (surfaces->Pecran); + SELECTION (0,ALLIE) + SELECTION (1,ALLIE) + SELECTION (2,ALLIE) + SELECTION (3,ALLIE) + SELECTION (4,ALLIE) + SDL_Flip (surfaces->Pecran); +} + +void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions,int type,OBJET *objets) +{ + int i; + TTF_Font *police=NULL; + SDL_Color couleur={0,0,0,0}; + char chaine[3][50]; + police=TTF_OpenFont ("C://Windows//Fonts//TIMESBI.TTF",20); + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); + SDL_BlitSurface (surfaces->Pcadreactions,NULL,surfaces->Pecran,&positions->Vpositioncadreactions); + for(i=0;iPactionselectionnee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[selection-page*3]); + } + for(i=0;i<3;i++) + { + if(surfaces->Pnomactions[i]!=NULL) + { + SDL_FreeSurface(surfaces->Pnomactions[i]); + surfaces->Pnomactions[i]=NULL; + } + } + if(type==ACTIONS) + { + if(page==0) + { + ECRIRE("ATTAQUE",0); + ECRIRE("MAGIE BLANCHE",1); + ECRIRE("MAGIE NOIRE",2); + } + else if(page==1) + { + ECRIRE("TECHNIQUES",0); + ECRIRE("OBJETS",1); + } + } + else if(type==MAGIE_BLANCHE) + { + if (page==0) + { + ECRIRE("SOIN",0); + } + } + else if(type==MAGIE_NOIRE) + { + if(page==0) + { + ECRIRE("FEU",0); + ECRIRE("GLACE",1); + ECRIRE("EAU",2); + } + else if(page==1) + { + ECRIRE("TONNERRE",0); + ECRIRE("CHOC",1); + } + } + else if(type==OBJETS) + { + if(page==0) + { + ECRIRE("POTION",0); + ECRIRE("ETHER",1); + ECRIRE("POTION +",2); + sprintf(chaine[0],"%d",objets->potions); + surfaces->Pquantite[0]=TTF_RenderText_Blended(police,chaine[0],couleur); + sprintf(chaine[1],"%d",objets->ethers); + surfaces->Pquantite[1]=TTF_RenderText_Blended(police,chaine[1],couleur); + sprintf(chaine[2],"%d",objets->potionsplus); + surfaces->Pquantite[2]=TTF_RenderText_Blended(police,chaine[2],couleur); + SDL_BlitSurface(surfaces->Pquantite[0],NULL,surfaces->Pecran,&positions->Vpositionquantite[0]); + SDL_BlitSurface(surfaces->Pquantite[1],NULL,surfaces->Pecran,&positions->Vpositionquantite[1]); + SDL_BlitSurface(surfaces->Pquantite[2],NULL,surfaces->Pecran,&positions->Vpositionquantite[2]); + } + else if(page==1) + { + ECRIRE("ETHER +",0); + sprintf(chaine[0],"%d",objets->ethersplus); + surfaces->Pquantite[0]=TTF_RenderText_Blended(police,chaine[0],couleur); + SDL_BlitSurface(surfaces->Pquantite[0],NULL,surfaces->Pecran,&positions->Vpositionquantite[0]); + } + } + if (page==nbactions/3) + { + if(3*(page+1)-nbactions==1) + SDL_BlitSurface (surfaces->Pactiondesactivee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[2]); + if(3*(page+1)-nbactions==2) + { + SDL_BlitSurface (surfaces->Pactiondesactivee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[2]); + SDL_BlitSurface (surfaces->Pactiondesactivee,NULL,surfaces->Pecran,&positions->Vpositionactionselectionnee[1]); + } + } + SDL_Flip(surfaces->Pecran); + TTF_CloseFont (police); +} + +void Fafficherdegats (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible,PERSONNAGES persos[]) +{ + char chaine[10]; + TTF_Font *police = NULL; + SDL_Color fg = {210,0,0,0}; + if(surfaces->Pnbdegats != NULL) + { + SDL_FreeSurface (surfaces->Pnbdegats); + surfaces->Pnbdegats=NULL; + } + sprintf (chaine,"%d ", degats); + police = TTF_OpenFont ("C://Windows//Fonts//TIMES.TTF", 30 +); + TTF_SetFontStyle(police,TTF_STYLE_BOLD); + surfaces->Pnbdegats = TTF_RenderText_Blended(police,chaine,fg); + if(clan==ENNEMI) + { + positions->Vpositiondegats.x=positions->Vpositionennemis[cible].x-30-surfaces->Pnbdegats->w; + positions->Vpositiondegats.y=positions->Vpositionennemis[cible].y+surfaces->Tennemi[cible]->h/2-surfaces->Pnbdegats->h/2; + } + else + { + positions->Vpositiondegats.x=positions->Vpositionpersos[cible].x+surfaces->Tperso[cible]->w+30; + positions->Vpositiondegats.y=positions->Vpositionpersos[cible].y+surfaces->Tperso[cible]->h/2-surfaces->Pnbdegats->h/2; + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositionpvpersos[cible],surfaces->Pecran,&positions->Vpositionpvpersos[cible]); + Fblitterpersos(surfaces,positions,persos); + } + positions->Vpositiondegats.w=surfaces->Pnbdegats->w; + positions->Vpositiondegats.h=surfaces->Pnbdegats->h; + SDL_BlitSurface (surfaces->Pnbdegats,NULL,surfaces->Pecran,&positions->Vpositiondegats); + SDL_Flip (surfaces->Pecran); + TTF_CloseFont (police); +} + +void Faffichersoins (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible,PERSONNAGES persos[]) +{ + char chaine[10]; + TTF_Font *police = NULL; + SDL_Color fg = {80,255,80,0}; + + if (surfaces->Pnbdegats != NULL) + { + SDL_FreeSurface (surfaces->Pnbdegats); + surfaces->Pnbdegats=NULL; + } + sprintf (chaine,"%d", degats); + police = TTF_OpenFont ("C://Windows//Fonts//TIMES.TTF", 30); + TTF_SetFontStyle(police,TTF_STYLE_BOLD); + surfaces->Pnbdegats = TTF_RenderText_Blended (police,chaine,fg); + if(clan==ENNEMI) + { + positions->Vpositiondegats.x=positions->Vpositionennemis[cible].x-30-surfaces->Pnbdegats->w; + positions->Vpositiondegats.y=positions->Vpositionennemis[cible].y+surfaces->Tennemi[cible]->h/2-surfaces->Pnbdegats->h/2; + } + else + { + positions->Vpositiondegats.x=positions->Vpositionpersos[cible].x+surfaces->Tperso[cible]->w+30; + positions->Vpositiondegats.y=positions->Vpositionpersos[cible].y+surfaces->Tperso[cible]->h/2-surfaces->Pnbdegats->h/2; + + } + positions->Vpositiondegats.w=surfaces->Pnbdegats->w; + positions->Vpositiondegats.h=surfaces->Pnbdegats->h; + SDL_BlitSurface (surfaces->Pnbdegats,NULL,surfaces->Pecran,&positions->Vpositiondegats); + SDL_Flip (surfaces->Pecran); + + TTF_CloseFont (police); +} + +void Fblitteractivedesactive (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection) +{ + int i; + + for (i=0;i<4;i++) + { + if(ennemis[selection].sensibilite[i] == ACTIVE) + SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i]); + else + SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i]); + } + for (i=0;i<4;i++) + { + if(ennemis[selection].resistance[i] == ACTIVE) + SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+4]); + else + SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+4]); + } + for(i=0;i<4;i++) + { + if (ennemis[selection].invulnerabilite[i] == ACTIVE) + SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+8]); + else + SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+8]); + } + for (i=0;i<4;i++) + { + if (ennemis[selection].absorbtion[i] == ACTIVE) + SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+12]); + else + SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i+12]); + } +} + +void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection) +{ + TTF_Font *police = NULL; + SDL_Color couleur = {132,215,107,0}; + char chaine[50]; + + if (surfaces->Ppvcible != NULL) + { + SDL_FreeSurface (surfaces->Ppvcible); + surfaces->Ppvcible=NULL; + } + if (ennemis[selection].pv<0) + ennemis[selection].pv=0; + sprintf (chaine,"%d/%d",ennemis[selection].pv,ennemis[selection].pvinitiaux); + police=TTF_OpenFont ("C://Windows//Fonts//TIMESBI.TTF",18); + surfaces->Ppvcible=TTF_RenderText_Blended (police,chaine,couleur); + SDL_BlitSurface (surfaces->Ppvcible,NULL,surfaces->Pecran,&positions->Vpositionpvcible); + TTF_CloseFont (police); +} + +void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection) +{ + TTF_Font *police = NULL; + SDL_Color couleur = {132,215,107,0}; + char chaine[50]; + + if (surfaces->Ppmcible != NULL) + { + SDL_FreeSurface (surfaces->Ppmcible); + surfaces->Ppvcible=NULL; + } + sprintf (chaine,"%d/%d",ennemis[selection].pm,ennemis[selection].pminitiaux); + police=TTF_OpenFont ("C://Windows//Fonts//TIMESBI.TTF",18); + surfaces->Ppmcible=TTF_RenderText_Blended (police,chaine,couleur); + SDL_BlitSurface (surfaces->Ppmcible,NULL,surfaces->Pecran,&positions->Vpositionpmcible); + TTF_CloseFont (police); +} + +void Fblitterpmpvpersos(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int selection) +{ + TTF_Font *police=NULL; + SDL_Color fg={132,215,107,0},bg={100,0,0,0}; + char chaine[2][50]; + police=TTF_OpenFont("C://WINDOWS//Fonts//TIMESBI.TTF",18); + sprintf(chaine[0],"PV %d/%d ",persos[selection].pv,persos[selection].pvinitiaux); + surfaces->Ppvpersos=TTF_RenderText_Shaded(police,chaine[0],fg,bg); + sprintf(chaine[1],"PM %d/%d ",persos[selection].pm,persos[selection].pminitiaux); + surfaces->Ppmpersos=TTF_RenderText_Shaded(police,chaine[1],fg,bg); + positions->Vpositionpvpersos[selection].x=(positions->Vpositionpersos[selection].x+surfaces->Tperso[selection]->w/2-surfaces->Ppvpersos->w/2); + positions->Vpositionpmpersos[selection].x=(positions->Vpositionpersos[selection].x+surfaces->Tperso[selection]->w/2-surfaces->Ppmpersos->w/2); + positions->Vpositionpvpersos[selection].y=(positions->Vpositionpersos[selection].y+surfaces->Tperso[selection]->h-surfaces->Ppvpersos->h-surfaces->Ppmpersos->h); + positions->Vpositionpmpersos[selection].y=(positions->Vpositionpersos[selection].y+surfaces->Tperso[selection]->h-surfaces->Ppmpersos->h); + SDL_BlitSurface(surfaces->Ppvpersos,NULL,surfaces->Pecran,&positions->Vpositionpvpersos[selection]); + SDL_BlitSurface(surfaces->Ppmpersos,NULL,surfaces->Pecran,&positions->Vpositionpmpersos[selection]); + positions->Vpositionpvpersos[selection].w=surfaces->Ppvpersos->w; + positions->Vpositionpvpersos[selection].h=surfaces->Ppvpersos->h; + positions->Vpositionpmpersos[selection].w=surfaces->Ppmpersos->w; + positions->Vpositionpmpersos[selection].h=surfaces->Ppmpersos->h; + + TTF_CloseFont(police); +} + +void Fblitterfond(SURFACES* surfaces) +{ + SDL_Rect position; + position.x=0; + position.y=0; + surfaces->Pfondjeu=IMG_Load("images/jeu/textures/background.jpg"); + SDL_BlitSurface(surfaces->Pfondjeu,NULL,surfaces->Pecran,&position); + SDL_Flip(surfaces->Pecran); +} + +void Fcolourselection(SURFACES* surfaces, PERSONNAGES persos[],int Vtourallie,POSITIONS* positions) +{ + int x=0; + int i; + int y=0; + int tampon; + Uint32 pixel; + Uint8 r,g,b,a; + int ajout=30; + for(i=0;i<3;i++) + { + tampon=0; + SDL_LockSurface(surfaces->Tperso[i]); + for(y=0;yTperso[i]->h;y++) + { + for(x=0;xTperso[i]->w;x++) + { + pixel=obtenirPixel(surfaces->Tperso[i],x,y); + SDL_GetRGBA(pixel,surfaces->Pecran->format,&r,&g,&b,&a); + tampon=(int)r+ajout; + if(tampon>255) + tampon=255; + else if(tampon<0) + tampon=0; + r=(Uint8)tampon; + pixel=SDL_MapRGBA(surfaces->Pecran->format,r,g,b,a); + definirPixel(surfaces->Tperso[i],x,y,pixel); + } + } + SDL_UnlockSurface(surfaces->Tperso[i]); + SDL_SetColorKey(surfaces->Tperso[i],SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,r,g,b)); + } + SDL_Flip(surfaces->Pecran); + +} + +void Fblitcoloredselection (SURFACES surfaces[],POSITIONS positions[],int Vtourallie,PERSONNAGES persos[]) +{ + SDL_BlitSurface(surfaces->Tperso[Vtourallie],NULL,surfaces->Pecran,&positions->Vpositionpersos[Vtourallie]); + Fblitterpmpvpersos(surfaces,positions,persos,Vtourallie); + SDL_Flip(surfaces->Pecran); +} + + + + + + diff --git a/competences.c b/competences.c index 5d97b4a..e25acf1 100644 --- a/competences.c +++ b/competences.c @@ -1,120 +1,120 @@ -#include -#include -#include -#include "structures.h" -#include "constantes.h" -#include "prototypes.h" - -void Fremplircompetencesennemis (ENNEMIS ennemis[],int Vnbennemis) -{ - int i, y; - unsigned int sensibilite; - unsigned int max = 8, min = 0; - - for (i=0;i<=Vnbennemis;i++) - { - if(ennemis[i].classe==GUERRIER_GOBELIN) - { - ennemis[i].force = 15; - ennemis[i].magie = 0; - ennemis[i].defense = 10; - ennemis[i].defensemagique = 5; - ennemis[i].pv = 1000; - ennemis[i].pm = 0; - ennemis[i].pminitiaux = 0; - ennemis[i].pvinitiaux = 1000; - ennemis[i].etat = VIE; - for (y=0;y<4;y++) - { - sensibilite = (rand() % (max - min + 1)) + min; - if (sensibilite == SENSIBILITE) - { - ennemis[i].sensibilite[y] = ACTIVE; - ennemis[i].resistance[y] = DESACTIVE; - ennemis[i].invulnerabilite[y] = DESACTIVE; - ennemis[i].absorbtion[y] = DESACTIVE; - } - else if (sensibilite == RESISTANCE) - { - ennemis[i].resistance[y] = ACTIVE; - ennemis[i].sensibilite[y] = DESACTIVE; - ennemis[i].invulnerabilite[y] = DESACTIVE; - ennemis[i].absorbtion[y] = DESACTIVE; - } - else if (sensibilite == INVULNERABILITE) - { - ennemis[i].resistance[y] = DESACTIVE; - ennemis[i].sensibilite[y] = DESACTIVE; - ennemis[i].invulnerabilite[y] = ACTIVE; - ennemis[i].absorbtion[y] = DESACTIVE; - } - else if (sensibilite == ABSORBTION) - { - ennemis[i].sensibilite[y] = DESACTIVE; - ennemis[i].resistance[y] = DESACTIVE; - ennemis[i].invulnerabilite[y] = DESACTIVE; - ennemis[i].absorbtion[y] = ACTIVE; - } - else - { - ennemis[i].sensibilite[y] = DESACTIVE; - ennemis[i].resistance[y] = DESACTIVE; - ennemis[i].invulnerabilite[y] = DESACTIVE; - ennemis[i].absorbtion[y] = DESACTIVE; - } - } - } - } -} - -void Fremplircompetencesallie (PERSONNAGES persos[]) -{ - int i; - - for(i=0;i<3;i++) - { - if(persos[i].classe==PALADIN) - { - persos[i].xp = 0; - persos[i].nv = 0; - persos[i].force = 20; - persos[i].magie = 5; - persos[i].defense = 15; - persos[i].defensemagique = 10; - persos[i].pv = 1500; - persos[i].pvinitiaux = 1500; - persos[i].pminitiaux = 40; - persos[i].pm = 40; - persos[i].etat = VIE; - } - else if (persos[i].classe == PRETRE) - { - persos[i].xp = 0; - persos[i].nv = 0; - persos[i].force = 5; - persos[i].magie = 20; - persos[i].defense = 10; - persos[i].defensemagique = 20; - persos[i].pv = 1000; - persos[i].pvinitiaux = 1000; - persos[i].pminitiaux = 40; - persos[i].pm = 40; - persos[i].etat = VIE; - } - else if (persos[i].classe == VOLEUR) - { - persos[i].xp = 0; - persos[i].nv = 0; - persos[i].force = 14; - persos[i].magie = 11; - persos[i].defense = 15; - persos[i].defensemagique = 15; - persos[i].pv = 1250; - persos[i].pvinitiaux = 1250; - persos[i].pminitiaux = 40; - persos[i].pm = 40; - persos[i].etat = VIE; - } - } -} - +#include +#include +#include +#include "structures.h" +#include "constantes.h" +#include "prototypes.h" + +void Fremplircompetencesennemis (ENNEMIS ennemis[],int Vnbennemis) +{ + int i, y; + unsigned int sensibilite; + unsigned int max = 8, min = 0; + + for (i=0;i<=Vnbennemis;i++) + { + if(ennemis[i].classe==GUERRIER_GOBELIN) + { + ennemis[i].force = 15; + ennemis[i].magie = 0; + ennemis[i].defense = 10; + ennemis[i].defensemagique = 5; + ennemis[i].pv = 1000; + ennemis[i].pm = 0; + ennemis[i].pminitiaux = 0; + ennemis[i].pvinitiaux = 1000; + ennemis[i].etat = VIE; + for (y=0;y<4;y++) + { + sensibilite = (rand() % (max - min + 1)) + min; + if (sensibilite == SENSIBILITE) + { + ennemis[i].sensibilite[y] = ACTIVE; + ennemis[i].resistance[y] = DESACTIVE; + ennemis[i].invulnerabilite[y] = DESACTIVE; + ennemis[i].absorbtion[y] = DESACTIVE; + } + else if (sensibilite == RESISTANCE) + { + ennemis[i].resistance[y] = ACTIVE; + ennemis[i].sensibilite[y] = DESACTIVE; + ennemis[i].invulnerabilite[y] = DESACTIVE; + ennemis[i].absorbtion[y] = DESACTIVE; + } + else if (sensibilite == INVULNERABILITE) + { + ennemis[i].resistance[y] = DESACTIVE; + ennemis[i].sensibilite[y] = DESACTIVE; + ennemis[i].invulnerabilite[y] = ACTIVE; + ennemis[i].absorbtion[y] = DESACTIVE; + } + else if (sensibilite == ABSORBTION) + { + ennemis[i].sensibilite[y] = DESACTIVE; + ennemis[i].resistance[y] = DESACTIVE; + ennemis[i].invulnerabilite[y] = DESACTIVE; + ennemis[i].absorbtion[y] = ACTIVE; + } + else + { + ennemis[i].sensibilite[y] = DESACTIVE; + ennemis[i].resistance[y] = DESACTIVE; + ennemis[i].invulnerabilite[y] = DESACTIVE; + ennemis[i].absorbtion[y] = DESACTIVE; + } + } + } + } +} + +void Fremplircompetencesallie (PERSONNAGES persos[]) +{ + int i; + + for(i=0;i<3;i++) + { + if(persos[i].classe==PALADIN) + { + persos[i].xp = 0; + persos[i].nv = 0; + persos[i].force = 20; + persos[i].magie = 5; + persos[i].defense = 15; + persos[i].defensemagique = 10; + persos[i].pv = 1500; + persos[i].pvinitiaux = 1500; + persos[i].pminitiaux = 40; + persos[i].pm = 40; + persos[i].etat = VIE; + } + else if (persos[i].classe == PRETRE) + { + persos[i].xp = 0; + persos[i].nv = 0; + persos[i].force = 5; + persos[i].magie = 20; + persos[i].defense = 10; + persos[i].defensemagique = 20; + persos[i].pv = 1000; + persos[i].pvinitiaux = 1000; + persos[i].pminitiaux = 40; + persos[i].pm = 40; + persos[i].etat = VIE; + } + else if (persos[i].classe == VOLEUR) + { + persos[i].xp = 0; + persos[i].nv = 0; + persos[i].force = 14; + persos[i].magie = 11; + persos[i].defense = 15; + persos[i].defensemagique = 15; + persos[i].pv = 1250; + persos[i].pvinitiaux = 1250; + persos[i].pminitiaux = 40; + persos[i].pm = 40; + persos[i].etat = VIE; + } + } +} + diff --git a/constantes.h b/constantes.h index 9607c66..415074b 100644 --- a/constantes.h +++ b/constantes.h @@ -1,169 +1,169 @@ -#ifndef CONSTANTES_H -#define CONSTANTES_H -#define JOUER 0 -#define OPTIONS 1 -#define QUITTER 2 -#define XWIN 1024 -#define YWIN 768 -#define PALADIN 0 -#define PRETRE 1 -#define VOLEUR 2 -#define GUERRIER_GOBELIN 10 -#define VIE 1 -#define MORT 0 - -//type de sort -#define FEU 0 -#define GLACE 1 -#define EAU 2 -#define TONNERRE 3 -#define CHOC 4 -#define NON_ELEMENTAIRE 4 -#define SOIN 0 - -//caractéristiques -#define SENSIBILITE 1 -#define RESISTANCE 2 -#define INVULNERABILITE 3 -#define ABSORBTION 4 - -//active / desactivé -#define ACTIVE 1 -#define DESACTIVE 0 - - -#define ATTAQUE 0 -#define MAGIE_BLANCHE 1 -#define MAGIE_NOIRE 2 -#define TECHNIQUES 3 -#define OBJETS 4 -#define POTION 0 -#define ETHER 1 -#define POTIONPLUS 2 -#define ETHERPLUS 3 -#define ACTIONS 5 -#define DEGATS 0 -#define SOINS 1 -#define ALLIE 1 -#define ENNEMI 0 -#define TYPE_ATTAQUE 0 -#define TYPE_MAGIE 1 - - -#define SELECTION(nb,nb2) if (selection == nb)\ - {\ - if(nb2==ALLIE)\ - {\ - positions->Vpositioncurseurallies.x = positions->Vpositionpersos[nb].x + 20 + surfaces->Tperso[nb]->w;\ - positions->Vpositioncurseurallies.y = positions->Vpositionpersos[nb].y + surfaces->Tperso[nb]->h/2 - surfaces->Pcurseurallies->h/2;\ - SDL_BlitSurface (surfaces->Pcurseurallies,NULL,surfaces->Pecran,&positions->Vpositioncurseurallies);\ - }\ - else\ - {\ - SDL_BlitSurface (surfaces->Pcadrecible,NULL,surfaces->Pecran,&positions->Vpositioncadrecible);\ - positions->Vpositioncurseurennemis.x=positions->Vpositionennemis[nb].x-20-surfaces->Pcurseurennemis->w;\ - positions->Vpositioncurseurennemis.y=positions->Vpositionennemis[nb].y+surfaces->Tennemi[nb]->h/2 - surfaces->Pcurseurennemis->h/2;\ - SDL_BlitSurface (surfaces->Pcurseurennemis,NULL,surfaces->Pecran,&positions->Vpositioncurseurennemis);\ - }\ - } -#define ECRIRE(texte,id)sprintf(chaine[id],texte);\ - surfaces->Pnomactions[id]=TTF_RenderText_Blended(police,chaine[id],couleur);\ - SDL_BlitSurface (surfaces->Pnomactions[id],NULL,surfaces->Pecran,&positions->Vpositionnomactions[id]); - -//map -#define SOL 0 -#define MUR 1 -#define COFFRE 2 -#define GUS 3 - - - -#define SELECTION_CIBLE() case SDLK_RIGHT:\ - if(clan==ALLIE)\ - {\ - selection=0;\ - while(ennemis[selection].etat==MORT)\ - selection++;\ - inverse(&clan);\ - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);\ - Fchangercurseurennemis (surfaces,positions,selection,ennemis);\ - }\ - break;\ - case SDLK_LEFT:\ - if(clan==ENNEMI)\ - {\ - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);\ - selection=0;\ - while(persos[selection].etat==MORT)\ - selection++;\ - inverse(&clan);\ - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);\ - Fchangercurseurpersos(surfaces,positions,selection,persos);\ - }\ - break;\ - case SDLK_UP:\ - if(clan==ENNEMI)\ - {\ - if (selection!=0)\ - selection--;\ - else\ - selection=Vnbennemis;\ - while(ennemis[selection].etat==MORT)\ - {\ - if(selection!=0)\ - selection--;\ - else\ - selection=Vnbennemis;\ - }\ - Fchangercurseurennemis (surfaces,positions,selection,ennemis);\ - }\ - else\ - {\ - if (selection!=0)\ - selection--;\ - else\ - selection=2;\ - while(persos[selection].etat==MORT)\ - {\ - if(selection!=0)\ - selection--;\ - else\ - selection=2;\ - }\ - Fchangercurseurpersos(surfaces,positions,selection,ennemis);\ - }\ - break;\ - case SDLK_DOWN:\ - if(clan==ENNEMI)\ - {\ - if(selection!=Vnbennemis)\ - selection++;\ - else\ - selection=0;\ - while(ennemis[selection].etat==MORT)\ - {\ - if(selection!=Vnbennemis)\ - selection++;\ - else\ - selection=0;\ - }\ - Fchangercurseurennemis(surfaces,positions,selection,ennemis);\ - }\ - else\ - {\ - if(selection!=2)\ - selection++;\ - else\ - selection=0;\ - while(persos[selection].etat==MORT)\ - {\ - if(selection!=2)\ - selection++;\ - else\ - selection=0;\ - }\ - Fchangercurseurpersos(surfaces,positions,selection,ennemis);\ - }\ - break; - -#endif +#ifndef CONSTANTES_H +#define CONSTANTES_H +#define JOUER 0 +#define OPTIONS 1 +#define QUITTER 2 +#define XWIN 1024 +#define YWIN 768 +#define PALADIN 0 +#define PRETRE 1 +#define VOLEUR 2 +#define GUERRIER_GOBELIN 10 +#define VIE 1 +#define MORT 0 + +//type de sort +#define FEU 0 +#define GLACE 1 +#define EAU 2 +#define TONNERRE 3 +#define CHOC 4 +#define NON_ELEMENTAIRE 4 +#define SOIN 0 + +//caractéristiques +#define SENSIBILITE 1 +#define RESISTANCE 2 +#define INVULNERABILITE 3 +#define ABSORBTION 4 + +//active / desactivé +#define ACTIVE 1 +#define DESACTIVE 0 + + +#define ATTAQUE 0 +#define MAGIE_BLANCHE 1 +#define MAGIE_NOIRE 2 +#define TECHNIQUES 3 +#define OBJETS 4 +#define POTION 0 +#define ETHER 1 +#define POTIONPLUS 2 +#define ETHERPLUS 3 +#define ACTIONS 5 +#define DEGATS 0 +#define SOINS 1 +#define ALLIE 1 +#define ENNEMI 0 +#define TYPE_ATTAQUE 0 +#define TYPE_MAGIE 1 + + +#define SELECTION(nb,nb2) if (selection == nb)\ + {\ + if(nb2==ALLIE)\ + {\ + positions->Vpositioncurseurallies.x = positions->Vpositionpersos[nb].x + 20 + surfaces->Tperso[nb]->w;\ + positions->Vpositioncurseurallies.y = positions->Vpositionpersos[nb].y + surfaces->Tperso[nb]->h/2 - surfaces->Pcurseurallies->h/2;\ + SDL_BlitSurface (surfaces->Pcurseurallies,NULL,surfaces->Pecran,&positions->Vpositioncurseurallies);\ + }\ + else\ + {\ + SDL_BlitSurface (surfaces->Pcadrecible,NULL,surfaces->Pecran,&positions->Vpositioncadrecible);\ + positions->Vpositioncurseurennemis.x=positions->Vpositionennemis[nb].x-20-surfaces->Pcurseurennemis->w;\ + positions->Vpositioncurseurennemis.y=positions->Vpositionennemis[nb].y+surfaces->Tennemi[nb]->h/2 - surfaces->Pcurseurennemis->h/2;\ + SDL_BlitSurface (surfaces->Pcurseurennemis,NULL,surfaces->Pecran,&positions->Vpositioncurseurennemis);\ + }\ + } +#define ECRIRE(texte,id)sprintf(chaine[id],texte);\ + surfaces->Pnomactions[id]=TTF_RenderText_Blended(police,chaine[id],couleur);\ + SDL_BlitSurface (surfaces->Pnomactions[id],NULL,surfaces->Pecran,&positions->Vpositionnomactions[id]); + +//map +#define SOL 0 +#define MUR 1 +#define COFFRE 2 +#define GUS 3 + + + +#define SELECTION_CIBLE() case SDLK_RIGHT:\ + if(clan==ALLIE)\ + {\ + selection=0;\ + while(ennemis[selection].etat==MORT)\ + selection++;\ + inverse(&clan);\ + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);\ + Fchangercurseurennemis (surfaces,positions,selection,ennemis);\ + }\ + break;\ + case SDLK_LEFT:\ + if(clan==ENNEMI)\ + {\ + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);\ + selection=0;\ + while(persos[selection].etat==MORT)\ + selection++;\ + inverse(&clan);\ + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);\ + Fchangercurseurpersos(surfaces,positions,selection,persos);\ + }\ + break;\ + case SDLK_UP:\ + if(clan==ENNEMI)\ + {\ + if (selection!=0)\ + selection--;\ + else\ + selection=Vnbennemis;\ + while(ennemis[selection].etat==MORT)\ + {\ + if(selection!=0)\ + selection--;\ + else\ + selection=Vnbennemis;\ + }\ + Fchangercurseurennemis (surfaces,positions,selection,ennemis);\ + }\ + else\ + {\ + if (selection!=0)\ + selection--;\ + else\ + selection=2;\ + while(persos[selection].etat==MORT)\ + {\ + if(selection!=0)\ + selection--;\ + else\ + selection=2;\ + }\ + Fchangercurseurpersos(surfaces,positions,selection,ennemis);\ + }\ + break;\ + case SDLK_DOWN:\ + if(clan==ENNEMI)\ + {\ + if(selection!=Vnbennemis)\ + selection++;\ + else\ + selection=0;\ + while(ennemis[selection].etat==MORT)\ + {\ + if(selection!=Vnbennemis)\ + selection++;\ + else\ + selection=0;\ + }\ + Fchangercurseurennemis(surfaces,positions,selection,ennemis);\ + }\ + else\ + {\ + if(selection!=2)\ + selection++;\ + else\ + selection=0;\ + while(persos[selection].etat==MORT)\ + {\ + if(selection!=2)\ + selection++;\ + else\ + selection=0;\ + }\ + Fchangercurseurpersos(surfaces,positions,selection,ennemis);\ + }\ + break; + +#endif diff --git a/ia.c b/ia.c index cfd0bce..5e74f3c 100644 --- a/ia.c +++ b/ia.c @@ -1,66 +1,66 @@ -#include -#include -#include -#include "constantes.h" -#include "structures.h" -#include "prototypes.h" -#include - -void Factionennemi(int* Vtourennemi,SURFACES* surfaces,POSITIONS* positions, ENNEMIS ennemis[], PERSONNAGES persos[],int Vnbennemis,int*Vtour,int Vtourallie) -{ - int target,degats; - - target=Fchoosetargetallie(persos); - degats=Fgeneratedegats(persos, ennemis,*Vtourennemi,target); - persos[target].pv=persos[target].pv-degats; - do - { - if(*VtourennemiVpositionmort.x=positions->Vpositionpersos[target].x+surfaces->Tperso[target]->w/2-surfaces->Pmort->w/2; - positions->Vpositionmort.y=positions->Vpositionpersos[target].y+surfaces->Tperso[target]->h/2-surfaces->Pmort->h/2; - SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); - } - Fafficherdegats(surfaces,positions,degats,ALLIE,target,persos); - SDL_Delay(1000); - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - if(*Vtour==ALLIE) - Fblitcoloredselection(surfaces,positions,Vtourallie,persos); - SDL_Flip(surfaces->Pecran); -} - -int Fchoosetargetallie(PERSONNAGES persos[]) -{ - int min=0,max=2,target; - - do - { - target=(rand()%(max-min+1)+min); - }while(persos[target].etat==MORT); - return target; -} - -int Fgeneratedegats(PERSONNAGES persos[],ENNEMIS ennemis[],int Vtourennemi,int target) -{ - int degats,taux,min,max; - - degats=ennemis[Vtourennemi].force*60-persos[target].defense*50; - taux=degats/4; - min=degats-taux; - max=degats+taux; - degats=(rand()%(max-min+1)+min); - if(degats<0) - degats=0; - - return degats; -} +#include +#include +#include +#include "constantes.h" +#include "structures.h" +#include "prototypes.h" +#include + +void Factionennemi(int* Vtourennemi,SURFACES* surfaces,POSITIONS* positions, ENNEMIS ennemis[], PERSONNAGES persos[],int Vnbennemis,int*Vtour,int Vtourallie) +{ + int target,degats; + + target=Fchoosetargetallie(persos); + degats=Fgeneratedegats(persos, ennemis,*Vtourennemi,target); + persos[target].pv=persos[target].pv-degats; + do + { + if(*VtourennemiVpositionmort.x=positions->Vpositionpersos[target].x+surfaces->Tperso[target]->w/2-surfaces->Pmort->w/2; + positions->Vpositionmort.y=positions->Vpositionpersos[target].y+surfaces->Tperso[target]->h/2-surfaces->Pmort->h/2; + SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort); + } + Fafficherdegats(surfaces,positions,degats,ALLIE,target,persos); + SDL_Delay(1000); + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); + if(*Vtour==ALLIE) + Fblitcoloredselection(surfaces,positions,Vtourallie,persos); + SDL_Flip(surfaces->Pecran); +} + +int Fchoosetargetallie(PERSONNAGES persos[]) +{ + int min=0,max=2,target; + + do + { + target=(rand()%(max-min+1)+min); + }while(persos[target].etat==MORT); + return target; +} + +int Fgeneratedegats(PERSONNAGES persos[],ENNEMIS ennemis[],int Vtourennemi,int target) +{ + int degats,taux,min,max; + + degats=ennemis[Vtourennemi].force*60-persos[target].defense*50; + taux=degats/4; + min=degats-taux; + max=degats+taux; + degats=(rand()%(max-min+1)+min); + if(degats<0) + degats=0; + + return degats; +} diff --git a/jouer.c b/jouer.c index 8ef1377..f1efab7 100644 --- a/jouer.c +++ b/jouer.c @@ -1,222 +1,222 @@ -#include -#include -#include -#include "structures.h" -#include "constantes.h" -#include "prototypes.h" - -int Fjouer (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[],ENNEMIS ennemis[]) -{ - OBJET objets; - unsigned int continuer=1; - int selection=0; - int i; - SDL_Event event; - int Vtourallie=0; - int Vtourennemi=0; - int Vtour; - int Vnbennemis=0; - int page=0; - int nbactions=5; - unsigned int gagne,perdu; - if(surfaces->Pfondjeu!=NULL) - { - SDL_FreeSurface(surfaces->Pfondjeu); - surfaces->Pfondjeu=NULL; - } - Finitialiserpositionspersos(surfaces,positions); - Fblitterfond(surfaces); // on blit le fond du jeu - Fremplirobjets(&objets); // on monte les variables potions ether, etc - Fremplircompetencesallie(persos); // on initialise les pv, pm, xp etc DES PERSOS - Vnbennemis=Fcalculernbennemis(); // on tire aléatoirement le nombre d'ennemis présents dans le combat - Fchoisirtypeennemis(persos,surfaces,ennemis,Vnbennemis); // on choisit la classe des ennemis comme guerrier gobelin etc - Fremplirennemis(surfaces,Vnbennemis,ennemis); - Fblitterpersos(surfaces,positions,persos); // on blit les persos sur l'ecran - Fblitterennemis(surfaces,positions,ennemis,Vnbennemis); // idem pour les ennemis - Fremplircompetencesennemis(ennemis,Vnbennemis); // on initialise les pv, pm, exp, etc DES ENNEMIS - Vtour=(rand()%(1-0+1)+0); // on détermine aléatoirement si c'est les ennemis ou les persos qui tapent en premier - Fcolourselection(surfaces,persos,Vtourallie,positions); // on créé les surfaces rouges (pour le tour) - if(Vtour==ALLIE) - Fblitcoloredselection(surfaces,positions,Vtourallie,persos); - while (continuer) - { - if(Vtour==ALLIE) //si un player joue - { - while (persos[Vtourallie].etat==MORT) //si le perso selectionné est mort - { - if(Vtourallie<2) // si ce n'est pas le dernier - Vtourallie++; // on prend le perso suivant - else // sinon si c'est le dernier - Vtourallie=0; // on reprend le 1er - } - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,ACTIONS,NULL); - SDL_WaitEvent(&event); - switch(event.type) - { - case SDL_KEYDOWN: - switch(event.key.keysym.unicode) - { - case SDLK_ESCAPE: - continuer=0; - break; - } - switch (event.key.keysym.sym) - { - case SDLK_UP: - if (selection!=0) - selection--; - else - selection=nbactions-1; - page=selection/3; - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,ACTIONS,NULL); - break; - case SDLK_DOWN: - if (selection!=nbactions-1) - selection++; - else - selection=0; - page=selection/3; - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,ACTIONS,NULL); - break; - case SDLK_RETURN: - if(selection==ATTAQUE) - Fattaquer(surfaces,positions,persos,&Vtourallie,ennemis,Vnbennemis,&Vtour); - else if(selection==MAGIE_BLANCHE) - Fselectionnermagieblanche (surfaces,positions,persos,&Vtourallie,ennemis,Vnbennemis,&Vtour); - else if(selection==MAGIE_NOIRE) - Fselectionnermagienoire (surfaces,positions,persos,&Vtourallie,ennemis,Vnbennemis,&Vtour); - else if(selection==TECHNIQUES){} - else if(selection==OBJETS) - Fselectionnerobjet(surfaces,positions,persos,&Vtourallie,ennemis,Vnbennemis,&objets,&Vtour); - break; - } - break; - } - } - else if(Vtour==ENNEMI) // sinon si c'est le cpu qui joue - { - while(ennemis[Vtourennemi].etat==MORT) - { - if(VtourennemiVpositionpersos[i].x=20; - positions->Vpositionpersos[1].y=YWIN/2-(surfaces->Tperso[1]->h/2); - positions->Vpositionpersos[0].y=positions->Vpositionpersos[1].y/2-surfaces->Tperso[0]->h/2; - positions->Vpositionpersos[2].y=YWIN-(20+surfaces->Tperso[2]->h); -} - -void Finitialiserpositionsennemis(SURFACES *surfaces,POSITIONS *positions,int Vnbennemis) -{ - if (Vnbennemis==0) - { - positions->Vpositionennemis[0].x=XWIN-20-surfaces->Tennemi[0]->w; - positions->Vpositionennemis[0].y=YWIN/2-surfaces->Tennemi[0]->h/2; - } - if (Vnbennemis==1) - { - positions->Vpositionennemis[0].x = XWIN - 20 - surfaces->Tennemi[0]->w; - positions->Vpositionennemis[0].y = YWIN/3 - surfaces->Tennemi[0]->h/2; - positions->Vpositionennemis[1].x = XWIN - 20 - surfaces->Tennemi[2]->w; - positions->Vpositionennemis[1].y = YWIN/3*2 - surfaces->Tennemi[1]->h/2; - } - else if (Vnbennemis==2) - { - positions->Vpositionennemis[1].x = XWIN - 20 - surfaces->Tennemi[1]->w; - positions->Vpositionennemis[1].y = YWIN/2 - surfaces->Tennemi[1]->h/2; - positions->Vpositionennemis[0].x = XWIN - 20 - surfaces->Tennemi[0]->w; - positions->Vpositionennemis[0].y = YWIN/4 - surfaces->Tennemi[1]->h/2; - positions->Vpositionennemis[2].x = XWIN - 20 - surfaces->Tennemi[2]->w; - positions->Vpositionennemis[2].y = YWIN/4*3 - surfaces->Tennemi[2]->h/2; - } - else if (Vnbennemis==3) - { - positions->Vpositionennemis[1].x = XWIN - 20 - surfaces->Tennemi[1]->w; - positions->Vpositionennemis[1].y = YWIN/5*2 - surfaces->Tennemi[1]->h/2; - positions->Vpositionennemis[2].x = XWIN - 20 - surfaces->Tennemi[2]->w; - positions->Vpositionennemis[2].y = YWIN/5*3 - surfaces->Tennemi[2]->h/2; - positions->Vpositionennemis[0].x = XWIN - surfaces->Tennemi[1]->w - surfaces->Tennemi[0]->w/2; - positions->Vpositionennemis[0].y = YWIN/5 -surfaces->Tennemi[0]->h/2; - positions->Vpositionennemis[3].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[3]->w/2; - positions->Vpositionennemis[3].y = YWIN/5*4 - surfaces->Tennemi[3]->h/2; - } - else if (Vnbennemis==4) - { - positions->Vpositionennemis[2].x = XWIN - 20 - surfaces->Tennemi[2]->w; - positions->Vpositionennemis[2].y = YWIN/2 - surfaces->Tennemi[2]->h/2; - positions->Vpositionennemis[1].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[1]->w/2; - positions->Vpositionennemis[1].y = YWIN/6*2 - surfaces->Tennemi[1]->h/2; - positions->Vpositionennemis[3].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[3]->w/2; - positions->Vpositionennemis[3].y = YWIN/6*4 - surfaces->Tennemi[3]->h/2; - positions->Vpositionennemis[0].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[1]->w - surfaces->Tennemi[0]->w/2; - positions->Vpositionennemis[0].y = YWIN/6 - surfaces->Tennemi[0]->h/2; - positions->Vpositionennemis[4].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[3]->w - surfaces->Tennemi[4]->w/2; - positions->Vpositionennemis[4].y = YWIN/6*5 - surfaces->Tennemi[4]->h/2; - } -} - -void Fremplirobjets(OBJET *objets) -{ - objets->potions=10; - objets->ethers=10; - objets->potionsplus=5; - objets->ethersplus=5; -} - - - - +#include +#include +#include +#include "structures.h" +#include "constantes.h" +#include "prototypes.h" + +int Fjouer (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[],ENNEMIS ennemis[]) +{ + OBJET objets; + unsigned int continuer=1; + int selection=0; + int i; + SDL_Event event; + int Vtourallie=0; + int Vtourennemi=0; + int Vtour; + int Vnbennemis=0; + int page=0; + int nbactions=5; + unsigned int gagne,perdu; + if(surfaces->Pfondjeu!=NULL) + { + SDL_FreeSurface(surfaces->Pfondjeu); + surfaces->Pfondjeu=NULL; + } + Finitialiserpositionspersos(surfaces,positions); + Fblitterfond(surfaces); // on blit le fond du jeu + Fremplirobjets(&objets); // on monte les variables potions ether, etc + Fremplircompetencesallie(persos); // on initialise les pv, pm, xp etc DES PERSOS + Vnbennemis=Fcalculernbennemis(); // on tire aléatoirement le nombre d'ennemis présents dans le combat + Fchoisirtypeennemis(persos,surfaces,ennemis,Vnbennemis); // on choisit la classe des ennemis comme guerrier gobelin etc + Fremplirennemis(surfaces,Vnbennemis,ennemis); + Fblitterpersos(surfaces,positions,persos); // on blit les persos sur l'ecran + Fblitterennemis(surfaces,positions,ennemis,Vnbennemis); // idem pour les ennemis + Fremplircompetencesennemis(ennemis,Vnbennemis); // on initialise les pv, pm, exp, etc DES ENNEMIS + Vtour=(rand()%(1-0+1)+0); // on détermine aléatoirement si c'est les ennemis ou les persos qui tapent en premier + Fcolourselection(surfaces,persos,Vtourallie,positions); // on créé les surfaces rouges (pour le tour) + if(Vtour==ALLIE) + Fblitcoloredselection(surfaces,positions,Vtourallie,persos); + while (continuer) + { + if(Vtour==ALLIE) //si un player joue + { + while (persos[Vtourallie].etat==MORT) //si le perso selectionné est mort + { + if(Vtourallie<2) // si ce n'est pas le dernier + Vtourallie++; // on prend le perso suivant + else // sinon si c'est le dernier + Vtourallie=0; // on reprend le 1er + } + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,ACTIONS,NULL); + SDL_WaitEvent(&event); + switch(event.type) + { + case SDL_KEYDOWN: + switch(event.key.keysym.unicode) + { + case SDLK_ESCAPE: + continuer=0; + break; + } + switch (event.key.keysym.sym) + { + case SDLK_UP: + if (selection!=0) + selection--; + else + selection=nbactions-1; + page=selection/3; + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,ACTIONS,NULL); + break; + case SDLK_DOWN: + if (selection!=nbactions-1) + selection++; + else + selection=0; + page=selection/3; + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,ACTIONS,NULL); + break; + case SDLK_RETURN: + if(selection==ATTAQUE) + Fattaquer(surfaces,positions,persos,&Vtourallie,ennemis,Vnbennemis,&Vtour); + else if(selection==MAGIE_BLANCHE) + Fselectionnermagieblanche (surfaces,positions,persos,&Vtourallie,ennemis,Vnbennemis,&Vtour); + else if(selection==MAGIE_NOIRE) + Fselectionnermagienoire (surfaces,positions,persos,&Vtourallie,ennemis,Vnbennemis,&Vtour); + else if(selection==TECHNIQUES){} + else if(selection==OBJETS) + Fselectionnerobjet(surfaces,positions,persos,&Vtourallie,ennemis,Vnbennemis,&objets,&Vtour); + break; + } + break; + } + } + else if(Vtour==ENNEMI) // sinon si c'est le cpu qui joue + { + while(ennemis[Vtourennemi].etat==MORT) + { + if(VtourennemiVpositionpersos[i].x=20; + positions->Vpositionpersos[1].y=YWIN/2-(surfaces->Tperso[1]->h/2); + positions->Vpositionpersos[0].y=positions->Vpositionpersos[1].y/2-surfaces->Tperso[0]->h/2; + positions->Vpositionpersos[2].y=YWIN-(20+surfaces->Tperso[2]->h); +} + +void Finitialiserpositionsennemis(SURFACES *surfaces,POSITIONS *positions,int Vnbennemis) +{ + if (Vnbennemis==0) + { + positions->Vpositionennemis[0].x=XWIN-20-surfaces->Tennemi[0]->w; + positions->Vpositionennemis[0].y=YWIN/2-surfaces->Tennemi[0]->h/2; + } + if (Vnbennemis==1) + { + positions->Vpositionennemis[0].x = XWIN - 20 - surfaces->Tennemi[0]->w; + positions->Vpositionennemis[0].y = YWIN/3 - surfaces->Tennemi[0]->h/2; + positions->Vpositionennemis[1].x = XWIN - 20 - surfaces->Tennemi[2]->w; + positions->Vpositionennemis[1].y = YWIN/3*2 - surfaces->Tennemi[1]->h/2; + } + else if (Vnbennemis==2) + { + positions->Vpositionennemis[1].x = XWIN - 20 - surfaces->Tennemi[1]->w; + positions->Vpositionennemis[1].y = YWIN/2 - surfaces->Tennemi[1]->h/2; + positions->Vpositionennemis[0].x = XWIN - 20 - surfaces->Tennemi[0]->w; + positions->Vpositionennemis[0].y = YWIN/4 - surfaces->Tennemi[1]->h/2; + positions->Vpositionennemis[2].x = XWIN - 20 - surfaces->Tennemi[2]->w; + positions->Vpositionennemis[2].y = YWIN/4*3 - surfaces->Tennemi[2]->h/2; + } + else if (Vnbennemis==3) + { + positions->Vpositionennemis[1].x = XWIN - 20 - surfaces->Tennemi[1]->w; + positions->Vpositionennemis[1].y = YWIN/5*2 - surfaces->Tennemi[1]->h/2; + positions->Vpositionennemis[2].x = XWIN - 20 - surfaces->Tennemi[2]->w; + positions->Vpositionennemis[2].y = YWIN/5*3 - surfaces->Tennemi[2]->h/2; + positions->Vpositionennemis[0].x = XWIN - surfaces->Tennemi[1]->w - surfaces->Tennemi[0]->w/2; + positions->Vpositionennemis[0].y = YWIN/5 -surfaces->Tennemi[0]->h/2; + positions->Vpositionennemis[3].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[3]->w/2; + positions->Vpositionennemis[3].y = YWIN/5*4 - surfaces->Tennemi[3]->h/2; + } + else if (Vnbennemis==4) + { + positions->Vpositionennemis[2].x = XWIN - 20 - surfaces->Tennemi[2]->w; + positions->Vpositionennemis[2].y = YWIN/2 - surfaces->Tennemi[2]->h/2; + positions->Vpositionennemis[1].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[1]->w/2; + positions->Vpositionennemis[1].y = YWIN/6*2 - surfaces->Tennemi[1]->h/2; + positions->Vpositionennemis[3].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[3]->w/2; + positions->Vpositionennemis[3].y = YWIN/6*4 - surfaces->Tennemi[3]->h/2; + positions->Vpositionennemis[0].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[1]->w - surfaces->Tennemi[0]->w/2; + positions->Vpositionennemis[0].y = YWIN/6 - surfaces->Tennemi[0]->h/2; + positions->Vpositionennemis[4].x = XWIN - surfaces->Tennemi[2]->w - surfaces->Tennemi[3]->w - surfaces->Tennemi[4]->w/2; + positions->Vpositionennemis[4].y = YWIN/6*5 - surfaces->Tennemi[4]->h/2; + } +} + +void Fremplirobjets(OBJET *objets) +{ + objets->potions=10; + objets->ethers=10; + objets->potionsplus=5; + objets->ethersplus=5; +} + + + + diff --git a/magies.c b/magies.c index 112506f..35d2b00 100644 --- a/magies.c +++ b/magies.c @@ -1,255 +1,255 @@ -#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: - 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 +#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: + 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; +} + + + + diff --git a/main.c b/main.c index 3406771..864e329 100644 --- a/main.c +++ b/main.c @@ -1,382 +1,350 @@ -/* ******************************************************************** - WARCRAFT BATTLE : Jeu au tour par tour similaire à Final Fantasy - développé entièrement par moi :p pour le plaisir^^ - Je sais c'est du beau quand même sa fait plaisir de faire un programme - assez complet avec pour seule aide un clavier et une souris (et encore là - j'ai pas de souris je programme sur pc portable xD) - Enfin bref voilà ma création :) - Fais en bon usage et bon jeu à toi ;) - -PS : Et surtout copyright :p pas touche à mon code pas de désassemblage ni rien -hein ;) MON PROGRAMME ! :o) - -@+++ amuse toi bien */ - - - -#include -#include -#include -#include "structures.h" -#include "constantes.h" -#include -#include -#include "prototypes.h" -#include - -int main (int argc, char *argv[]) -{ - srand (time(NULL)); - SURFACES surfaces; - POSITIONS positions; - Finitialisersurfaces (&surfaces); - if (SDL_Init (SDL_INIT_VIDEO) == -1) - { - fprintf(stderr, "Erreur lors de l'ouverture de la SDL : %s", SDL_GetError()); - exit (EXIT_FAILURE); - } - surfaces.Pecran = SDL_SetVideoMode (XWIN,YWIN,32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_NOFRAME|SDL_FULLSCREEN); - if (surfaces.Pecran == NULL) - { - fprintf(stderr,"Impossible de charger la mémoire vidéo : %s", SDL_GetError()); - exit (EXIT_FAILURE); - } - SDL_EnableUNICODE (1); - TTF_Init(); - SDL_WM_SetCaption ("WARCRAFT BATTLE",NULL); - SDL_ShowCursor(SDL_DISABLE); - Fchargerimages (&surfaces); - Finitialiserpositions (&positions,&surfaces); - Fmenuprincipal (&surfaces, &positions); - - - //une fois le jeu quitté - Fdechargerimages (&surfaces); - SDL_EnableUNICODE (0); - TTF_Quit(); - SDL_Quit(); - - - return 0; -} - -void Finitialisersurfaces (SURFACES *surfaces) -{ - int i; - surfaces->Pcurseurennemis=NULL; - surfaces->Pcurseurallies=NULL; - surfaces->Pchoixvoleur=NULL; - surfaces->Pchoixpretre=NULL; - surfaces->Pchoixpaladin=NULL; - surfaces->Pecran=NULL; - surfaces->Pgobelin=NULL; - surfaces->Ppaladin=NULL; - surfaces->Ppretre=NULL; - surfaces->Pvoleur=NULL; - surfaces->Pmenujouer=NULL; - surfaces->Pmenuoptions=NULL; - surfaces->Pmenuquitter=NULL; - surfaces->Pfondjeu=NULL; - surfaces->Ppvpersos=NULL; - surfaces->Ppmpersos=NULL; - for (i=0;i<3;i++) - surfaces->Tperso[i]=NULL; - for (i=0;i<5;i++) - surfaces->Tennemi[i]=NULL; - for (i=0;i<3;i++) - surfaces->Pnomactions[i]=NULL; - surfaces->Ptextechoixmenu=NULL; - surfaces->Pnbdegats=NULL; - surfaces->Pcadrecible=NULL; - surfaces->Pnomcible=NULL; - surfaces->Pactive=NULL; - surfaces->Pdesactive=NULL; - surfaces->Ppvcible=NULL; - surfaces->Ppmcible=NULL; - surfaces->Pcadreactions=NULL; - surfaces->Pactionselectionnee=NULL; - surfaces->Pactiondesactivee=NULL; - surfaces->Pmort=NULL; - for (i=0;i<3;i++) - surfaces->Pquantite[i]=NULL; -} - -void Finitialiserpositions (POSITIONS *positions, SURFACES *surfaces) -{ - int i,y=0,z=0; - positions->Vpositionmenu.x = 0; - positions->Vpositionmenu.y = 0; - positions->Vpositionmenupretre.x = XWIN/2 - surfaces->Ppretre->w/2; - positions->Vpositionmenupretre.y = YWIN - 20 - surfaces->Ppretre->h; - positions->Vpositionmenupaladin.x = positions->Vpositionmenupretre.x/2 - surfaces->Ppaladin->w/2; - positions->Vpositionmenupaladin.y = YWIN - 20 - surfaces->Ppaladin->h; - positions->Vpositionmenuvoleur.x = XWIN/4*3 - surfaces->Pvoleur->w/2; - positions->Vpositionmenuvoleur.y = YWIN - 20 - surfaces->Pvoleur->h; - positions->Vpositiontextemenu.y = 362; - positions->Vpositioncurseurennemis.x=1024; - positions->Vpositioncurseurennemis.y=768; - positions->Vpositioncurseurallies.x=1024; - positions->Vpositioncurseurallies.y=768; - positions->Vpositioncurseurennemis.w = surfaces->Pcurseurennemis->w; - positions->Vpositioncurseurennemis.h = surfaces->Pcurseurennemis->h; - positions->Vpositioncadrecible.y = 15; - positions->Vpositioncadrecible.x = XWIN/2-50-surfaces->Pcadrecible->w/2; - positions->Vpositioncadrecible.w = surfaces->Pcadrecible->w; - positions->Vpositioncadrecible.h = surfaces->Pcadrecible->h; - positions->Vpositioncadreactions.y = YWIN-surfaces->Pcadreactions->h; - positions->Vpositioncadreactions.x = XWIN/2-50-surfaces->Pcadreactions->w/2; - positions->Vpositioncadreactions.w = surfaces->Pcadreactions->w; - positions->Vpositioncadreactions.h = surfaces->Pcadreactions->h; - positions->Vpositionpvcible.x = 380; - positions->Vpositionpvcible.y = 185; - positions->Vpositionpmcible.x = 545; - positions->Vpositionpmcible.y = 185; - positions->Vpositiondegats.x=1024; - positions->Vpositiondegats.y=768; - for(i=0;i<3;i++) - { - positions->Vpositionactionselectionnee[i].x=positions->Vpositioncadreactions.x+5; - positions->Vpositionactionselectionnee[i].y=positions->Vpositioncadreactions.y+5+44*i; - positions->Vpositionnomactions[i].x=positions->Vpositioncadreactions.x+15; - positions->Vpositionnomactions[i].y=positions->Vpositioncadreactions.y+12+44*i; - positions->Vpositionquantite[i].y=positions->Vpositionnomactions[i].y; - positions->Vpositionquantite[i].x=positions->Vpositioncadreactions.x+surfaces->Pcadreactions->w-45; - } - for (i=0;i < 16;i++) - { - positions->Vpositionactivedesactive[i].x = 471+51*y; - positions->Vpositionactivedesactive[i].y = 101+19*z; - if (y < 3) - y++; - else - { - y=0; - z++; - } - } -} - -void Fchargerimages (SURFACES *surfaces) -{ - int i; - surfaces->Pgobelin = IMG_Load ("images/gobelin.bmp"); - surfaces->Ppaladin = IMG_Load ("images/paladin.bmp"); - surfaces->Ppretre = IMG_Load ("images/prêtre.bmp"); - surfaces->Pvoleur = IMG_Load ("images/voleur.bmp"); - surfaces->Pmenujouer = IMG_Load ("images/menu_principal/jouer.bmp"); - surfaces->Pmenuoptions = IMG_Load ("images/menu_principal/options.bmp"); - surfaces->Pmenuquitter = IMG_Load ("images/menu_principal/quitter.bmp"); - surfaces->Pchoixvoleur = IMG_Load ("images/menu_choix_classe/voleur.bmp"); - surfaces->Pchoixpretre = IMG_Load ("images/menu_choix_classe/pretre.bmp"); - surfaces->Pchoixpaladin = IMG_Load ("images/menu_choix_classe/paladin.bmp"); - surfaces->Pcurseurennemis = IMG_Load ("images/jeu/curseur.bmp"); - surfaces->Pcurseurallies = IMG_Load ("images/jeu/curseurpersos.bmp"); - surfaces->Pcadrecible = IMG_Load ("images/jeu/cadre_cible.bmp"); - surfaces->Pactive = IMG_Load ("images/jeu/active.bmp"); - surfaces->Pdesactive = IMG_Load ("images/jeu/desactive.bmp"); - surfaces->Pcadreactions = IMG_Load ("images/jeu/cadre_actions.bmp"); - surfaces->Pactionselectionnee=IMG_Load ("images/jeu/cadre_actions_select.bmp"); - surfaces->Pactiondesactivee=IMG_Load("images/jeu/cadre_actions_unactive.bmp"); - surfaces->Pmort=IMG_Load("images/jeu/mort.bmp"); - for (i = 0;i < 5;i++) - surfaces->Tennemi[i] = surfaces->Pgobelin; - - //définition de la transparence alpha dans les surfaces - SDL_SetColorKey(surfaces->Pgobelin,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,0,255,18)); - SDL_SetColorKey(surfaces->Ppretre,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,39,189,31)); - SDL_SetColorKey(surfaces->Ppaladin,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,189,31,31)); - SDL_SetColorKey(surfaces->Pvoleur,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,39,189,31)); - SDL_SetColorKey(surfaces->Pcurseurennemis,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); - SDL_SetColorKey(surfaces->Pcurseurallies,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); - SDL_SetColorKey(surfaces->Pactive,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); - SDL_SetColorKey(surfaces->Pdesactive,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); - SDL_SetColorKey(surfaces->Pmort,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); -} - -void Fdechargerimages (SURFACES *surfaces)//dechargement des surfaces alouées -{ - int i; - if(surfaces->Pecran!=NULL) - SDL_FreeSurface(surfaces->Pecran); - if(surfaces->Pgobelin!=NULL) - SDL_FreeSurface (surfaces->Pgobelin); - if(surfaces->Ppaladin!=NULL) - SDL_FreeSurface (surfaces->Ppaladin); - if(surfaces->Ppretre!=NULL) - SDL_FreeSurface (surfaces->Ppretre); - if(surfaces->Pvoleur!=NULL) - SDL_FreeSurface (surfaces->Pvoleur); - if(surfaces->Pmenujouer!=NULL) - SDL_FreeSurface (surfaces->Pmenujouer); - if(surfaces->Pmenuoptions!=NULL) - SDL_FreeSurface (surfaces->Pmenuoptions); - if(surfaces->Pmenuquitter!=NULL) - SDL_FreeSurface (surfaces->Pmenuquitter); - if(surfaces->Pchoixpretre!=NULL) - SDL_FreeSurface (surfaces->Pchoixpretre); - if(surfaces->Ppaladin!=NULL) - SDL_FreeSurface (surfaces->Pchoixpaladin); - if(surfaces->Pvoleur!=NULL) - SDL_FreeSurface (surfaces->Pchoixvoleur); - if(surfaces->Pcurseurennemis!=NULL) - SDL_FreeSurface (surfaces->Pcurseurennemis); - if(surfaces->Pcurseurallies!=NULL) - SDL_FreeSurface (surfaces->Pcurseurallies); - if(surfaces->Pcadrecible!=NULL) - SDL_FreeSurface (surfaces->Pcadrecible); - if(surfaces->Pactive!=NULL) - SDL_FreeSurface (surfaces->Pactive); - if(surfaces->Pdesactive!=NULL) - SDL_FreeSurface (surfaces->Pdesactive); - if(surfaces->Pcadreactions!=NULL) - SDL_FreeSurface (surfaces->Pcadreactions); - if(surfaces->Pactionselectionnee!=NULL) - SDL_FreeSurface (surfaces->Pactionselectionnee); - if(surfaces->Pactionselectionnee!=NULL) - SDL_FreeSurface (surfaces->Pactiondesactivee); - if(surfaces->Pmort!=NULL) - SDL_FreeSurface (surfaces->Pmort); - if(surfaces->Pfondjeu != NULL) - SDL_FreeSurface (surfaces->Pfondjeu); - if(surfaces->Ptextechoixmenu!=NULL) - SDL_FreeSurface(surfaces->Ptextechoixmenu); - if(surfaces->Pnbdegats!=NULL) - SDL_FreeSurface(surfaces->Pnbdegats); - if(surfaces->Pnomcible!=NULL) - SDL_FreeSurface(surfaces->Pnomcible); - if(surfaces->Ppvcible!=NULL) - SDL_FreeSurface(surfaces->Ppvcible); - if(surfaces->Ppmcible!=NULL) - SDL_FreeSurface(surfaces->Ppmcible); - if(surfaces->Ppvpersos!=NULL) - SDL_FreeSurface(surfaces->Ppvpersos); - if(surfaces->Ppmpersos!=NULL) - SDL_FreeSurface(surfaces->Ppmpersos); - for(i = 0;i < 3;i++) - { - if(surfaces->Tperso[i]!=NULL) - SDL_FreeSurface(surfaces->Tperso[i]); - } - for(i=0;i<5;i++) - { - if(surfaces->Tennemi[i]!=NULL) - SDL_FreeSurface(surfaces->Tennemi[i]); - } - for(i=0;i<3;i++) - { - if(surfaces->Pnomactions[i]!=NULL) - SDL_FreeSurface (surfaces->Pnomactions[i]); - } - for(i=0;i<3;i++) - { - if(surfaces->Pquantite[i]!=NULL) - SDL_FreeSurface (surfaces->Pquantite[i]); - } -} - -void inverse(int *bool) -{ - if (*bool) - *bool=0; - else if (!*bool) - *bool=1; -} - - -/* ********************************************************************* */ -/*obtenirPixel : permet de récupérer la couleur d'un pixel -Paramètres d'entrée/sortie : -SDL_Surface *surface : la surface sur laquelle on va récupérer la couleur d'un pixel -int x : la coordonnée en x du pixel à récupérer -int y : la coordonnée en y du pixel à récupérer - -Uint32 resultat : la fonction renvoie le pixel aux coordonnées (x,y) dans la surface -*/ -Uint32 obtenirPixel(SDL_Surface *surface, int x, int y) -{ - /*nbOctetsParPixel représente le nombre d'octets utilisés pour stocker un pixel. - En multipliant ce nombre d'octets par 8 (un octet = 8 bits), on obtient la profondeur de couleur - de l'image : 8, 16, 24 ou 32 bits.*/ - int nbOctetsParPixel = surface->format->BytesPerPixel; - /* Ici p est l'adresse du pixel que l'on veut connaitre */ - /*surface->pixels contient l'adresse du premier pixel de l'image*/ - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * nbOctetsParPixel; - - /*Gestion différente suivant le nombre d'octets par pixel de l'image*/ - switch(nbOctetsParPixel) - { - case 1: - return *p; - - case 2: - return *(Uint16 *)p; - - case 3: - /*Suivant l'architecture de la machine*/ - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - return p[0] << 16 | p[1] << 8 | p[2]; - else - return p[0] | p[1] << 8 | p[2] << 16; - - case 4: - return *(Uint32 *)p; - - /*Ne devrait pas arriver, mais évite les erreurs*/ - default: - return 0; - } -} - -/* ********************************************************************* */ -/*definirPixel : permet de modifier la couleur d'un pixel -Paramètres d'entrée/sortie : -SDL_Surface *surface : la surface sur laquelle on va modifier la couleur d'un pixel -int x : la coordonnée en x du pixel à modifier -int y : la coordonnée en y du pixel à modifier -Uint32 pixel : le pixel à insérer -*/ -void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) -{ - /*nbOctetsParPixel représente le nombre d'octets utilisés pour stocker un pixel. - En multipliant ce nombre d'octets par 8 (un octet = 8 bits), on obtient la profondeur de couleur - de l'image : 8, 16, 24 ou 32 bits.*/ - int nbOctetsParPixel = surface->format->BytesPerPixel; - /*Ici p est l'adresse du pixel que l'on veut modifier*/ - /*surface->pixels contient l'adresse du premier pixel de l'image*/ - Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * nbOctetsParPixel; - - /*Gestion différente suivant le nombre d'octets par pixel de l'image*/ - switch(nbOctetsParPixel) - { - case 1: - *p = pixel; - break; - - case 2: - *(Uint16 *)p = pixel; - break; - - case 3: - /*Suivant l'architecture de la machine*/ - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - { - p[0] = (pixel >> 16) & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = pixel & 0xff; - } - else - { - p[0] = pixel & 0xff; - p[1] = (pixel >> 8) & 0xff; - p[2] = (pixel >> 16) & 0xff; - } - break; - - case 4: - *(Uint32 *)p = pixel; - break; - } -} - - - +/* ******************************************************************** + WARCRAFT BATTLE : Jeu au tour par tour similaire à Final Fantasy + développé entièrement par moi :p pour le plaisir^^ + Je sais c'est du beau quand même sa fait plaisir de faire un programme + assez complet avec pour seule aide un clavier et une souris (et encore là + j'ai pas de souris je programme sur pc portable xD) + Enfin bref voilà ma création :) + Fais en bon usage et bon jeu à toi ;) + +PS : Et surtout copyright :p pas touche à mon code pas de désassemblage ni rien +hein ;) MON PROGRAMME ! :o) + +@+++ amuse toi bien */ + + + +#include +#include +#include +#include "structures.h" +#include "constantes.h" +#include +#include +#include "prototypes.h" +#include + +int main (int argc, char *argv[]) +{ + srand (time(NULL)); + SURFACES surfaces; + POSITIONS positions; + Finitialisersurfaces (&surfaces); + if (SDL_Init (SDL_INIT_VIDEO) == -1) + { + fprintf(stderr, "Erreur lors de l'ouverture de la SDL : %s", SDL_GetError()); + exit (EXIT_FAILURE); + } + surfaces.Pecran = SDL_SetVideoMode (XWIN,YWIN,32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_NOFRAME|SDL_FULLSCREEN); + if (surfaces.Pecran == NULL) + { + fprintf(stderr,"Impossible de charger la mémoire vidéo : %s", SDL_GetError()); + exit (EXIT_FAILURE); + } + SDL_EnableUNICODE (1); + TTF_Init(); + SDL_WM_SetCaption ("WARCRAFT BATTLE",NULL); + SDL_ShowCursor(SDL_DISABLE); + Fchargerimages (&surfaces); + Finitialiserpositions (&positions,&surfaces); + Fmenuprincipal (&surfaces, &positions); + + + //une fois le jeu quitté + Fdechargerimages (&surfaces); + SDL_EnableUNICODE (0); + TTF_Quit(); + SDL_Quit(); + + + return 0; +} + +void Finitialisersurfaces (SURFACES *surfaces) +{ + int i; + surfaces->Pcurseurennemis=NULL; + surfaces->Pcurseurallies=NULL; + surfaces->Pchoixvoleur=NULL; + surfaces->Pchoixpretre=NULL; + surfaces->Pchoixpaladin=NULL; + surfaces->Pecran=NULL; + surfaces->Pgobelin=NULL; + surfaces->Ppaladin=NULL; + surfaces->Ppretre=NULL; + surfaces->Pvoleur=NULL; + surfaces->Pmenujouer=NULL; + surfaces->Pmenuoptions=NULL; + surfaces->Pmenuquitter=NULL; + surfaces->Pfondjeu=NULL; + surfaces->Ppvpersos=NULL; + surfaces->Ppmpersos=NULL; + for (i=0;i<3;i++) + surfaces->Tperso[i]=NULL; + for (i=0;i<5;i++) + surfaces->Tennemi[i]=NULL; + for (i=0;i<3;i++) + surfaces->Pnomactions[i]=NULL; + surfaces->Ptextechoixmenu=NULL; + surfaces->Pnbdegats=NULL; + surfaces->Pcadrecible=NULL; + surfaces->Pnomcible=NULL; + surfaces->Pactive=NULL; + surfaces->Pdesactive=NULL; + surfaces->Ppvcible=NULL; + surfaces->Ppmcible=NULL; + surfaces->Pcadreactions=NULL; + surfaces->Pactionselectionnee=NULL; + surfaces->Pactiondesactivee=NULL; + surfaces->Pmort=NULL; + for (i=0;i<3;i++) + surfaces->Pquantite[i]=NULL; +} + +void Finitialiserpositions (POSITIONS *positions, SURFACES *surfaces) +{ + int i,y=0,z=0; + positions->Vpositionmenu.x = 0; + positions->Vpositionmenu.y = 0; + positions->Vpositionmenupretre.x = XWIN/2 - surfaces->Ppretre->w/2; + positions->Vpositionmenupretre.y = YWIN - 20 - surfaces->Ppretre->h; + positions->Vpositionmenupaladin.x = positions->Vpositionmenupretre.x/2 - surfaces->Ppaladin->w/2; + positions->Vpositionmenupaladin.y = YWIN - 20 - surfaces->Ppaladin->h; + positions->Vpositionmenuvoleur.x = XWIN/4*3 - surfaces->Pvoleur->w/2; + positions->Vpositionmenuvoleur.y = YWIN - 20 - surfaces->Pvoleur->h; + positions->Vpositiontextemenu.y = 362; + positions->Vpositioncurseurennemis.x=1024; + positions->Vpositioncurseurennemis.y=768; + positions->Vpositioncurseurallies.x=1024; + positions->Vpositioncurseurallies.y=768; + positions->Vpositioncurseurennemis.w = surfaces->Pcurseurennemis->w; + positions->Vpositioncurseurennemis.h = surfaces->Pcurseurennemis->h; + positions->Vpositioncadrecible.y = 15; + positions->Vpositioncadrecible.x = XWIN/2-50-surfaces->Pcadrecible->w/2; + positions->Vpositioncadrecible.w = surfaces->Pcadrecible->w; + positions->Vpositioncadrecible.h = surfaces->Pcadrecible->h; + positions->Vpositioncadreactions.y = YWIN-surfaces->Pcadreactions->h; + positions->Vpositioncadreactions.x = XWIN/2-50-surfaces->Pcadreactions->w/2; + positions->Vpositioncadreactions.w = surfaces->Pcadreactions->w; + positions->Vpositioncadreactions.h = surfaces->Pcadreactions->h; + positions->Vpositionpvcible.x = 380; + positions->Vpositionpvcible.y = 185; + positions->Vpositionpmcible.x = 545; + positions->Vpositionpmcible.y = 185; + positions->Vpositiondegats.x=1024; + positions->Vpositiondegats.y=768; + for(i=0;i<3;i++) + { + positions->Vpositionactionselectionnee[i].x=positions->Vpositioncadreactions.x+5; + positions->Vpositionactionselectionnee[i].y=positions->Vpositioncadreactions.y+5+44*i; + positions->Vpositionnomactions[i].x=positions->Vpositioncadreactions.x+15; + positions->Vpositionnomactions[i].y=positions->Vpositioncadreactions.y+12+44*i; + positions->Vpositionquantite[i].y=positions->Vpositionnomactions[i].y; + positions->Vpositionquantite[i].x=positions->Vpositioncadreactions.x+surfaces->Pcadreactions->w-45; + } + for (i=0;i < 16;i++) + { + positions->Vpositionactivedesactive[i].x = 471+51*y; + positions->Vpositionactivedesactive[i].y = 101+19*z; + if (y < 3) + y++; + else + { + y=0; + z++; + } + } +} + +void Fchargerimages (SURFACES *surfaces) +{ + int i; + surfaces->Pgobelin = IMG_Load ("images/gobelin.bmp"); + surfaces->Ppaladin = IMG_Load ("images/paladin.bmp"); + surfaces->Ppretre = IMG_Load ("images/prêtre.bmp"); + surfaces->Pvoleur = IMG_Load ("images/voleur.bmp"); + surfaces->Pmenujouer = IMG_Load ("images/menu_principal/jouer.bmp"); + surfaces->Pmenuoptions = IMG_Load ("images/menu_principal/options.bmp"); + surfaces->Pmenuquitter = IMG_Load ("images/menu_principal/quitter.bmp"); + surfaces->Pchoixvoleur = IMG_Load ("images/menu_choix_classe/voleur.bmp"); + surfaces->Pchoixpretre = IMG_Load ("images/menu_choix_classe/pretre.bmp"); + surfaces->Pchoixpaladin = IMG_Load ("images/menu_choix_classe/paladin.bmp"); + surfaces->Pcurseurennemis = IMG_Load ("images/jeu/curseur.bmp"); + surfaces->Pcurseurallies = IMG_Load ("images/jeu/curseurpersos.bmp"); + surfaces->Pcadrecible = IMG_Load ("images/jeu/cadre_cible.bmp"); + surfaces->Pactive = IMG_Load ("images/jeu/active.bmp"); + surfaces->Pdesactive = IMG_Load ("images/jeu/desactive.bmp"); + surfaces->Pcadreactions = IMG_Load ("images/jeu/cadre_actions.bmp"); + surfaces->Pactionselectionnee=IMG_Load ("images/jeu/cadre_actions_select.bmp"); + surfaces->Pactiondesactivee=IMG_Load("images/jeu/cadre_actions_unactive.bmp"); + surfaces->Pmort=IMG_Load("images/jeu/mort.bmp"); + for (i = 0;i < 5;i++) + surfaces->Tennemi[i] = surfaces->Pgobelin; + + //définition de la transparence alpha dans les surfaces + SDL_SetColorKey(surfaces->Pgobelin,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,0,255,18)); + SDL_SetColorKey(surfaces->Ppretre,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,39,189,31)); + SDL_SetColorKey(surfaces->Ppaladin,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,189,31,31)); + SDL_SetColorKey(surfaces->Pvoleur,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,39,189,31)); + SDL_SetColorKey(surfaces->Pcurseurennemis,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); + SDL_SetColorKey(surfaces->Pcurseurallies,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); + SDL_SetColorKey(surfaces->Pactive,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); + SDL_SetColorKey(surfaces->Pdesactive,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); + SDL_SetColorKey(surfaces->Pmort,SDL_SRCCOLORKEY,SDL_MapRGB(surfaces->Pecran->format,255,255,255)); +} + +void Fdechargerimages (SURFACES *surfaces)//dechargement des surfaces alouées +{ + int i; + SDL_FreeSurface(surfaces->Pecran); + SDL_FreeSurface (surfaces->Pgobelin); + SDL_FreeSurface (surfaces->Ppaladin); + SDL_FreeSurface (surfaces->Ppretre); + SDL_FreeSurface (surfaces->Pvoleur); + SDL_FreeSurface (surfaces->Pmenujouer); + SDL_FreeSurface (surfaces->Pmenuoptions); + SDL_FreeSurface (surfaces->Pmenuquitter); + SDL_FreeSurface (surfaces->Pchoixpretre); + SDL_FreeSurface (surfaces->Pchoixpaladin); + SDL_FreeSurface (surfaces->Pchoixvoleur); + SDL_FreeSurface (surfaces->Pcurseurennemis); + SDL_FreeSurface (surfaces->Pcurseurallies); + SDL_FreeSurface (surfaces->Pcadrecible); + SDL_FreeSurface (surfaces->Pactive); + SDL_FreeSurface (surfaces->Pdesactive); + SDL_FreeSurface (surfaces->Pcadreactions); + SDL_FreeSurface (surfaces->Pactionselectionnee); + SDL_FreeSurface (surfaces->Pactiondesactivee); + SDL_FreeSurface (surfaces->Pmort); + SDL_FreeSurface (surfaces->Pfondjeu); + SDL_FreeSurface(surfaces->Ptextechoixmenu); + SDL_FreeSurface(surfaces->Pnbdegats); + SDL_FreeSurface(surfaces->Pnomcible); + SDL_FreeSurface(surfaces->Ppvcible); + SDL_FreeSurface(surfaces->Ppmcible); + SDL_FreeSurface(surfaces->Ppvpersos); + SDL_FreeSurface(surfaces->Ppmpersos); + for(i = 0;i < 3;i++) + { + SDL_FreeSurface(surfaces->Tperso[i]); + } + for(i=0;i<5;i++) + { + SDL_FreeSurface(surfaces->Tennemi[i]); + } + for(i=0;i<3;i++) + { + SDL_FreeSurface (surfaces->Pnomactions[i]); + } + for(i=0;i<3;i++) + { + SDL_FreeSurface (surfaces->Pquantite[i]); + } +} + +void inverse(int *bool) +{ + if (*bool) + *bool=0; + else if (!*bool) + *bool=1; +} + + +/* ********************************************************************* */ +/*obtenirPixel : permet de récupérer la couleur d'un pixel +Paramètres d'entrée/sortie : +SDL_Surface *surface : la surface sur laquelle on va récupérer la couleur d'un pixel +int x : la coordonnée en x du pixel à récupérer +int y : la coordonnée en y du pixel à récupérer + +Uint32 resultat : la fonction renvoie le pixel aux coordonnées (x,y) dans la surface +*/ +Uint32 obtenirPixel(SDL_Surface *surface, int x, int y) +{ + /*nbOctetsParPixel représente le nombre d'octets utilisés pour stocker un pixel. + En multipliant ce nombre d'octets par 8 (un octet = 8 bits), on obtient la profondeur de couleur + de l'image : 8, 16, 24 ou 32 bits.*/ + int nbOctetsParPixel = surface->format->BytesPerPixel; + /* Ici p est l'adresse du pixel que l'on veut connaitre */ + /*surface->pixels contient l'adresse du premier pixel de l'image*/ + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * nbOctetsParPixel; + + /*Gestion différente suivant le nombre d'octets par pixel de l'image*/ + switch(nbOctetsParPixel) + { + case 1: + return *p; + + case 2: + return *(Uint16 *)p; + + case 3: + /*Suivant l'architecture de la machine*/ + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + return p[0] << 16 | p[1] << 8 | p[2]; + else + return p[0] | p[1] << 8 | p[2] << 16; + + case 4: + return *(Uint32 *)p; + + /*Ne devrait pas arriver, mais évite les erreurs*/ + default: + return 0; + } +} + +/* ********************************************************************* */ +/*definirPixel : permet de modifier la couleur d'un pixel +Paramètres d'entrée/sortie : +SDL_Surface *surface : la surface sur laquelle on va modifier la couleur d'un pixel +int x : la coordonnée en x du pixel à modifier +int y : la coordonnée en y du pixel à modifier +Uint32 pixel : le pixel à insérer +*/ +void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) +{ + /*nbOctetsParPixel représente le nombre d'octets utilisés pour stocker un pixel. + En multipliant ce nombre d'octets par 8 (un octet = 8 bits), on obtient la profondeur de couleur + de l'image : 8, 16, 24 ou 32 bits.*/ + int nbOctetsParPixel = surface->format->BytesPerPixel; + /*Ici p est l'adresse du pixel que l'on veut modifier*/ + /*surface->pixels contient l'adresse du premier pixel de l'image*/ + Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * nbOctetsParPixel; + + /*Gestion différente suivant le nombre d'octets par pixel de l'image*/ + switch(nbOctetsParPixel) + { + case 1: + *p = pixel; + break; + + case 2: + *(Uint16 *)p = pixel; + break; + + case 3: + /*Suivant l'architecture de la machine*/ + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + { + p[0] = (pixel >> 16) & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = pixel & 0xff; + } + else + { + p[0] = pixel & 0xff; + p[1] = (pixel >> 8) & 0xff; + p[2] = (pixel >> 16) & 0xff; + } + break; + + case 4: + *(Uint32 *)p = pixel; + break; + } +} + + + diff --git a/map.c b/map.c index 04d0be4..5c341a1 100644 --- a/map.c +++ b/map.c @@ -1,130 +1,130 @@ -#include -#include -#include -#include "constantes.h" -#include "structures.h" -#include "prototypes.h" -#include - -void Fmap (SURFACES*surfaces, POSITIONS* positions,PERSONNAGES persos[],ENNEMIS ennemis[]) -{ - int map[15][11]; - int continuer=1; - SDL_Event event; - Fchargersurfaces_map(surfaces,positions); - Fgetmap (map); - Fblittermap(surfaces,positions,map); - while(continuer) - { - SDL_WaitEvent (&event); - switch (event.type) - { - case SDL_KEYDOWN: - switch (event.key.keysym.sym) - { - case SDLK_RETURN: - continuer=Fjouer(surfaces,positions,persos,ennemis); - break; - case SDLK_ESCAPE: - continuer=0; - break; - } - break; - } - } -//une fois le jeu quitté ! - Fdechargersurfaces_map(surfaces); -} - -void Fgetmap (int map[][11]) -{ - FILE* fichier=NULL; - char chaine[165]; - int i,j,k=0; - - fichier=fopen("map.war","r"); - if(fichier==NULL) - fprintf(stderr, "Impossible d'ouvrir le fichier map.war"); - fgets(chaine,166,fichier); - fclose(fichier); - for(j=0;j<11;j++) - { - for(i=0;i<15;i++) - { - switch (chaine[k]) - { - case '0': - map[i][j]=SOL; - break; - case '1': - map[i][j]=MUR; - break; - case '2': - map[i][j]=COFFRE; - break; - case '3': - map[i][j]=GUS; - break; - } - k++; - } - } -} - -void Fchargersurfaces_map (SURFACES *surfaces,POSITIONS*positions) -{ - int i,j; - for(j=0;j<11;j++) - { - for(i=0;i<15;i++) - { - positions->Vpositionmap_item[i][j].x=i*64+32; - positions->Vpositionmap_item[i][j].y=j*64+32; - } - } - surfaces->Pmap_sol=NULL; - surfaces->Pmap_sol=IMG_Load("images/map/sol.bmp"); - surfaces->Pmap_mur=NULL; - surfaces->Pmap_mur=IMG_Load("images/map/mur.bmp"); - surfaces->Pmap_coffre=NULL; - surfaces->Pmap_coffre=IMG_Load("images/map/coffre.bmp"); - surfaces->Pmap_perso=NULL; - surfaces->Pmap_perso=IMG_Load("images/map/perso.bmp"); -} - -void Fdechargersurfaces_map(SURFACES*surfaces) -{ - SDL_FreeSurface(surfaces->Pmap_sol); - SDL_FreeSurface(surfaces->Pmap_mur); - SDL_FreeSurface(surfaces->Pmap_coffre); - SDL_FreeSurface(surfaces->Pmap_perso); -} - - -void Fblittermap (SURFACES*surfaces,POSITIONS*positions,int map[][11]) -{ - int i,j; - - for(j=0;j<11;j++) - { - for(i=0;i<15;i++) - { - switch (map[i][j]) - { - case SOL: - SDL_BlitSurface(surfaces->Pmap_sol,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); - break; - case MUR: - SDL_BlitSurface(surfaces->Pmap_mur,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); - break; - case COFFRE: - SDL_BlitSurface(surfaces->Pmap_coffre,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); - break; - case GUS: - SDL_BlitSurface(surfaces->Pmap_perso,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); - break; - } - } - } - SDL_Flip(surfaces->Pecran); -} +#include +#include +#include +#include "constantes.h" +#include "structures.h" +#include "prototypes.h" +#include + +void Fmap (SURFACES*surfaces, POSITIONS* positions,PERSONNAGES persos[],ENNEMIS ennemis[]) +{ + int map[15][11]; + int continuer=1; + SDL_Event event; + Fchargersurfaces_map(surfaces,positions); + Fgetmap (map); + Fblittermap(surfaces,positions,map); + while(continuer) + { + SDL_WaitEvent (&event); + switch (event.type) + { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_RETURN: + continuer=Fjouer(surfaces,positions,persos,ennemis); + break; + case SDLK_ESCAPE: + continuer=0; + break; + } + break; + } + } +//une fois le jeu quitté ! + Fdechargersurfaces_map(surfaces); +} + +void Fgetmap (int map[][11]) +{ + FILE* fichier=NULL; + char chaine[165]; + int i,j,k=0; + + fichier=fopen("map.war","r"); + if(fichier==NULL) + fprintf(stderr, "Impossible d'ouvrir le fichier map.war"); + fgets(chaine,166,fichier); + fclose(fichier); + for(j=0;j<11;j++) + { + for(i=0;i<15;i++) + { + switch (chaine[k]) + { + case '0': + map[i][j]=SOL; + break; + case '1': + map[i][j]=MUR; + break; + case '2': + map[i][j]=COFFRE; + break; + case '3': + map[i][j]=GUS; + break; + } + k++; + } + } +} + +void Fchargersurfaces_map (SURFACES *surfaces,POSITIONS*positions) +{ + int i,j; + for(j=0;j<11;j++) + { + for(i=0;i<15;i++) + { + positions->Vpositionmap_item[i][j].x=i*64+32; + positions->Vpositionmap_item[i][j].y=j*64+32; + } + } + surfaces->Pmap_sol=NULL; + surfaces->Pmap_sol=IMG_Load("images/map/sol.bmp"); + surfaces->Pmap_mur=NULL; + surfaces->Pmap_mur=IMG_Load("images/map/mur.bmp"); + surfaces->Pmap_coffre=NULL; + surfaces->Pmap_coffre=IMG_Load("images/map/coffre.bmp"); + surfaces->Pmap_perso=NULL; + surfaces->Pmap_perso=IMG_Load("images/map/perso.bmp"); +} + +void Fdechargersurfaces_map(SURFACES*surfaces) +{ + SDL_FreeSurface(surfaces->Pmap_sol); + SDL_FreeSurface(surfaces->Pmap_mur); + SDL_FreeSurface(surfaces->Pmap_coffre); + SDL_FreeSurface(surfaces->Pmap_perso); +} + + +void Fblittermap (SURFACES*surfaces,POSITIONS*positions,int map[][11]) +{ + int i,j; + + for(j=0;j<11;j++) + { + for(i=0;i<15;i++) + { + switch (map[i][j]) + { + case SOL: + SDL_BlitSurface(surfaces->Pmap_sol,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); + break; + case MUR: + SDL_BlitSurface(surfaces->Pmap_mur,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); + break; + case COFFRE: + SDL_BlitSurface(surfaces->Pmap_coffre,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); + break; + case GUS: + SDL_BlitSurface(surfaces->Pmap_perso,NULL,surfaces->Pecran,&positions->Vpositionmap_item[i][j]); + break; + } + } + } + SDL_Flip(surfaces->Pecran); +} diff --git a/menuchoixpersos.c b/menuchoixpersos.c index 8db15df..6c5f9b7 100644 --- a/menuchoixpersos.c +++ b/menuchoixpersos.c @@ -1,154 +1,154 @@ -#include -#include -#include -#include "structures.h" -#include "constantes.h" -#include "prototypes.h" -#include -#include - -void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) -{ - - int nbpersos = 0; - TTF_Font *police = NULL; - int Vchoix = 0; - SDL_Color vert; - unsigned int continuer = 1; - PERSONNAGES persos[3]; - ENNEMIS ennemis[5]; - SDL_Event event; - int Vnbperso = 0; - - vert.r = 39; - vert.g = 189; - vert.b = 31; - SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); - police = TTF_OpenFont ("C://WINDOWS//Fonts//TIMESI.TTF",36); - while (Vnbperso!=3) - { - continuer = 1; - if (Vnbperso == 0) - surfaces->Ptextechoixmenu = TTF_RenderText_Blended (police,"Choisissez la Classe de votre Premier Personnage",vert); - else if (Vnbperso == 1) - surfaces->Ptextechoixmenu = TTF_RenderText_Blended (police,"Choisissez la Classe de votre Deuxième Personnage",vert); - else if (Vnbperso == 2) - surfaces->Ptextechoixmenu = TTF_RenderText_Blended (police,"Choisissez la Classe de votre Troisième Personnage",vert); - positions->Vpositiontextemenu.x=XWIN/2-surfaces->Ptextechoixmenu->w/2; - if (persos[Vnbperso-1].classe == PALADIN) - SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); - if (persos[Vnbperso-1].classe == PRETRE) - SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); - if (persos[Vnbperso-1].classe == VOLEUR) - SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu); - SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionmenupretre); - SDL_BlitSurface (surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionmenupaladin); - SDL_BlitSurface (surfaces->Pvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenuvoleur); - SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu); - SDL_Flip (surfaces->Pecran); - while (continuer) - { - SDL_WaitEvent (&event); - switch (event.type) - { - case SDL_KEYDOWN: - switch (event.key.keysym.sym) - { - case SDLK_LEFT: - if(Vchoix>PALADIN) - { - Vchoix--; - Fchangersurlignage2 (Vchoix,surfaces,positions); - } - else - { - Vchoix=VOLEUR; - Fchangersurlignage2 (Vchoix,surfaces,positions); - } - break; - case SDLK_RIGHT: - if (VchoixPecran); - Fremplirpersos2 (surfaces,persos); - Fmap(surfaces,positions,persos,ennemis); -} - -void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions) -{ - if (Vchoix==PALADIN) - SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); - else if (Vchoix==PRETRE) - SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); - else if (Vchoix==VOLEUR) - SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu); - SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionmenupretre); - SDL_BlitSurface (surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionmenupaladin); - SDL_BlitSurface (surfaces->Pvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenuvoleur); - SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu); - SDL_Flip (surfaces->Pecran); -} - -void Fremplirpersos (int Vchoix, PERSONNAGES persos[],int Vnbpersos) -{ - if (Vchoix==PALADIN) - persos[Vnbpersos].classe=PALADIN; - else if (Vchoix==PRETRE) - persos[Vnbpersos].classe=PRETRE; - else if (Vchoix==VOLEUR) - persos[Vnbpersos].classe=VOLEUR; -} - -void Fremplirpersos2 (SURFACES *surfaces, PERSONNAGES persos[]) -{ - - int i; - for (i=0;i<3;i++) - { - if (persos[i].classe==PALADIN) - surfaces->Tperso[i]=IMG_Load("images/paladin.bmp"); - else if (persos[i].classe==PRETRE) - surfaces->Tperso[i]=IMG_Load("images/prêtre.bmp"); - else if (persos[i].classe==VOLEUR) - surfaces->Tperso[i]=IMG_Load("images/voleur.bmp"); - } -} - -void Fremplirennemis (SURFACES *surfaces,int Vnbennemis,ENNEMIS ennemis[]) -{ - - int i; - for (i=0;i<=Vnbennemis;i++) - { - if (ennemis[i].classe==GUERRIER_GOBELIN) - surfaces->Tennemi[i]=surfaces->Pgobelin; - } -} - -int Fcalculernbennemis () -{ - int nb; - nb=(rand()%(4-0+1))+0; - return nb; -} - +#include +#include +#include +#include "structures.h" +#include "constantes.h" +#include "prototypes.h" +#include +#include + +void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) +{ + + int nbpersos = 0; + TTF_Font *police = NULL; + int Vchoix = 0; + SDL_Color vert; + unsigned int continuer = 1; + PERSONNAGES persos[3]; + ENNEMIS ennemis[5]; + SDL_Event event; + int Vnbperso = 0; + + vert.r = 39; + vert.g = 189; + vert.b = 31; + SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); + police = TTF_OpenFont ("C://WINDOWS//Fonts//TIMESI.TTF",36); + while (Vnbperso!=3) + { + continuer = 1; + if (Vnbperso == 0) + surfaces->Ptextechoixmenu = TTF_RenderText_Blended (police,"Choisissez la Classe de votre Premier Personnage",vert); + else if (Vnbperso == 1) + surfaces->Ptextechoixmenu = TTF_RenderText_Blended (police,"Choisissez la Classe de votre Deuxième Personnage",vert); + else if (Vnbperso == 2) + surfaces->Ptextechoixmenu = TTF_RenderText_Blended (police,"Choisissez la Classe de votre Troisième Personnage",vert); + positions->Vpositiontextemenu.x=XWIN/2-surfaces->Ptextechoixmenu->w/2; + if (persos[Vnbperso-1].classe == PALADIN) + SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); + if (persos[Vnbperso-1].classe == PRETRE) + SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); + if (persos[Vnbperso-1].classe == VOLEUR) + SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu); + SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionmenupretre); + SDL_BlitSurface (surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionmenupaladin); + SDL_BlitSurface (surfaces->Pvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenuvoleur); + SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu); + SDL_Flip (surfaces->Pecran); + while (continuer) + { + SDL_WaitEvent (&event); + switch (event.type) + { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_LEFT: + if(Vchoix>PALADIN) + { + Vchoix--; + Fchangersurlignage2 (Vchoix,surfaces,positions); + } + else + { + Vchoix=VOLEUR; + Fchangersurlignage2 (Vchoix,surfaces,positions); + } + break; + case SDLK_RIGHT: + if (VchoixPecran); + Fremplirpersos2 (surfaces,persos); + Fmap(surfaces,positions,persos,ennemis); +} + +void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions) +{ + if (Vchoix==PALADIN) + SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); + else if (Vchoix==PRETRE) + SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); + else if (Vchoix==VOLEUR) + SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu); + SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionmenupretre); + SDL_BlitSurface (surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionmenupaladin); + SDL_BlitSurface (surfaces->Pvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenuvoleur); + SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu); + SDL_Flip (surfaces->Pecran); +} + +void Fremplirpersos (int Vchoix, PERSONNAGES persos[],int Vnbpersos) +{ + if (Vchoix==PALADIN) + persos[Vnbpersos].classe=PALADIN; + else if (Vchoix==PRETRE) + persos[Vnbpersos].classe=PRETRE; + else if (Vchoix==VOLEUR) + persos[Vnbpersos].classe=VOLEUR; +} + +void Fremplirpersos2 (SURFACES *surfaces, PERSONNAGES persos[]) +{ + + int i; + for (i=0;i<3;i++) + { + if (persos[i].classe==PALADIN) + surfaces->Tperso[i]=IMG_Load("images/paladin.bmp"); + else if (persos[i].classe==PRETRE) + surfaces->Tperso[i]=IMG_Load("images/prêtre.bmp"); + else if (persos[i].classe==VOLEUR) + surfaces->Tperso[i]=IMG_Load("images/voleur.bmp"); + } +} + +void Fremplirennemis (SURFACES *surfaces,int Vnbennemis,ENNEMIS ennemis[]) +{ + + int i; + for (i=0;i<=Vnbennemis;i++) + { + if (ennemis[i].classe==GUERRIER_GOBELIN) + surfaces->Tennemi[i]=surfaces->Pgobelin; + } +} + +int Fcalculernbennemis () +{ + int nb; + nb=(rand()%(4-0+1))+0; + return nb; +} + diff --git a/menuoptions.c b/menuoptions.c index 4d704d3..95da338 100644 --- a/menuoptions.c +++ b/menuoptions.c @@ -1,10 +1,10 @@ -#include -#include -#include -#include "structures.h" - -void Foptions (SURFACES *surfaces, POSITIONS *positions) -{ - -} - +#include +#include +#include +#include "structures.h" + +void Foptions (SURFACES *surfaces, POSITIONS *positions) +{ + +} + diff --git a/menuprincipal.c b/menuprincipal.c index 57f709f..d3b4813 100644 --- a/menuprincipal.c +++ b/menuprincipal.c @@ -1,86 +1,86 @@ -#include -#include -#include -#include "structures.h" -#include "prototypes.h" -#include "constantes.h" - -void Fmenuprincipal (SURFACES *surfaces, POSITIONS *positions) -{ - int continuer = 1; - SDL_Event event; - int Vmode = 0; - SDL_BlitSurface (surfaces->Pmenujouer,NULL,surfaces->Pecran,&positions->Vpositionmenu); - SDL_Flip (surfaces->Pecran); - while (continuer) - { - SDL_WaitEvent (&event); - switch (event.type) - { - case SDL_KEYDOWN: - switch (event.key.keysym.sym) - { - case SDLK_DOWN: - - if (Vmode < 2) - { - Vmode++; - Fchangersurlignage (Vmode,surfaces,positions); - } - else - { - Vmode = 0; - Fchangersurlignage (Vmode,surfaces,positions); - } - break; - case SDLK_UP: - if (Vmode > 0) - { - Vmode--; - Fchangersurlignage (Vmode,surfaces,positions); - } - else - { - Vmode = 2; - Fchangersurlignage (Vmode,surfaces,positions); - } - break; - case SDLK_RETURN: - continuer = Fentrermode (Vmode,surfaces,positions); - Vmode = 0; - if (continuer) - { - SDL_BlitSurface (surfaces->Pmenujouer,NULL,surfaces->Pecran,&positions->Vpositionmenu); - SDL_Flip (surfaces->Pecran); - } - break; - } - break; - } - } -} - -void Fchangersurlignage (int Vmode, SURFACES *surfaces, POSITIONS *positions) -{ - if (Vmode == 0) - SDL_BlitSurface (surfaces->Pmenujouer,NULL,surfaces->Pecran,&positions->Vpositionmenu); - else if (Vmode == 1) - SDL_BlitSurface (surfaces->Pmenuoptions,NULL,surfaces->Pecran,&positions->Vpositionmenu); - else if (Vmode == 2) - SDL_BlitSurface (surfaces->Pmenuquitter,NULL,surfaces->Pecran,&positions->Vpositionmenu); - SDL_Flip (surfaces->Pecran); -} - -int Fentrermode (int Vmode, SURFACES *surfaces, POSITIONS *positions) -{ - int continuer = 1; - - if (Vmode == 0) - Fmenuchoixpersos (surfaces,positions); - else if (Vmode == 1) - Foptions (surfaces,positions); - else if (Vmode == 2) - continuer = 0; - return continuer; -} - +#include +#include +#include +#include "structures.h" +#include "prototypes.h" +#include "constantes.h" + +void Fmenuprincipal (SURFACES *surfaces, POSITIONS *positions) +{ + int continuer = 1; + SDL_Event event; + int Vmode = 0; + SDL_BlitSurface (surfaces->Pmenujouer,NULL,surfaces->Pecran,&positions->Vpositionmenu); + SDL_Flip (surfaces->Pecran); + while (continuer) + { + SDL_WaitEvent (&event); + switch (event.type) + { + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_DOWN: + + if (Vmode < 2) + { + Vmode++; + Fchangersurlignage (Vmode,surfaces,positions); + } + else + { + Vmode = 0; + Fchangersurlignage (Vmode,surfaces,positions); + } + break; + case SDLK_UP: + if (Vmode > 0) + { + Vmode--; + Fchangersurlignage (Vmode,surfaces,positions); + } + else + { + Vmode = 2; + Fchangersurlignage (Vmode,surfaces,positions); + } + break; + case SDLK_RETURN: + continuer = Fentrermode (Vmode,surfaces,positions); + Vmode = 0; + if (continuer) + { + SDL_BlitSurface (surfaces->Pmenujouer,NULL,surfaces->Pecran,&positions->Vpositionmenu); + SDL_Flip (surfaces->Pecran); + } + break; + } + break; + } + } +} + +void Fchangersurlignage (int Vmode, SURFACES *surfaces, POSITIONS *positions) +{ + if (Vmode == 0) + SDL_BlitSurface (surfaces->Pmenujouer,NULL,surfaces->Pecran,&positions->Vpositionmenu); + else if (Vmode == 1) + SDL_BlitSurface (surfaces->Pmenuoptions,NULL,surfaces->Pecran,&positions->Vpositionmenu); + else if (Vmode == 2) + SDL_BlitSurface (surfaces->Pmenuquitter,NULL,surfaces->Pecran,&positions->Vpositionmenu); + SDL_Flip (surfaces->Pecran); +} + +int Fentrermode (int Vmode, SURFACES *surfaces, POSITIONS *positions) +{ + int continuer = 1; + + if (Vmode == 0) + Fmenuchoixpersos (surfaces,positions); + else if (Vmode == 1) + Foptions (surfaces,positions); + else if (Vmode == 2) + continuer = 0; + return continuer; +} + diff --git a/prototypes.h b/prototypes.h index 9bd1e47..3957017 100644 --- a/prototypes.h +++ b/prototypes.h @@ -1,61 +1,61 @@ -#ifndef PROTOTYPES_H -#define PROTOTYPES_H - -void Fmenuprincipal (SURFACES *surfaces, POSITIONS *positions); -void Fchangersurlignage (int Vmode, SURFACES *surfaces, POSITIONS *positions); -int Fentrermode (int Vmode, SURFACES *surfaces, POSITIONS *positions); -void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions); -void Fchangersurlignage2 (int Vperso, SURFACES *surfaces, POSITIONS *positions); -void Fremplirpersos (int Vperso, PERSONNAGES persos[],int Vnbpersos); -void Fremplirpersos2 (SURFACES *surfaces, PERSONNAGES persos[]); -int Fjouer (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[],ENNEMIS ennemis[]); -void Fblitterpersos (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[]); -void Finitialiserpositionspersos (SURFACES *surfaces,POSITIONS *positions); -void Finitialisersurfaces (SURFACES *surfaces); -void Fchargerimages (SURFACES *surfaces); -void Fdechargerimages (SURFACES *surfaces); -void inverse(int *bool); -void Finitialiserpositions (POSITIONS *positions, SURFACES *surfaces); -void Fblitterennemis (SURFACES *surfaces, POSITIONS *positions,ENNEMIS ennemis[],int Vnbennemis); -void Finitialiserpositionsennemis (SURFACES *surfaces, POSITIONS *positions,int Vnbennemis); -void Fattaquer (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int*Vtour); -void Fremplircompetencesallie (PERSONNAGES persos[]); -int Fcalculernbennemis (); -void Fchoisirtypeennemis (PERSONNAGES persos[],SURFACES *surfaces,ENNEMIS ennemis[],int Vnbennemis); -void Fremplirennemis (SURFACES *surfaces,int Vnbennemis,ENNEMIS ennemis[]); -int Fcalculerdegats(PERSONNAGES persos[],int *Vtourallie,int *min,ENNEMIS ennemis[],int selection,int camp,int type); -int Fcalculersoins(PERSONNAGES persos[],int *Vtourallie,int *min,ENNEMIS ennemis[],int selection); -void Fchangercurseur (SURFACES *surfaces, POSITIONS *positions,int selection,ENNEMIS ennemis[]); -void Fafficherdegats (SURFACES *surfaces, POSITIONS *positions, int degats,int camp, int cible,PERSONNAGES persos[]); -void Fremplircompetencesennemis (ENNEMIS ennemis[],int Vnbennemis); -void Fselectionnermagienoire (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int*Vtour); -int Fmagieelement (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis, int element,int *Vtour); -void Fblitteractivedesactive (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection); -void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions,int type,OBJET *objets); -void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection); -void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection); -void Fchangermagienoireselectionnee(SURFACES *surfaces,POSITIONS *positions,int selection,int page,int nbactions); -void Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int *Vtour); -void Fchangermagieblancheselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions); -void Fblitterpmpvpersos(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int selection); -int Fmagiesoin (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int *Vtour); -void Faffichersoins (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible,PERSONNAGES persos[]); -void Fremplirobjets(OBJET *objets); -void Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int*Vtour); -int Fpotion(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type,int*Vtour); -int Fether(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type,int *Vtour); -void Fblitterfond(SURFACES* surfaces); -void Fcolourselection(SURFACES* surfaces, PERSONNAGES persos[],int Vtourallie,POSITIONS* positions); -void Fblitcoloredselection (SURFACES surfaces[],POSITIONS positions[],int Vtourallie,PERSONNAGES persos[]); -Uint32 obtenirPixel(SDL_Surface *surface, int x, int y); -void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel); -int Fgeneratedegats(PERSONNAGES persos[],ENNEMIS ennemis[],int Vtourennemi,int target); -int Fchoosetargetallie(PERSONNAGES persos[]); -void Factionennemi(int* Vtourennemi,SURFACES* surfaces,POSITIONS* positions, ENNEMIS ennemis[], PERSONNAGES persos[],int Vnbennemis,int*Vtour,int Vtourallie); -void Fgetmap (int map[][11]); -void Fmap (SURFACES*surfaces, POSITIONS* positions,PERSONNAGES persos[],ENNEMIS ennemis[]); -void Fchargersurfaces_map (SURFACES *surfaces,POSITIONS*positions); -void Fblittermap (SURFACES*surfaces,POSITIONS*positions,int map[][11]); -void Fdechargersurfaces_map(SURFACES*surfaces); - -#endif +#ifndef PROTOTYPES_H +#define PROTOTYPES_H + +void Fmenuprincipal (SURFACES *surfaces, POSITIONS *positions); +void Fchangersurlignage (int Vmode, SURFACES *surfaces, POSITIONS *positions); +int Fentrermode (int Vmode, SURFACES *surfaces, POSITIONS *positions); +void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions); +void Fchangersurlignage2 (int Vperso, SURFACES *surfaces, POSITIONS *positions); +void Fremplirpersos (int Vperso, PERSONNAGES persos[],int Vnbpersos); +void Fremplirpersos2 (SURFACES *surfaces, PERSONNAGES persos[]); +int Fjouer (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[],ENNEMIS ennemis[]); +void Fblitterpersos (SURFACES *surfaces, POSITIONS *positions, PERSONNAGES persos[]); +void Finitialiserpositionspersos (SURFACES *surfaces,POSITIONS *positions); +void Finitialisersurfaces (SURFACES *surfaces); +void Fchargerimages (SURFACES *surfaces); +void Fdechargerimages (SURFACES *surfaces); +void inverse(int *bool); +void Finitialiserpositions (POSITIONS *positions, SURFACES *surfaces); +void Fblitterennemis (SURFACES *surfaces, POSITIONS *positions,ENNEMIS ennemis[],int Vnbennemis); +void Finitialiserpositionsennemis (SURFACES *surfaces, POSITIONS *positions,int Vnbennemis); +void Fattaquer (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int*Vtour); +void Fremplircompetencesallie (PERSONNAGES persos[]); +int Fcalculernbennemis (); +void Fchoisirtypeennemis (PERSONNAGES persos[],SURFACES *surfaces,ENNEMIS ennemis[],int Vnbennemis); +void Fremplirennemis (SURFACES *surfaces,int Vnbennemis,ENNEMIS ennemis[]); +int Fcalculerdegats(PERSONNAGES persos[],int *Vtourallie,int *min,ENNEMIS ennemis[],int selection,int camp,int type); +int Fcalculersoins(PERSONNAGES persos[],int *Vtourallie,int *min,ENNEMIS ennemis[],int selection); +void Fchangercurseur (SURFACES *surfaces, POSITIONS *positions,int selection,ENNEMIS ennemis[]); +void Fafficherdegats (SURFACES *surfaces, POSITIONS *positions, int degats,int camp, int cible,PERSONNAGES persos[]); +void Fremplircompetencesennemis (ENNEMIS ennemis[],int Vnbennemis); +void Fselectionnermagienoire (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int*Vtour); +int Fmagieelement (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis, int element,int *Vtour); +void Fblitteractivedesactive (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection); +void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions,int type,OBJET *objets); +void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection); +void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection); +void Fchangermagienoireselectionnee(SURFACES *surfaces,POSITIONS *positions,int selection,int page,int nbactions); +void Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int *Vtour); +void Fchangermagieblancheselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions); +void Fblitterpmpvpersos(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int selection); +int Fmagiesoin (SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,int *Vtour); +void Faffichersoins (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible,PERSONNAGES persos[]); +void Fremplirobjets(OBJET *objets); +void Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int*Vtour); +int Fpotion(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type,int*Vtour); +int Fether(SURFACES *surfaces,POSITIONS *positions,PERSONNAGES persos[],int *Vtourallie,ENNEMIS ennemis[],int Vnbennemis,OBJET *objets,int type,int *Vtour); +void Fblitterfond(SURFACES* surfaces); +void Fcolourselection(SURFACES* surfaces, PERSONNAGES persos[],int Vtourallie,POSITIONS* positions); +void Fblitcoloredselection (SURFACES surfaces[],POSITIONS positions[],int Vtourallie,PERSONNAGES persos[]); +Uint32 obtenirPixel(SDL_Surface *surface, int x, int y); +void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel); +int Fgeneratedegats(PERSONNAGES persos[],ENNEMIS ennemis[],int Vtourennemi,int target); +int Fchoosetargetallie(PERSONNAGES persos[]); +void Factionennemi(int* Vtourennemi,SURFACES* surfaces,POSITIONS* positions, ENNEMIS ennemis[], PERSONNAGES persos[],int Vnbennemis,int*Vtour,int Vtourallie); +void Fgetmap (int map[][11]); +void Fmap (SURFACES*surfaces, POSITIONS* positions,PERSONNAGES persos[],ENNEMIS ennemis[]); +void Fchargersurfaces_map (SURFACES *surfaces,POSITIONS*positions); +void Fblittermap (SURFACES*surfaces,POSITIONS*positions,int map[][11]); +void Fdechargersurfaces_map(SURFACES*surfaces); + +#endif diff --git a/structures.h b/structures.h index 8b8783f..fdb2ecb 100644 --- a/structures.h +++ b/structures.h @@ -1,119 +1,119 @@ -#ifndef STRUCTURES_H -#define STRUCTURES_H - -typedef struct surfaces SURFACES; -struct surfaces -{ - SDL_Surface *Pecran; - SDL_Surface *Pgobelin; - SDL_Surface *Ppaladin; - SDL_Surface *Ppretre; - SDL_Surface *Pvoleur; - SDL_Surface *Pmenuoptions; - SDL_Surface *Pmenujouer; - SDL_Surface *Pmenuquitter; - SDL_Surface *Pchoixpaladin; - SDL_Surface *Pchoixpretre; - SDL_Surface *Pchoixvoleur; - SDL_Surface *Tperso[3]; - SDL_Surface *Tennemi[5]; - SDL_Surface *Ptextechoixmenu; - SDL_Surface *Pcurseurennemis; - SDL_Surface *Pcurseurallies; - SDL_Surface *Pfondjeu; - SDL_Surface *Pnbdegats; - SDL_Surface *Pcadrecible; - SDL_Surface *Pnomcible; - SDL_Surface *Pactive; - SDL_Surface *Pdesactive; - SDL_Surface *Ppvcible; - SDL_Surface *Ppmcible; - SDL_Surface *Ppvpersos; - SDL_Surface *Ppmpersos; - SDL_Surface *Pcadreactions; - SDL_Surface *Pactionselectionnee; - SDL_Surface *Pactiondesactivee; - SDL_Surface *Pnomactions[3]; - SDL_Surface *Pmort; - SDL_Surface *Pquantite[3]; - SDL_Surface *Pmap_sol; - SDL_Surface *Pmap_mur; - SDL_Surface *Pmap_coffre; - SDL_Surface *Pmap_perso; -}; - -typedef struct positions POSITIONS; -struct positions -{ - SDL_Rect Vpositionmenu; - SDL_Rect Vpositionmenupaladin; - SDL_Rect Vpositionmenuvoleur; - SDL_Rect Vpositionmenupretre; - SDL_Rect Vpositionpersos[3]; - SDL_Rect Vpositionennemis[5]; - SDL_Rect Vpositiontextemenu; - SDL_Rect Vpositioncurseurennemis; - SDL_Rect Vpositioncurseurallies; - SDL_Rect Vpositioncadrecible; - SDL_Rect Vpositionnomcible; - SDL_Rect Vpositionactivedesactive[16]; - SDL_Rect Vpositionpvcible; - SDL_Rect Vpositionpmcible; - SDL_Rect Vpositioncadreactions; - SDL_Rect Vpositionactionselectionnee[3]; - SDL_Rect Vpositionnomactions[3]; - SDL_Rect Vpositionmort; - SDL_Rect Vpositiondegats; - SDL_Rect Vpositionpvpersos[3]; - SDL_Rect Vpositionpmpersos[3]; - SDL_Rect Vpositionquantite[3]; - SDL_Rect Vpositionmap_item[15][11]; -}; - -typedef struct personnages PERSONNAGES; -struct personnages -{ - int classe; - int nv; - int pv; - int pm; - int magie; - int force; - int defense; - int defensemagique; - int xp; - int etat; - int pvinitiaux; - int pminitiaux; -}; - -typedef struct ennemis ENNEMIS; -struct ennemis -{ - int classe; - int pv; - int pm; - int magie; - int force; - int defense; - int defensemagique; - int etat; - int sensibilite[4]; - int resistance[4]; - int invulnerabilite[4]; - int absorbtion[4]; - int pvinitiaux; - int pminitiaux; -}; - -typedef struct objets OBJET; -struct objets -{ - int potions; - int ethers; - int potionsplus; - int ethersplus; -}; - -#endif - +#ifndef STRUCTURES_H +#define STRUCTURES_H + +typedef struct surfaces SURFACES; +struct surfaces +{ + SDL_Surface *Pecran; + SDL_Surface *Pgobelin; + SDL_Surface *Ppaladin; + SDL_Surface *Ppretre; + SDL_Surface *Pvoleur; + SDL_Surface *Pmenuoptions; + SDL_Surface *Pmenujouer; + SDL_Surface *Pmenuquitter; + SDL_Surface *Pchoixpaladin; + SDL_Surface *Pchoixpretre; + SDL_Surface *Pchoixvoleur; + SDL_Surface *Tperso[3]; + SDL_Surface *Tennemi[5]; + SDL_Surface *Ptextechoixmenu; + SDL_Surface *Pcurseurennemis; + SDL_Surface *Pcurseurallies; + SDL_Surface *Pfondjeu; + SDL_Surface *Pnbdegats; + SDL_Surface *Pcadrecible; + SDL_Surface *Pnomcible; + SDL_Surface *Pactive; + SDL_Surface *Pdesactive; + SDL_Surface *Ppvcible; + SDL_Surface *Ppmcible; + SDL_Surface *Ppvpersos; + SDL_Surface *Ppmpersos; + SDL_Surface *Pcadreactions; + SDL_Surface *Pactionselectionnee; + SDL_Surface *Pactiondesactivee; + SDL_Surface *Pnomactions[3]; + SDL_Surface *Pmort; + SDL_Surface *Pquantite[3]; + SDL_Surface *Pmap_sol; + SDL_Surface *Pmap_mur; + SDL_Surface *Pmap_coffre; + SDL_Surface *Pmap_perso; +}; + +typedef struct positions POSITIONS; +struct positions +{ + SDL_Rect Vpositionmenu; + SDL_Rect Vpositionmenupaladin; + SDL_Rect Vpositionmenuvoleur; + SDL_Rect Vpositionmenupretre; + SDL_Rect Vpositionpersos[3]; + SDL_Rect Vpositionennemis[5]; + SDL_Rect Vpositiontextemenu; + SDL_Rect Vpositioncurseurennemis; + SDL_Rect Vpositioncurseurallies; + SDL_Rect Vpositioncadrecible; + SDL_Rect Vpositionnomcible; + SDL_Rect Vpositionactivedesactive[16]; + SDL_Rect Vpositionpvcible; + SDL_Rect Vpositionpmcible; + SDL_Rect Vpositioncadreactions; + SDL_Rect Vpositionactionselectionnee[3]; + SDL_Rect Vpositionnomactions[3]; + SDL_Rect Vpositionmort; + SDL_Rect Vpositiondegats; + SDL_Rect Vpositionpvpersos[3]; + SDL_Rect Vpositionpmpersos[3]; + SDL_Rect Vpositionquantite[3]; + SDL_Rect Vpositionmap_item[15][11]; +}; + +typedef struct personnages PERSONNAGES; +struct personnages +{ + int classe; + int nv; + int pv; + int pm; + int magie; + int force; + int defense; + int defensemagique; + int xp; + int etat; + int pvinitiaux; + int pminitiaux; +}; + +typedef struct ennemis ENNEMIS; +struct ennemis +{ + int classe; + int pv; + int pm; + int magie; + int force; + int defense; + int defensemagique; + int etat; + int sensibilite[4]; + int resistance[4]; + int invulnerabilite[4]; + int absorbtion[4]; + int pvinitiaux; + int pminitiaux; +}; + +typedef struct objets OBJET; +struct objets +{ + int potions; + int ethers; + int potionsplus; + int ethersplus; +}; + +#endif + -- cgit v1.2.3