1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
#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>
static void blit_chr_infos(SURFACES *surfaces, struct character_t *chr)
{
TTF_Font *police=NULL;
SDL_Color fg={132,215,107,0},bg={100,0,0,0};
char string[256];
SDL_Surface *surf_hp;
SDL_Surface *surf_mp;
police=TTF_OpenFont("TIMESBI.TTF",18);
sprintf(string, "PV %d/%d ", chr->hp, chr->max_hp);
surf_hp = TTF_RenderText_Shaded(police, string, fg, bg);
sprintf(string, "PM %d/%d ", chr->mp, chr->max_mp);
surf_mp = TTF_RenderText_Shaded(police, string, fg, bg);
chr->pos_hp.x = chr->pos.x + chr->def_surf->w / 2 - surf_hp->w / 2;
chr->pos_mp.x = chr->pos.x + chr->def_surf->w / 2 - surf_mp->w / 2;
chr->pos_hp.y = chr->pos.y + chr->def_surf->h - surf_hp->h - surf_mp->h;
chr->pos_mp.y = chr->pos_hp.y + surf_mp->h;
SDL_BlitSurface(surf_hp, NULL, surfaces->Pecran, &chr->pos_hp);
SDL_BlitSurface(surf_mp, NULL, surfaces->Pecran, &chr->pos_mp);
chr->pos_hp.w = surf_hp->w;
chr->pos_hp.h = surf_hp->h;
chr->pos_mp.w = surf_mp->w;
chr->pos_mp.h = surf_mp->h;
SDL_FreeSurface(surf_hp);
SDL_FreeSurface(surf_mp);
TTF_CloseFont(police);
}
void blit_character(SURFACES *surfaces, struct character_t *chr)
{
SDL_BlitSurface(chr->surf, NULL, surfaces->Pecran, &chr->pos);
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;
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, struct character_t *chr)
{
SDL_Color couleur={120,0,0,0};
TTF_Font *police=NULL;
const char *string;
if (surfaces->Pnomcible!=NULL)
{
SDL_FreeSurface (surfaces->Pnomcible);
surfaces->Pnomcible=NULL;
}
police=TTF_OpenFont("times.ttf",20);
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);
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;
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);
}
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;
TTF_Font *police=NULL;
SDL_Color couleur={0,0,0,0};
char chaine[3][50];
police=TTF_OpenFont ("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;i<nbactions;i++)
{
if (selection==i)
SDL_BlitSurface (surfaces->Pactionselectionnee,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);
}
static 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];
SDL_Surface *surf;
sprintf(string, "%d", incr);
TTF_SetFontStyle(font, TTF_STYLE_BOLD);
surf = TTF_RenderText_Blended(font, string, color);
blit_character(surfaces, target);
SDL_BlitSurface(surf, NULL, surfaces->Pecran, &target->pos_curs);
positions->Vpositiondegats.x = target->pos_curs.x;
positions->Vpositiondegats.y = target->pos_curs.y;
positions->Vpositiondegats.w = surf->w;
positions->Vpositiondegats.h = surf->h;
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);
}
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);
}
|