diff options
-rw-r--r-- | blits.c | 25 | ||||
-rw-r--r-- | menuchoixpersos.c | 64 | ||||
-rw-r--r-- | menuprincipal.c | 39 | ||||
-rw-r--r-- | prototypes.h | 2 | ||||
-rw-r--r-- | rpg.c | 122 | ||||
-rw-r--r-- | structures.h | 23 |
6 files changed, 126 insertions, 149 deletions
@@ -88,16 +88,13 @@ void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions, const struct char { SDL_Color couleur = {132,215,107,0}; char chaine[50]; - - if (surfaces->Ppvcible != NULL) - { - SDL_FreeSurface (surfaces->Ppvcible); - surfaces->Ppvcible=NULL; - } + SDL_Surface *surf; sprintf (chaine,"%d/%d", chr->hp, chr->max_hp); - surfaces->Ppvcible=TTF_RenderText_Blended(rpg_g.font, chaine, couleur); - SDL_BlitSurface (surfaces->Ppvcible,NULL,surfaces->Pecran,&positions->Vpositionpvcible); + surf = TTF_RenderText_Blended(rpg_g.font, chaine, couleur); + SDL_BlitSurface(surf, NULL, surfaces->screen, &positions->Vpositionpvcible); + + SDL_FreeSurface(surf); } static @@ -105,15 +102,13 @@ void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions, const struct char { SDL_Color couleur = {132,215,107,0}; char chaine[50]; + SDL_Surface *surf; - if (surfaces->Ppmcible != NULL) - { - SDL_FreeSurface (surfaces->Ppmcible); - surfaces->Ppmcible=NULL; - } sprintf (chaine,"%d/%d", chr->mp, chr->max_mp); - surfaces->Ppmcible=TTF_RenderText_Blended(rpg_g.font, chaine, couleur); - SDL_BlitSurface (surfaces->Ppmcible,NULL,surfaces->Pecran,&positions->Vpositionpmcible); + surf = TTF_RenderText_Blended(rpg_g.font, chaine, couleur); + SDL_BlitSurface(surf, NULL, surfaces->screen, &positions->Vpositionpmcible); + + SDL_FreeSurface(surf); } static void display_target_infos(SURFACES *surfaces, POSITIONS *positions, struct target_t *target) diff --git a/menuchoixpersos.c b/menuchoixpersos.c index 90c36a4..3d55efd 100644 --- a/menuchoixpersos.c +++ b/menuchoixpersos.c @@ -156,6 +156,32 @@ struct team_t *new_enemy_team(SURFACES *surfaces, const struct team_t *ally_team return team; } +static void Fchangersurlignage2(int Vchoix, SURFACES *surfaces, + SDL_Surface *text, POSITIONS *positions) +{ + SDL_Surface *surf; + + if (Vchoix == CLASS_PALADIN) { + surf = surfaces->Pchoixpaladin; + } else if (Vchoix == CLASS_PRIEST) { + surf = surfaces->Pchoixpretre; + } else if (Vchoix == CLASS_THIEF) { + surf = surfaces->Pchoixvoleur; + } else { + abort(); + } + + /* this surface fills the whole screen */ + SDL_BlitSurface(surf, NULL, surfaces->screen, NULL); + + 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(text, NULL, surfaces->screen, &positions->Vpositiontextemenu); + + SDL_Flip (surfaces->Pecran); +} void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) { @@ -180,22 +206,27 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) "Please choose the class of your third character", }; + SDL_Surface *surf; + /* display the background with the selected text */ if (Vchoix == CLASS_PALADIN) { - SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); + surf = surfaces->Pchoixpaladin; } else if (Vchoix == CLASS_PRIEST) { - SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); + surf = surfaces->Pchoixpretre; } else if (Vchoix == CLASS_THIEF) { - SDL_BlitSurface (surfaces->Pchoixvoleur,NULL,surfaces->Pecran,&positions->Vpositionmenu); + surf = surfaces->Pchoixvoleur; } else { abort(); } + SDL_BlitSurface(surf, NULL, surfaces->screen, NULL); + /* display the string associated with the current character number (aka Please choose ...) */ - surfaces->Ptextechoixmenu = TTF_RenderText_Blended(rpg_g.font, strings[Vnbperso], vert); + surf = TTF_RenderText_Blended(rpg_g.font, strings[Vnbperso], vert); + + positions->Vpositiontextemenu.x = surfaces->screen->w / 2 - surf->w / 2; + SDL_BlitSurface(surf, NULL, surfaces->screen, &positions->Vpositiontextemenu); - positions->Vpositiontextemenu.x = surfaces->screen->w / 2 - surfaces->Ptextechoixmenu->w / 2; - SDL_BlitSurface (surfaces->Ptextechoixmenu,NULL,surfaces->Pecran,&positions->Vpositiontextemenu); SDL_BlitSurface (surfaces->Ppretre,NULL,surfaces->Pecran,&positions->Vpositionmenupretre); SDL_BlitSurface (surfaces->Ppaladin,NULL,surfaces->Pecran,&positions->Vpositionmenupaladin); @@ -218,7 +249,7 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) } else { Vchoix = CLASS_THIEF; } - Fchangersurlignage2 (Vchoix,surfaces,positions); + Fchangersurlignage2(Vchoix, surfaces, surf, positions); break; case SDLK_RIGHT: @@ -228,7 +259,7 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) } else { Vchoix = CLASS_PALADIN; } - Fchangersurlignage2 (Vchoix,surfaces,positions); + Fchangersurlignage2(Vchoix, surfaces, surf, positions); break; case SDLK_RETURN: case SDLK_f: @@ -241,6 +272,8 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) break; } } + + SDL_FreeSurface(surf); } SDL_Flip(surfaces->Pecran); @@ -248,18 +281,3 @@ void Fmenuchoixpersos (SURFACES *surfaces, POSITIONS *positions) enemy_team = new_enemy_team(surfaces, ally_team); Fmap(surfaces,positions, ally_team, enemy_team); } - -void Fchangersurlignage2 (int Vchoix, SURFACES *surfaces, POSITIONS *positions) -{ - if (Vchoix == CLASS_PALADIN) - SDL_BlitSurface (surfaces->Pchoixpaladin,NULL,surfaces->Pecran,&positions->Vpositionmenu); - else if (Vchoix == CLASS_PRIEST) - SDL_BlitSurface (surfaces->Pchoixpretre,NULL,surfaces->Pecran,&positions->Vpositionmenu); - else if (Vchoix == CLASS_THIEF) - 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); -} diff --git a/menuprincipal.c b/menuprincipal.c index 51d4732..76dff2f 100644 --- a/menuprincipal.c +++ b/menuprincipal.c @@ -5,12 +5,28 @@ #include "prototypes.h" #include "constantes.h" +static void Fchangersurlignage(int Vmode, SURFACES *surfaces) +{ + SDL_Surface *surf; + + if (Vmode == 0) + surf = surfaces->Pmenujouer; + else if (Vmode == 1) + surf = surfaces->Pmenuoptions; + else if (Vmode == 2) + surf = surfaces->Pmenuquitter; + + SDL_BlitSurface(surf, NULL, surfaces->screen, NULL); + + SDL_Flip(surfaces->screen); +} + 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_BlitSurface(surfaces->Pmenujouer, NULL, surfaces->screen, NULL); SDL_Flip (surfaces->Pecran); while (continuer) { @@ -26,12 +42,12 @@ void Fmenuprincipal (SURFACES *surfaces, POSITIONS *positions) if (Vmode < 2) { Vmode++; - Fchangersurlignage (Vmode,surfaces,positions); + Fchangersurlignage(Vmode, surfaces); } else { Vmode = 0; - Fchangersurlignage (Vmode,surfaces,positions); + Fchangersurlignage(Vmode, surfaces); } break; case SDLK_UP: @@ -39,12 +55,12 @@ void Fmenuprincipal (SURFACES *surfaces, POSITIONS *positions) if (Vmode > 0) { Vmode--; - Fchangersurlignage (Vmode,surfaces,positions); + Fchangersurlignage(Vmode, surfaces); } else { Vmode = 2; - Fchangersurlignage (Vmode,surfaces,positions); + Fchangersurlignage(Vmode, surfaces); } break; case SDLK_RETURN: @@ -53,7 +69,7 @@ void Fmenuprincipal (SURFACES *surfaces, POSITIONS *positions) Vmode = 0; if (continuer) { - SDL_BlitSurface (surfaces->Pmenujouer,NULL,surfaces->Pecran,&positions->Vpositionmenu); + SDL_BlitSurface(surfaces->Pmenujouer, NULL, surfaces->screen, NULL); SDL_Flip (surfaces->Pecran); } break; @@ -65,17 +81,6 @@ void Fmenuprincipal (SURFACES *surfaces, POSITIONS *positions) } } -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; diff --git a/prototypes.h b/prototypes.h index 30baa57..0b34b26 100644 --- a/prototypes.h +++ b/prototypes.h @@ -6,10 +6,8 @@ #include "entry.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); int Fjouer(SURFACES *surfaces, POSITIONS *positions, struct team_t *ally, struct team_t *enemy); Uint32 obtenirPixel(SDL_Surface *surface, int x, int y); @@ -178,9 +178,8 @@ static int rpg_initialize_sprites(void) static void Finitialiserpositions (POSITIONS *positions, const SURFACES *surfaces) { - int i,y=0,z=0; - positions->Vpositionmenu.x = 0; - positions->Vpositionmenu.y = 0; + int y = 0, z = 0; + positions->Vpositionmenupretre.x = surfaces->screen->w / 2 - surfaces->Ppretre->w / 2; positions->Vpositionmenupretre.y = surfaces->screen->h - 20 - surfaces->Ppretre->h; positions->Vpositionmenupaladin.x = positions->Vpositionmenupretre.x/2 - surfaces->Ppaladin->w/2; @@ -188,48 +187,39 @@ static void Finitialiserpositions (POSITIONS *positions, const SURFACES *surface positions->Vpositionmenuvoleur.x = surfaces->screen->w / 4 * 3 - surfaces->Pvoleur->w / 2; positions->Vpositionmenuvoleur.y = surfaces->screen->h - 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 = surfaces->screen->w / 2 - 50 - surfaces->Pcadrecible->w / 2; + positions->Vpositioncadrecible.x = surfaces->screen->w / 2 - surfaces->Pcadrecible->w / 2; positions->Vpositioncadrecible.w = surfaces->Pcadrecible->w; positions->Vpositioncadrecible.h = surfaces->Pcadrecible->h; + positions->Vpositioncadreactions.y = surfaces->screen->h - surfaces->Pcadreactions->h; - positions->Vpositioncadreactions.x = surfaces->screen->w / 2 - 50 - surfaces->Pcadreactions->w / 2; + positions->Vpositioncadreactions.x = surfaces->screen->w / 2 - 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; + positions->Vpositionpvcible.x = positions->Vpositioncadrecible.x + 104; + positions->Vpositionpvcible.y = positions->Vpositioncadrecible.y + 170; + positions->Vpositionpmcible.x = positions->Vpositioncadrecible.x + 269; + positions->Vpositionpmcible.y = positions->Vpositioncadrecible.y + 170; + + for(int 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; } - for (i=0;i < 16;i++) - { - positions->Vpositionactivedesactive[i].x = 471+51*y; - positions->Vpositionactivedesactive[i].y = 101+19*z; - if (y < 3) + for (int i = 0; i < 16; i++) { + positions->Vpositionactivedesactive[i].x = positions->Vpositioncadrecible.x + 202 + 51 * y; + positions->Vpositionactivedesactive[i].y = positions->Vpositioncadrecible.y + 86 + 19 * z; + if (y < 3) { y++; - else - { - y=0; + } else { + y = 0; z++; } } + /* TODO this is pretty uggly .. and we can have multiple cursors as well */ positions->last_cursor = (SDL_Rect){0, 0, 0, 0}; } @@ -286,51 +276,41 @@ static int rpg_init(int width, int height) static void Fdechargerimages(SURFACES *surfaces) { - int i; - - SDL_FreeSurface (surfaces->Pgobelin); + SDL_FreeSurface(surfaces->Pgobelin); SDL_FreeSurface(surfaces->red_warrior_gobelin); - SDL_FreeSurface (surfaces->Ppaladin); - SDL_FreeSurface (surfaces->Ppretre); - SDL_FreeSurface (surfaces->Pvoleur); + SDL_FreeSurface(surfaces->Ppaladin); + SDL_FreeSurface(surfaces->Ppretre); + SDL_FreeSurface(surfaces->Pvoleur); SDL_FreeSurface(surfaces->red_paladin); SDL_FreeSurface(surfaces->red_priest); SDL_FreeSurface(surfaces->red_thief); - 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->Pnomactions[i]); - } - for(i=0;i<3;i++) - { - SDL_FreeSurface (surfaces->Pquantite[i]); - } + 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); } static void rpg_shutdown(void) diff --git a/structures.h b/structures.h index 2c5710e..b26fffa 100644 --- a/structures.h +++ b/structures.h @@ -4,8 +4,7 @@ #include <SDL/SDL.h> typedef struct surfaces SURFACES; -struct surfaces -{ +struct surfaces { SDL_Surface *Pecran; /* deprecated */ SDL_Surface *screen; @@ -32,28 +31,19 @@ struct surfaces SDL_Surface *Pchoixpretre; SDL_Surface *Pchoixvoleur; - SDL_Surface *Ptextechoixmenu; SDL_Surface *Pcurseurennemis; SDL_Surface *Pcurseurallies; SDL_Surface *Pfondjeu; /* deprecated */ SDL_Surface *background; - 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; @@ -61,17 +51,11 @@ struct surfaces }; typedef struct positions POSITIONS; -struct positions -{ - SDL_Rect Vpositionmenu; +struct positions { 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]; @@ -82,9 +66,6 @@ struct positions 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]; SDL_Rect last_cursor; |