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 --- blits.c | 800 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 400 insertions(+), 400 deletions(-) (limited to 'blits.c') 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); +} + + + + + + -- cgit v1.2.3