summaryrefslogtreecommitdiff
path: root/blits.c
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-01-08 02:39:16 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-01-08 02:44:56 +0100
commitc68227406beb7bc74a4179fb1b1b70bbeb6ad4a2 (patch)
treeb390ed5f463c28e7d80f5b446eddac6a6eeaf6e9 /blits.c
parent6d8a9ac6c08e414e8ebb57a6a2ef9b4779d599a7 (diff)
use the new enemy team instead of the old array of ENEMIES
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'blits.c')
-rw-r--r--blits.c221
1 files changed, 147 insertions, 74 deletions
diff --git a/blits.c b/blits.c
index ea57630..e432359 100644
--- a/blits.c
+++ b/blits.c
@@ -8,19 +8,6 @@
#include <SDL/SDL_image.h>
#include <string.h>
-void Fblitterennemis (SURFACES *surfaces, POSITIONS *positions,ENNEMIS ennemis[],int Vnbennemis)
-{
- int i;
-
- /* TODO understand if this is needed or not */
- (void) ennemis;
-
- 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);
-}
-
static void blit_chr_infos(SURFACES *surfaces, struct character_t *chr)
{
TTF_Font *police=NULL;
@@ -55,30 +42,34 @@ static void blit_chr_infos(SURFACES *surfaces, struct character_t *chr)
TTF_CloseFont(police);
}
-void blit_team(SURFACES *surfaces, struct team_t *team)
+void blit_character(SURFACES *surfaces, struct character_t *chr)
{
- for (int i = 0; i < team->chr_cnt; i++) {
- struct character_t *chr = &team->chrs[i];
+ SDL_BlitSurface(chr->surf, NULL, surfaces->Pecran, &chr->pos);
- SDL_BlitSurface(chr->surf, NULL, surfaces->Pecran, &chr->pos);
+ if (!chr->alive) {
+ SDL_Rect pos_dead;
- if (!chr->alive) {
- SDL_Rect pos_dead;
+ pos_dead.x = chr->pos.x + chr->surf->w / 2 - surfaces->Pmort->w / 2;
+ pos_dead.y = chr->pos.y + chr->surf->h / 2 - surfaces->Pmort->h / 2;
- pos_dead.x = chr->pos.x + chr->surf->w / 2 - surfaces->Pmort->w / 2;
- pos_dead.y = chr->pos.y + chr->surf->h / 2 - surfaces->Pmort->h / 2;
+ SDL_BlitSurface(surfaces->Pmort, NULL, surfaces->Pecran, &pos_dead);
+ }
+ blit_chr_infos(surfaces, chr);
+}
- SDL_BlitSurface(surfaces->Pmort, NULL, surfaces->Pecran, &pos_dead);
- }
- blit_chr_infos(surfaces, chr);
+void blit_team(SURFACES *surfaces, struct team_t *team)
+{
+ for (int i = 0; i < team->chr_cnt; i++) {
+ blit_character(surfaces, &team->chrs[i]);
}
}
-void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions,int selection,ENNEMIS ennemis[])
+void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions, struct character_t *chr)
{
SDL_Color couleur={120,0,0,0};
TTF_Font *police=NULL;
- char chaine[100];
+ const char *string;
+
if (surfaces->Pnomcible!=NULL)
{
SDL_FreeSurface (surfaces->Pnomcible);
@@ -86,19 +77,23 @@ void Fchangercurseurennemis (SURFACES *surfaces, POSITIONS *positions,int select
}
police=TTF_OpenFont("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;
+
+ 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);
+
+ string = (chr->name) ? chr->name : "NO NAME";
+
+ surfaces->Pnomcible = TTF_RenderText_Blended (police, string, 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);
+
+ blit_character_affinities(surfaces, positions, chr);
+
+ Fblitterpvcible (surfaces,positions, chr);
+ Fblitterpmcible (surfaces,positions, chr);
SDL_BlitSurface (surfaces->Pnomcible,NULL,surfaces->Pecran,&positions->Vpositionnomcible);
SDL_Flip (surfaces->Pecran);
TTF_CloseFont(police);
@@ -212,6 +207,99 @@ void Fchangeractionselectionnee(SURFACES *surfaces, POSITIONS *positions,int sel
TTF_CloseFont (police);
}
+static void incr_hp(SURFACES *surfaces, struct character_t *target, int incr)
+{
+ TTF_Font *font = TTF_OpenFont("TIMES.TTF", 30);
+ char string[256];
+ SDL_Color color;
+ SDL_Surface *surf;
+ SDL_Rect pos;
+ int incr_abs;
+
+ target->hp -= incr;
+
+ if (target->hp <= 0) {
+ target->hp = 0;
+ target->alive = true;
+ } 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};
+
+ incr_abs = (incr >= 0) ? incr : -incr;
+
+ sprintf(string, "%d", incr_abs);
+
+ TTF_SetFontStyle(font, TTF_STYLE_BOLD);
+ surf = TTF_RenderText_Blended(font, string, color);
+
+ pos.x = target->pos.x + target->surf->w + 20;
+ pos.y = target->pos.y + target->surf->h / 2 - surf->h / 2;
+
+ blit_character(surfaces, target);
+ SDL_BlitSurface(surf, NULL, surfaces->Pecran, &pos);
+
+ SDL_FreeSurface(surf);
+ TTF_CloseFont(font);
+}
+
+static void incr_mp(SURFACES *surfaces, struct character_t *target, int incr)
+{
+ TTF_Font *font = TTF_OpenFont("TIMES.TTF", 30);
+ char string[256];
+ SDL_Color color;
+ SDL_Surface *surf;
+ SDL_Rect pos;
+ int incr_abs;
+
+ 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};
+
+ incr_abs = (incr >= 0) ? incr : -incr;
+
+ sprintf(string, "%d", incr_abs);
+
+ TTF_SetFontStyle(font, TTF_STYLE_BOLD);
+ surf = TTF_RenderText_Blended(font, string, color);
+
+ pos.x = target->pos.x + target->surf->w + 20;
+ pos.y = target->pos.y + target->surf->h / 2 - surf->h / 2;
+
+ blit_character(surfaces, target);
+ SDL_BlitSurface(surf, NULL, surfaces->Pecran, &pos);
+
+ SDL_FreeSurface(surf);
+ TTF_CloseFont(font);
+}
+
+void damage_target_hp(SURFACES *surfaces, struct character_t *target, int damages)
+{
+ incr_hp(surfaces, target, -damages);
+}
+
+void cure_target_hp(SURFACES *surfaces, struct character_t *target, int cure)
+{
+ incr_hp(surfaces, target, cure);
+}
+
+void damage_target_mp(SURFACES *surfaces, struct character_t *target, int damages)
+{
+ incr_mp(surfaces, target, -damages);
+}
+
+void cure_target_mp(SURFACES *surfaces, struct character_t *target, int cure)
+{
+ incr_mp(surfaces, target, cure);
+}
+
void Fafficherdegats (SURFACES *surfaces, POSITIONS *positions, int degats,int clan, int cible, struct team_t *ally)
{
char chaine[10];
@@ -283,41 +371,27 @@ void Faffichersoins (SURFACES *surfaces, POSITIONS *positions, int degats,int cl
TTF_CloseFont (police);
}
-void Fblitteractivedesactive (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection)
+void blit_character_affinities(SURFACES *surfaces, POSITIONS *positions, const struct character_t *chr)
{
- 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]);
+ static const enum affinity_t affinities[] = {
+ AFFINITY_SENSITIVE,
+ AFFINITY_RESISTANCE,
+ AFFINITY_INVULNERABILITY,
+ AFFINITY_ABSORPTION,
+ };
+
+ for (enum element_t elmt = 0; elmt < ELEMENT_COUNT; ++elmt) {
+ for (int i = 0; i < countof(affinities); ++i) {
+ if (chr->affinities[elmt] == affinities[i]) {
+ SDL_BlitSurface (surfaces->Pactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i + elmt * countof(affinities)]);
+ } else {
+ SDL_BlitSurface (surfaces->Pdesactive,NULL,surfaces->Pecran,&positions->Vpositionactivedesactive[i + elmt * countof(affinities)]);
+ }
+ }
}
}
-void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],int selection)
+void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *chr)
{
TTF_Font *police = NULL;
SDL_Color couleur = {132,215,107,0};
@@ -328,16 +402,15 @@ void Fblitterpvcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],
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);
+
+ 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,ENNEMIS ennemis[],int selection)
+void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions, const struct character_t *chr)
{
TTF_Font *police = NULL;
SDL_Color couleur = {132,215,107,0};
@@ -348,7 +421,7 @@ void Fblitterpmcible (SURFACES *surfaces,POSITIONS *positions,ENNEMIS ennemis[],
SDL_FreeSurface (surfaces->Ppmcible);
surfaces->Ppmcible=NULL;
}
- sprintf (chaine,"%d/%d",ennemis[selection].pm,ennemis[selection].pminitiaux);
+ 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);