diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2015-01-08 19:45:03 +0100 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2015-01-08 19:45:03 +0100 |
commit | bfdf279cac51fe8945e59cd566cba2cb2efcffce (patch) | |
tree | c2310a297cb9d48814009142ea92cc31bd787fee | |
parent | fc3baf853b4429cf012f6d77b43d74872dc5ca11 (diff) |
move some functions and headers so that the compilation is quicker
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r-- | actions.c | 9 | ||||
-rw-r--r-- | blits.c | 181 | ||||
-rw-r--r-- | blits.h | 16 | ||||
-rw-r--r-- | character.c | 58 | ||||
-rw-r--r-- | character.h | 12 | ||||
-rw-r--r-- | jouer.c | 5 | ||||
-rw-r--r-- | priv_entries.h | 2 | ||||
-rw-r--r-- | prototypes.h | 21 |
8 files changed, 159 insertions, 145 deletions
@@ -1,9 +1,10 @@ -#include <SDL/SDL.h> +#include <stdlib.h> + #include "structures.h" + #include "constantes.h" -#include "prototypes.h" -#include <stdio.h> -#include <stdlib.h> + +#include "character.h" static int compute_damages(const struct character_t *src, const struct character_t *dest, enum damages_type_t type, enum element_t element) @@ -1,13 +1,15 @@ #include <stdlib.h> #include <stdio.h> #include <SDL/SDL.h> -#include "structures.h" -#include "constantes.h" -#include "prototypes.h" #include <SDL/SDL_ttf.h> #include <SDL/SDL_image.h> #include <string.h> +#include "constantes.h" + +#include "players.h" +#include "entry.h" + static void blit_chr_infos(SURFACES *surfaces, struct character_t *chr) { TTF_Font *police=NULL; @@ -64,6 +66,65 @@ void blit_team(SURFACES *surfaces, struct team_t *team) } } +static void blit_character_affinities(SURFACES *surfaces, POSITIONS *positions, const struct character_t *chr) +{ + static const enum affinity_t affinities[] = { + AFFINITY_SENSITIVE, + AFFINITY_RESISTANCE, + AFFINITY_INVULNERABILITY, + AFFINITY_ABSORPTION, + }; + + for (int i = 0; i < countof(affinities); ++i) { + for (enum element_t elmt = 0; elmt < ELEMENT_COUNT; ++elmt) { + if (chr->affinities[elmt] == affinities[i]) { + SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i * ELEMENT_COUNT + elmt]); + } else { + SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i * ELEMENT_COUNT + elmt]); + } + } + } +} + +static +void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *chr) +{ + 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; + } + + sprintf (chaine,"%d/%d", chr->hp, chr->max_hp); + police=TTF_OpenFont ("TIMESBI.TTF",18); + surfaces->Ppvcible=TTF_RenderText_Blended (police,chaine,couleur); + SDL_BlitSurface (surfaces->Ppvcible,NULL,surfaces->Pecran,&positions->Vpositionpvcible); + TTF_CloseFont (police); +} + +static +void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *chr) +{ + TTF_Font *police = NULL; + SDL_Color couleur = {132,215,107,0}; + char chaine[50]; + + if (surfaces->Ppmcible != NULL) + { + SDL_FreeSurface (surfaces->Ppmcible); + surfaces->Ppmcible=NULL; + } + sprintf (chaine,"%d/%d", chr->mp, chr->max_mp); + police=TTF_OpenFont ("TIMESBI.TTF",18); + surfaces->Ppmcible=TTF_RenderText_Blended (police,chaine,couleur); + SDL_BlitSurface (surfaces->Ppmcible,NULL,surfaces->Pecran,&positions->Vpositionpmcible); + TTF_CloseFont (police); +} + static void display_target_infos(SURFACES *surfaces, POSITIONS *positions, struct character_t *chr) { SDL_Color color = {0x8a, 0x00, 0x00, 0x00}; @@ -155,7 +216,7 @@ void update_list_entries(SURFACES *surfaces, POSITIONS *positions, const struct SDL_Flip(surfaces->Pecran); } -static void display_incr(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, unsigned int incr, SDL_Color color) +void display_incr(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, unsigned int incr, SDL_Color color) { TTF_Font *font = TTF_OpenFont("TIMES.TTF", 30); char string[256]; @@ -177,115 +238,3 @@ static void display_incr(SURFACES *surfaces, POSITIONS *positions, struct charac SDL_FreeSurface(surf); TTF_CloseFont(font); } - -static void incr_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int incr) -{ - SDL_Color color; - - target->hp += incr; - - if (target->hp <= 0) { - target->hp = 0; - target->alive = false; - } else if (target->hp > target->max_hp) { - target->hp = target->max_hp; - } - - color = (incr < 0) ? (SDL_Color){0xe0, 0x00, 0x00, 0x00} : (SDL_Color){0x00, 0xe0, 0x00, 0x00}; - - display_incr(surfaces, positions, target, (incr >= 0) ? incr : -incr, color); -} - -static void incr_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int incr) -{ - SDL_Color color; - - target->hp += incr; - - if (target->mp <= 0) { - target->mp = 0; - } else if (target->mp > target->max_mp) { - target->mp = target->max_mp; - } - - color = (incr < 0) ? (SDL_Color){0xe0, 0x00, 0x00, 0x00} : (SDL_Color){0x00, 0xe0, 0x00, 0x00}; - - display_incr(surfaces, positions, target, (incr >= 0) ? incr : -incr, color); -} - -void damage_target_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int damages) -{ - incr_hp(surfaces, positions, target, -damages); -} - -void cure_target_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int cure) -{ - incr_hp(surfaces, positions, target, cure); -} - -void damage_target_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int damages) -{ - incr_mp(surfaces, positions, target, -damages); -} - -void cure_target_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int cure) -{ - incr_mp(surfaces, positions, target, cure); -} - -void blit_character_affinities(SURFACES *surfaces, POSITIONS *positions, const struct character_t *chr) -{ - static const enum affinity_t affinities[] = { - AFFINITY_SENSITIVE, - AFFINITY_RESISTANCE, - AFFINITY_INVULNERABILITY, - AFFINITY_ABSORPTION, - }; - - for (int i = 0; i < countof(affinities); ++i) { - for (enum element_t elmt = 0; elmt < ELEMENT_COUNT; ++elmt) { - if (chr->affinities[elmt] == affinities[i]) { - SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i * ELEMENT_COUNT + elmt]); - } else { - SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i * ELEMENT_COUNT + elmt]); - } - } - } -} - -void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *chr) -{ - 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; - } - - sprintf (chaine,"%d/%d", chr->hp, chr->max_hp); - police=TTF_OpenFont ("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, const struct character_t *chr) -{ - TTF_Font *police = NULL; - SDL_Color couleur = {132,215,107,0}; - char chaine[50]; - - if (surfaces->Ppmcible != NULL) - { - SDL_FreeSurface (surfaces->Ppmcible); - surfaces->Ppmcible=NULL; - } - sprintf (chaine,"%d/%d", chr->mp, chr->max_mp); - police=TTF_OpenFont ("TIMESBI.TTF",18); - surfaces->Ppmcible=TTF_RenderText_Blended (police,chaine,couleur); - SDL_BlitSurface (surfaces->Ppmcible,NULL,surfaces->Pecran,&positions->Vpositionpmcible); - TTF_CloseFont (police); -} @@ -0,0 +1,16 @@ +#ifndef BLITS_H +#define BLITS_H + +#include <SDL/SDL.h> +#include "players.h" +#include "entry.h" + +void display_incr(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, unsigned int incr, SDL_Color color); + +void blit_team(SURFACES *surfaces, struct team_t *team); + +void blit_character(SURFACES *surfaces, struct character_t *chr); +void update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct character_t *chr); +void update_list_entries(SURFACES *surfaces, POSITIONS *positions, const struct entry_t *entries, int cnt, int selected); + +#endif /* BLITS_H */ diff --git a/character.c b/character.c new file mode 100644 index 0000000..4a3a260 --- /dev/null +++ b/character.c @@ -0,0 +1,58 @@ +#include <SDL/SDL.h> +#include "players.h" +#include "blits.h" + +static void incr_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int incr) +{ + SDL_Color color; + + target->hp += incr; + + if (target->hp <= 0) { + target->hp = 0; + target->alive = false; + } else if (target->hp > target->max_hp) { + target->hp = target->max_hp; + } + + color = (incr < 0) ? (SDL_Color){0xe0, 0x00, 0x00, 0x00} : (SDL_Color){0x00, 0xe0, 0x00, 0x00}; + + display_incr(surfaces, positions, target, (incr >= 0) ? incr : -incr, color); +} + +static void incr_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int incr) +{ + SDL_Color color; + + target->hp += incr; + + if (target->mp <= 0) { + target->mp = 0; + } else if (target->mp > target->max_mp) { + target->mp = target->max_mp; + } + + color = (incr < 0) ? (SDL_Color){0xe0, 0x00, 0x00, 0x00} : (SDL_Color){0x00, 0xe0, 0x00, 0x00}; + + display_incr(surfaces, positions, target, (incr >= 0) ? incr : -incr, color); +} + +void damage_target_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int damages) +{ + incr_hp(surfaces, positions, target, -damages); +} + +void cure_target_hp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int cure) +{ + incr_hp(surfaces, positions, target, cure); +} + +void damage_target_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int damages) +{ + incr_mp(surfaces, positions, target, -damages); +} + +void cure_target_mp(SURFACES *surfaces, POSITIONS *positions, struct character_t *target, int cure) +{ + incr_mp(surfaces, positions, target, cure); +} diff --git a/character.h b/character.h new file mode 100644 index 0000000..3fba9c7 --- /dev/null +++ b/character.h @@ -0,0 +1,12 @@ +#ifndef CHARACTER_H +#define CHARACTER_H + +#include "players.h" + +void damage_target_hp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int damages); +void cure_target_hp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int cure); + +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); + +#endif /* CHARACTER_H */ @@ -1,9 +1,8 @@ -#include <stdlib.h> -#include <stdio.h> #include <SDL/SDL.h> #include "structures.h" #include "constantes.h" -#include "prototypes.h" + +#include "blits.h" #include "priv_entries.h" diff --git a/priv_entries.h b/priv_entries.h index a0fe66e..62fe5f2 100644 --- a/priv_entries.h +++ b/priv_entries.h @@ -1,7 +1,7 @@ #ifndef PRIV_ENTRIES_H #define PRIV_ENTRIES_H -#include "prototypes.h" +#include "actions.h" #include "entry.h" /* TODO general make difference between action / action + and action x */ diff --git a/prototypes.h b/prototypes.h index 089b5f4..79bb5dd 100644 --- a/prototypes.h +++ b/prototypes.h @@ -11,33 +11,12 @@ 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); -void blit_team(SURFACES *surfaces, struct team_t *); -void blit_character(SURFACES *surfaces, struct character_t *); void Finitialisersurfaces (SURFACES *surfaces); int Fchargerimages (SURFACES *surfaces); void Fdechargerimages (SURFACES *surfaces); void Finitialiserpositions (POSITIONS *positions, SURFACES *surfaces); -/* actions */ -void attack(SURFACES *, POSITIONS *, struct character_t *src, struct character_t *dst, void *data); -void cast_element(SURFACES *, POSITIONS *, struct character_t *src, struct character_t *dst, void *data); -void cast_cure(SURFACES *, POSITIONS *, struct character_t *src, struct character_t *dst, void *data); -void use_potion(SURFACES *, POSITIONS *, struct character_t *src, struct character_t *dst, void *data); -void use_ether(SURFACES *, POSITIONS *, struct character_t *src, struct character_t *dst, void *data); - -void damage_target_hp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int damages); -void cure_target_hp(SURFACES *surfaces, POSITIONS *, struct character_t *target, int cure); - -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 update_selected_target(SURFACES *surfaces, POSITIONS *positions, struct character_t *); -void blit_character_affinities(SURFACES *, POSITIONS *, const struct character_t *); -void update_list_entries(SURFACES *surfaces, POSITIONS *positions, const struct entry_t *entries, int cnt, int selected); -void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *); -void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *); - 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); |