From 9a98118c3d9a062b33134e8354620be43ecf3786 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Thu, 8 Jan 2015 06:02:31 +0100 Subject: improve code and fix numerous bugs Signed-off-by: Olivier Gayot --- actions.c | 461 +++++++++++++++++++++++++---------------------------------- blits.c | 77 +++++++--- constantes.h | 20 +-- magies.c | 101 +++++-------- main.c | 2 + prototypes.h | 10 +- structures.h | 2 + 7 files changed, 308 insertions(+), 365 deletions(-) diff --git a/actions.c b/actions.c index b70758a..09fd3af 100644 --- a/actions.c +++ b/actions.c @@ -9,18 +9,15 @@ enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct te { int degats; struct character_t *target; - enum action_state_t ret = ACTION_CANCELED; - unsigned int continuer = 1; int clan=ENNEMI; int selection = 0; SDL_Event event; - int delay=1; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); while(!enemy->chrs[selection].alive) selection++; - Fchangercurseurennemis (surfaces,positions, &enemy->chrs[selection]); - while (continuer) - { + update_selected_target(surfaces, positions, &enemy->chrs[selection]); + + for (;;) { SDL_Flip (surfaces->Pecran); SDL_WaitEvent (&event); switch (event.type) @@ -30,50 +27,39 @@ enum action_state_t Fattaquer(SURFACES *surfaces,POSITIONS *positions, struct te { case SDLK_ESCAPE: case SDLK_a: - 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() + update_selected_target(surfaces, positions, NULL); + SDL_Flip(surfaces->Pecran); + return ACTION_CANCELED; + SELECTION_CIBLE(); case SDLK_RETURN: case SDLK_f: - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); + if (clan == ENNEMI) { + target = &enemy->chrs[selection]; + } else { + target = &ally->chrs[selection]; + } - if (clan == ENNEMI) { - target = &enemy->chrs[selection]; - } else { - target = &ally->chrs[selection]; - } + degats = compute_damages(&ally->chrs[ally->chr_cur], target, DAMAGES_PHYSICAL, ELEMENT_NONE); - degats = compute_damages(&ally->chrs[ally->chr_cur], target, DAMAGES_PHYSICAL, ELEMENT_NONE); + update_selected_target(surfaces, positions, NULL); damage_target_hp(surfaces, positions, target, degats); + SDL_Flip(surfaces->Pecran); - SDL_Flip(surfaces->Pecran); + SDL_Delay(1000); - ret = ACTION_PERFORMED; - continuer=0; - break; + SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats); + + SDL_Flip(surfaces->Pecran); + + return ACTION_PERFORMED; default: - break; + break; } break; } } - if (delay) - SDL_Delay(1000); - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip(surfaces->Pecran); - - return ret; } int compute_damages(const struct character_t *src, const struct character_t *dest, @@ -93,6 +79,9 @@ int compute_damages(const struct character_t *src, const struct character_t *des avg = src->magic * 60 - dest->spirit * 50; } + if (avg <= 0) + return 0; + if (element != ELEMENT_NONE) { switch (dest->affinities[element]) { case AFFINITY_SENSITIVE: @@ -117,33 +106,6 @@ int compute_damages(const struct character_t *src, const struct character_t *des return rand() % (max - min + 1) + min; } -int Fcalculerdegats(struct team_t *ally, 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=ally->chrs[ally->chr_cur].strength*60-ennemis[selection].defense*50; - else - degats=ally->chrs[ally->chr_cur].strength*60-ally->chrs[selection].defense*50; - } - else - { - if(camp==ENNEMI) - degats=ally->chrs[ally->chr_cur].magic*60-ennemis[selection].defensemagique*50; - else - degats=ally->chrs[ally->chr_cur].magic*60-ally->chrs[selection].spirit*50; - } - taux=degats/4; - max=degats+taux; - *min=degats-taux; - - return max; -} - enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy) { SDL_Event event; @@ -160,44 +122,44 @@ enum action_state_t Fselectionnermagienoire(SURFACES *surfaces,POSITIONS *positi switch (event.type) { case SDL_KEYDOWN: - switch (event.key.keysym.sym) - { - case SDLK_a: - case SDLK_ESCAPE: - continuer=0; - break; - case SDLK_k: - 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_j: - 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_f: - case SDLK_RETURN: - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip(surfaces->Pecran); - ret = Fmagieelement(surfaces,positions, ally, enemy, selection); + switch (event.key.keysym.sym) + { + case SDLK_a: + case SDLK_ESCAPE: + continuer=0; + break; + case SDLK_k: + 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_j: + 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_f: + case SDLK_RETURN: + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); + SDL_Flip(surfaces->Pecran); + ret = Fmagieelement(surfaces,positions, ally, enemy, selection); - if (ret == ACTION_PERFORMED) { - continuer = 0; - } + if (ret == ACTION_PERFORMED) { + continuer = 0; + } - break; - default: - break; - } + break; + default: + break; + } } } @@ -220,44 +182,44 @@ enum action_state_t Fselectionnermagieblanche(SURFACES *surfaces,POSITIONS *posi switch (event.type) { case SDL_KEYDOWN: - switch (event.key.keysym.sym) - { - case SDLK_ESCAPE: - case SDLK_a: - continuer=0; - break; - case SDLK_UP: - case SDLK_k: - if (selection!=0) - selection--; - else - selection=nbactions-1; - page=selection/3; - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_BLANCHE,NULL); - break; - case SDLK_DOWN: - case SDLK_j: - if(selection!=nbactions-1) - selection++; - else - selection=0; - page=selection/3; - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_BLANCHE,NULL); - break; - case SDLK_f: - case SDLK_RETURN: - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip(surfaces->Pecran); - if(selection==SOIN) - ret = Fmagiesoin(surfaces,positions, ally, enemy); + switch (event.key.keysym.sym) + { + case SDLK_ESCAPE: + case SDLK_a: + continuer=0; + break; + case SDLK_UP: + case SDLK_k: + if (selection!=0) + selection--; + else + selection=nbactions-1; + page=selection/3; + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_BLANCHE,NULL); + break; + case SDLK_DOWN: + case SDLK_j: + if(selection!=nbactions-1) + selection++; + else + selection=0; + page=selection/3; + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,MAGIE_BLANCHE,NULL); + break; + case SDLK_f: + case SDLK_RETURN: + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); + SDL_Flip(surfaces->Pecran); + if(selection==SOIN) + ret = Fmagiesoin(surfaces,positions, ally, enemy); - if (ret == ACTION_PERFORMED) { - continuer = 0; - } - break; - default: - break; - } + if (ret == ACTION_PERFORMED) { + continuer = 0; + } + break; + default: + break; + } } } @@ -280,58 +242,58 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, switch (event.type) { case SDL_KEYDOWN: - switch (event.key.keysym.sym) - { - case SDLK_ESCAPE: - case SDLK_a: - continuer=0; - break; - case SDLK_UP: - case SDLK_k: - if(selection!=0) - selection--; - else - selection=nbactions-1; - page=selection/3; - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS, &ally->objects); - break; - case SDLK_DOWN: - case SDLK_j: - if (selection!=nbactions-1) - selection++; - else - selection=0; - page=selection/3; - Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS, &ally->objects); - break; - case SDLK_RETURN: - case SDLK_f: - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip(surfaces->Pecran); - if(page==0) + switch (event.key.keysym.sym) { - if(selection==POTION) - ret = Fpotion(surfaces,positions, ally, enemy, &ally->objects,selection); - else if(selection==ETHER) - ret = Fether(surfaces,positions, ally, enemy, &ally->objects,selection); - else if(selection==POTIONPLUS) - ret = Fpotion(surfaces,positions, ally, enemy, &ally->objects,selection); + case SDLK_ESCAPE: + case SDLK_a: + continuer=0; + break; + case SDLK_UP: + case SDLK_k: + if(selection!=0) + selection--; + else + selection=nbactions-1; + page=selection/3; + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS, &ally->objects); + break; + case SDLK_DOWN: + case SDLK_j: + if (selection!=nbactions-1) + selection++; + else + selection=0; + page=selection/3; + Fchangeractionselectionnee(surfaces,positions,selection,page,nbactions,OBJETS, &ally->objects); + break; + case SDLK_RETURN: + case SDLK_f: + SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); + SDL_Flip(surfaces->Pecran); + if(page==0) + { + if(selection==POTION) + ret = Fpotion(surfaces,positions, ally, enemy, &ally->objects,selection); + else if(selection==ETHER) + ret = Fether(surfaces,positions, ally, enemy, &ally->objects,selection); + else if(selection==POTIONPLUS) + ret = Fpotion(surfaces,positions, ally, enemy, &ally->objects,selection); - } - else if(page==1) - { - if(selection==ETHERPLUS) - ret = Fether(surfaces,positions, ally, enemy, &ally->objects,selection); - } + } + else if(page==1) + { + if(selection==ETHERPLUS) + ret = Fether(surfaces,positions, ally, enemy, &ally->objects,selection); + } - if (ret == ACTION_PERFORMED) { - continuer = 0; - } + if (ret == ACTION_PERFORMED) { + continuer = 0; + } - break; - default: - break; - } + break; + default: + break; + } } } @@ -341,11 +303,8 @@ enum action_state_t Fselectionnerobjet(SURFACES *surfaces,POSITIONS *positions, enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, OBJET *objets,int type) { struct character_t *target; - enum action_state_t ret = ACTION_CANCELED; - int continuer=1; SDL_Event event; int selection=0; - int delay=1; int soins=0; int clan=ALLIE; @@ -357,9 +316,10 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); while (!ally->chrs[selection].alive) selection++; - Fchangercurseurpersos (surfaces,positions,selection); - while(continuer) - { + update_selected_target(surfaces,positions, &ally->chrs[selection]); + SDL_Flip(surfaces->Pecran); + + for (;;) { SDL_WaitEvent(&event); switch(event.type) { @@ -368,66 +328,47 @@ enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team { case SDLK_ESCAPE: case SDLK_a: - 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; + update_selected_target(surfaces, positions, NULL); + SDL_Flip(surfaces->Pecran); + return ACTION_CANCELED; SELECTION_CIBLE(); case SDLK_RETURN: case SDLK_f: - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); - if (clan == ENNEMI) { target = &enemy->chrs[selection]; } else { target = &ally->chrs[selection]; } - if (type == POTION) + update_selected_target(surfaces, positions, NULL); + + if (type == POTION) { soins = 1000; - else if (type == POTIONPLUS) + objets->potions--; + } else if (type == POTIONPLUS) { soins = 4000; + objets->potionsplus--; + } cure_target_hp(surfaces, positions, target, soins); SDL_Flip(surfaces->Pecran); + SDL_Delay(1000); + SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats); - continuer = 0; - ret = ACTION_PERFORMED; - - if (type == POTION) - objets->potions--; - else if (type == POTIONPLUS) - objets->potionsplus--; - break; + return ACTION_PERFORMED; default: break; } break; } } - if (delay) - SDL_Delay(1000); - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip(surfaces->Pecran); - - return ret; } enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, OBJET *objets,int type) { struct character_t *target; - enum action_state_t ret = ACTION_CANCELED; - int continuer=1; SDL_Event event; - int delay=1; int selection=0; int soins=0; int clan=ALLIE; @@ -440,9 +381,10 @@ enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_ SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); while (!ally->chrs[selection].alive) selection++; - Fchangercurseurpersos (surfaces,positions,selection); - while(continuer) - { + update_selected_target(surfaces,positions, &ally->chrs[selection]); + SDL_Flip(surfaces->Pecran); + + for (;;) { SDL_WaitEvent(&event); switch(event.type) { @@ -451,54 +393,37 @@ enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_ { case SDLK_ESCAPE: case SDLK_a: - 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() + update_selected_target(surfaces, positions, NULL); + SDL_Flip(surfaces->Pecran); + return ACTION_CANCELED; + SELECTION_CIBLE(); case SDLK_RETURN: case SDLK_f: - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); - - if (clan == ENNEMI) { - target = &enemy->chrs[selection]; - } else { - target = &ally->chrs[selection]; - } - - if (type == ETHER) - soins = 10; - else if (type == ETHERPLUS) - soins = 40; - - cure_target_mp(surfaces, positions, target, soins); - - SDL_Flip (surfaces->Pecran); - - continuer=0; - ret = ACTION_PERFORMED; - if(type==ETHER) - objets->ethers--; - else if(type==ETHERPLUS) - objets->ethersplus--; - break; + if (clan == ENNEMI) { + target = &enemy->chrs[selection]; + } else { + target = &ally->chrs[selection]; + } + + if (type == ETHER) { + soins = 10; + objets->ethers--; + } else if (type == ETHERPLUS) { + soins = 40; + objets->ethersplus--; + } + + cure_target_mp(surfaces, positions, target, soins); + + SDL_Flip(surfaces->Pecran); + SDL_Delay(1000); + SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats); + + return ACTION_PERFORMED; default: - break; + break; } break; } } - if (delay) - SDL_Delay(1000); - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip(surfaces->Pecran); - - return ret; } diff --git a/blits.c b/blits.c index 23913d8..eff5c4d 100644 --- a/blits.c +++ b/blits.c @@ -64,7 +64,58 @@ void blit_team(SURFACES *surfaces, struct team_t *team) } } -void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions, struct character_t *chr) +static void display_target_infos(SURFACES *surfaces, POSITIONS *positions, struct character_t *chr) +{ + SDL_Color color = {0x8a, 0x00, 0x00, 0x00}; + TTF_Font *font = TTF_OpenFont("times.ttf", 20); + SDL_Surface *surf_name; + SDL_Rect pos_name;; + + /* display the information frame */ + SDL_BlitSurface(surfaces->Pcadrecible, NULL, surfaces->Pecran, &positions->Vpositioncadrecible); + + /* display the name of the character */ + surf_name = TTF_RenderText_Blended(font, chr->name, color); + + pos_name.x = positions->Vpositioncadrecible.x + surfaces->Pcadrecible->w / 2 - surf_name->w / 2; + pos_name.y = positions->Vpositioncadrecible.y + 10; + + /* display the affinities of the character */ + blit_character_affinities(surfaces, positions, chr); + + /* display its HP / MP */ + Fblitterpvcible (surfaces,positions, chr); + Fblitterpmcible (surfaces,positions, chr); + + SDL_BlitSurface(surf_name, NULL, surfaces->Pecran, &pos_name); + + SDL_FreeSurface(surf_name); + TTF_CloseFont(font); +} + +void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct character_t *chr) +{ + /* clear cursor */ + SDL_BlitSurface(surfaces->Pfondjeu, &positions->last_cursor, surfaces->Pecran, &positions->last_cursor); + + if (chr == NULL) { + /* clear the target informations frame */ + SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositioncadrecible, surfaces->Pecran, &positions->Vpositioncadrecible); + } else { + /* display the new cursor */ + positions->last_cursor.x = chr->pos_curs.x; + positions->last_cursor.y = chr->pos_curs.y; + + positions->last_cursor.w = chr->curs->w; + positions->last_cursor.h = chr->curs->h; + + SDL_BlitSurface(chr->curs, NULL, surfaces->Pecran, &chr->pos_curs); + + display_target_infos(surfaces, positions, chr); + } +} + +void Fchangercurseurpersos (SURFACES *surfaces, POSITIONS *positions, struct character_t *chr) { SDL_Color couleur={120,0,0,0}; TTF_Font *police=NULL; @@ -76,12 +127,15 @@ void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions, struct ch surfaces->Pnomcible=NULL; } police=TTF_OpenFont("times.ttf",20); - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); + + SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); SDL_BlitSurface(surfaces->Pcadrecible, NULL, surfaces->Pecran, &positions->Vpositioncadrecible); - positions->Vpositioncurseurennemis.x = chr->pos.x - 20 - surfaces->Pcurseurennemis->w; - positions->Vpositioncurseurennemis.y = chr->pos.y + chr->surf->h / 2 - surfaces->Pcurseurennemis->h / 2; - SDL_BlitSurface(surfaces->Pcurseurennemis, NULL, surfaces->Pecran, &positions->Vpositioncurseurennemis); + + positions->Vpositioncurseurallies.x = chr->pos.x + 20 + chr->surf->w; + positions->Vpositioncurseurallies.y = chr->pos.y + chr->surf->h / 2 - surfaces->Pcurseurallies->h / 2; + + SDL_BlitSurface(surfaces->Pcurseurallies, NULL, surfaces->Pecran, &positions->Vpositioncurseurallies); string = (chr->name) ? chr->name : "NO NAME"; @@ -89,7 +143,6 @@ void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions, struct ch positions->Vpositionnomcible.x = positions->Vpositioncadrecible.x + surfaces->Pcadrecible->w / 2 - surfaces->Pnomcible->w / 2; positions->Vpositionnomcible.y = positions->Vpositioncadrecible.y + 10; - blit_character_affinities(surfaces, positions, chr); Fblitterpvcible (surfaces,positions, chr); @@ -99,18 +152,6 @@ void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions, struct ch TTF_CloseFont(police); } -void Fchangercurseurpersos (SURFACES *surfaces, POSITIONS *positions,int selection) -{ - 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; diff --git a/constantes.h b/constantes.h index d749d37..7e8a897 100644 --- a/constantes.h +++ b/constantes.h @@ -143,8 +143,8 @@ if(clan==ALLIE)\ while(!enemy->chrs[selection].alive) \ selection++;\ inverse_boolean(clan);\ - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);\ - Fchangercurseurennemis (surfaces,positions, &enemy->chrs[selection]);\ + update_selected_target (surfaces,positions, &enemy->chrs[selection]);\ + SDL_Flip(surfaces->Pecran); \ }\ break;\ case SDLK_LEFT:\ @@ -156,8 +156,8 @@ if(clan==ENNEMI)\ while (!ally->chrs[selection].alive)\ selection++;\ inverse_boolean(clan);\ - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);\ - Fchangercurseurpersos(surfaces,positions,selection);\ + update_selected_target(surfaces,positions, &ally->chrs[selection]);\ + SDL_Flip(surfaces->Pecran); \ }\ break;\ case SDLK_UP:\ @@ -175,7 +175,8 @@ if(clan==ENNEMI)\ else\ selection = enemy->chr_cnt;\ }\ - Fchangercurseurennemis (surfaces,positions, &enemy->chrs[selection]);\ + update_selected_target (surfaces,positions, &enemy->chrs[selection]);\ + SDL_Flip(surfaces->Pecran); \ }\ else\ {\ @@ -190,7 +191,8 @@ else\ else\ selection=2;\ }\ - Fchangercurseurpersos(surfaces,positions,selection); \ + update_selected_target(surfaces,positions, &ally->chrs[selection]); \ + SDL_Flip(surfaces->Pecran); \ }\ break;\ case SDLK_DOWN:\ @@ -207,7 +209,8 @@ if(clan==ENNEMI)\ else\ selection=0;\ }\ - Fchangercurseurennemis(surfaces,positions, &enemy->chrs[selection]); \ + update_selected_target(surfaces,positions, &enemy->chrs[selection]); \ + SDL_Flip(surfaces->Pecran); \ }\ else\ {\ @@ -222,7 +225,8 @@ else\ else\ selection=0;\ }\ - Fchangercurseurpersos(surfaces,positions,selection); \ + update_selected_target(surfaces,positions, &ally->chrs[selection]); \ + SDL_Flip(surfaces->Pecran); \ }\ break; diff --git a/magies.c b/magies.c index 13c98eb..3740c84 100644 --- a/magies.c +++ b/magies.c @@ -8,20 +8,17 @@ enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy, enum element_t element) { struct character_t *target; - enum action_state_t ret = ACTION_CANCELED; - unsigned int continuer = 1; int degats; int selection = 0; - int delay=1; int clan=ENNEMI; SDL_Event event; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); while (!enemy->chrs[selection].alive) selection++; - Fchangercurseurennemis (surfaces,positions, &enemy->chrs[selection]); - while (continuer) - { - SDL_Flip (surfaces->Pecran); + update_selected_target(surfaces,positions, &enemy->chrs[selection]); + SDL_Flip(surfaces->Pecran); + + for (;;) { SDL_WaitEvent (&event); switch (event.type) { @@ -30,21 +27,12 @@ enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions, stru { case SDLK_ESCAPE: case SDLK_a: - continuer = 0; - if(clan==ENNEMI) - { - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); - } - else - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); - SDL_Flip (surfaces->Pecran); - break; + update_selected_target(surfaces, positions, NULL); + SDL_Flip(surfaces->Pecran); + return ACTION_CANCELED; SELECTION_CIBLE() case SDLK_RETURN: case SDLK_f: - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); - if (clan == ENNEMI) { target = &enemy->chrs[selection]; } else { @@ -53,43 +41,40 @@ enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions, stru degats = compute_damages(&ally->chrs[ally->chr_cur], target, DAMAGES_MAGICAL, element); + update_selected_target(surfaces, positions, NULL); damage_target_hp(surfaces, positions, target, degats); SDL_Flip(surfaces->Pecran); - ret = ACTION_PERFORMED; - continuer=0; - break; + SDL_Delay(1000); + + SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats); + + SDL_Flip(surfaces->Pecran); + + return ACTION_PERFORMED; default: break; } break; } } - if (delay) - SDL_Delay(1000); - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip(surfaces->Pecran); - - return ret; } enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy) { struct character_t *target; - enum action_state_t ret = ACTION_CANCELED; - unsigned int continuer=1; SDL_Event event; int soins; int clan=ALLIE; - int delay=1; int selection=0; SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions); while(!ally->chrs[selection].alive) selection++; - Fchangercurseurpersos (surfaces,positions,selection); - while(continuer) - { + update_selected_target(surfaces,positions, &ally->chrs[selection]); + SDL_Flip(surfaces->Pecran); + + for (;;) { SDL_WaitEvent(&event); switch(event.type) { @@ -98,47 +83,39 @@ enum action_state_t Fmagiesoin(SURFACES *surfaces,POSITIONS *positions, struct t { case SDLK_ESCAPE: case SDLK_a: - continuer = 0; - if(clan==ENNEMI) - { - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis); - } - else - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies); - SDL_Flip (surfaces->Pecran); - break; + update_selected_target(surfaces, positions, NULL); + SDL_Flip (surfaces->Pecran); + return ACTION_CANCELED; SELECTION_CIBLE() case SDLK_RETURN: case SDLK_f: - SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible); + if (clan == ENNEMI) { + target = &enemy->chrs[selection]; + } else { + target = &ally->chrs[selection]; + } - if (clan == ENNEMI) { - target = &enemy->chrs[selection]; - } else { - target = &ally->chrs[selection]; - } + soins = compute_cure(&ally->chrs[ally->chr_cur], target); - soins = compute_cure(&ally->chrs[ally->chr_cur], target); + update_selected_target(surfaces, positions, NULL); - cure_target_hp(surfaces, positions, target, soins); + cure_target_hp(surfaces, positions, target, soins); + SDL_Flip(surfaces->Pecran); + + SDL_Delay(1000); + + SDL_BlitSurface(surfaces->Pfondjeu, &positions->Vpositiondegats, surfaces->Pecran, &positions->Vpositiondegats); - SDL_Flip (surfaces->Pecran); - ret = ACTION_PERFORMED; - continuer=0; - break; + SDL_Flip (surfaces->Pecran); + + return ACTION_PERFORMED; default: - break; + break; } break; } } - if (delay) - SDL_Delay(1000); - SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats); - SDL_Flip(surfaces->Pecran); - return ret; } int compute_cure(const struct character_t *src, const struct character_t *dest) diff --git a/main.c b/main.c index acbd749..02a0a9f 100644 --- a/main.c +++ b/main.c @@ -148,6 +148,8 @@ void Finitialiserpositions (POSITIONS *positions, SURFACES *surfaces) z++; } } + + positions->last_cursor = (SDL_Rect){0, 0, 0, 0}; } static void colorize_surface(SDL_Surface *surf, const SDL_PixelFormat *fmt, Uint32 incr) diff --git a/prototypes.h b/prototypes.h index 4e00d01..b871365 100644 --- a/prototypes.h +++ b/prototypes.h @@ -9,7 +9,6 @@ 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 Fremplirpersos2 (SURFACES *surfaces, PERSONNAGES persos[]); int Fjouer(SURFACES *surfaces, POSITIONS *positions, struct team_t *ally, struct team_t *enemy); void blit_team(SURFACES *surfaces, struct team_t *); void blit_character(SURFACES *surfaces, struct character_t *); @@ -18,7 +17,6 @@ void Finitialisersurfaces (SURFACES *surfaces); int Fchargerimages (SURFACES *surfaces); void Fdechargerimages (SURFACES *surfaces); void Finitialiserpositions (POSITIONS *positions, SURFACES *surfaces); -void Finitialiserpositionsennemis (SURFACES *surfaces, POSITIONS *positions,int Vnbennemis); /* actions */ enum action_state_t Fattaquer (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy); @@ -30,8 +28,6 @@ enum action_state_t Fmagiesoin (SURFACES *surfaces,POSITIONS *positions, struct enum action_state_t Fpotion(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy,OBJET *objets,int type); enum action_state_t Fether(SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, struct team_t *enemy,OBJET *objets,int type); -int Fcalculernbennemis (); - int compute_damages(const struct character_t *src, const struct character_t *target, enum damages_type_t, enum element_t); int compute_cure(const struct character_t *src, const struct character_t *target); @@ -41,16 +37,12 @@ void cure_target_hp(SURFACES *surfaces, POSITIONS *, struct character_t *target, void damage_target_mp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int damages); void cure_target_mp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int cure); -void Fchangercurseur (SURFACES *surfaces, POSITIONS *positions,int selection,ENNEMIS ennemis[]); -void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions, struct character_t *); -void Fchangercurseurpersos (SURFACES *surfaces, POSITIONS *positions,int selection); +void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct character_t *); void Fblitteractivedesactive (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection); void blit_character_affinities(SURFACES *, POSITIONS *, const struct character_t *); void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions,int type,OBJET *objets); void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *); void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *); -void Fchangermagienoireselectionnee(SURFACES *surfaces,POSITIONS *positions,int selection,int page,int nbactions); -void Fchangermagieblancheselectionnee(SURFACES *surfaces, POSITIONS *positions,int selection,int page,int nbactions); void Fremplirobjets(OBJET *objets); void Fblitterfond(SURFACES* surfaces); diff --git a/structures.h b/structures.h index b0f5b3b..11a0f76 100644 --- a/structures.h +++ b/structures.h @@ -82,6 +82,8 @@ struct positions SDL_Rect Vpositionpmpersos[3]; SDL_Rect Vpositionquantite[3]; SDL_Rect Vpositionmap_item[15][11]; + + SDL_Rect last_cursor; }; typedef struct ally_t PERSONNAGES; -- cgit v1.2.3