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
|
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include "structures.h"
#include "constantes.h"
#include "prototypes.h"
enum action_state_t Fmagieelement (SURFACES *surfaces,POSITIONS *positions, struct team_t *ally, ENNEMIS ennemis[],int Vnbennemis, int element)
{
enum action_state_t ret = ACTION_CANCELED;
int max;
int min;
unsigned int continuer = 1;
int degats;
int selection = 0;
int delay=1;
unsigned int Bdegats=DEGATS;
int clan=ENNEMI;
SDL_Event event;
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
while(ennemis[selection].etat==MORT)
selection++;
Fchangercurseurennemis (surfaces,positions,selection,ennemis);
while (continuer)
{
SDL_Flip (surfaces->Pecran);
SDL_WaitEvent (&event);
switch (event.type)
{
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
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;
SELECTION_CIBLE()
case SDLK_RETURN:
case SDLK_f:
continuer=0;
max=Fcalculerdegats(ally, &min,ennemis,selection,clan,TYPE_MAGIE);
degats=(rand()%(max-min+1))+min;
if(degats<0)
degats=0;
if(element!=NON_ELEMENTAIRE)
{
if (ennemis[selection].resistance[element]==ACTIVE)
degats/=2;
else if(ennemis[selection].sensibilite[element]==ACTIVE)
degats*=2;
else if(ennemis[selection].invulnerabilite[element]==ACTIVE)
degats=0;
else if(ennemis[selection].absorbtion[element]==ACTIVE)
inverse_boolean(Bdegats);
}
if(clan==ENNEMI)
{
if(Bdegats==DEGATS)
ennemis[selection].pv-=degats;
else
ennemis[selection].pv+=degats;
if(ennemis[selection].pv<=0)
{
ennemis[selection].pv=0;
ennemis[selection].etat=MORT;
positions->Vpositionmort.x=positions->Vpositionennemis[selection].x+surfaces->Tennemi[selection]->w/2-surfaces->Pmort->w/2;
positions->Vpositionmort.y=positions->Vpositionennemis[selection].y+surfaces->Tennemi[selection]->h/2-surfaces->Pmort->h/2;
SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort);
}
else if(ennemis[selection].pv>ennemis[selection].pvinitiaux)
ennemis[selection].pv=ennemis[selection].pvinitiaux;
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);
}
else
{
struct character_t *chr = &ally->chrs[selection];
if(Bdegats==DEGATS)
chr->hp-=degats;
else
chr->hp+=degats;
if(chr->hp<=0)
{
chr->hp=0;
chr->alive = false;
positions->Vpositionmort.x=positions->Vpositionpersos[selection].x+surfaces->Tperso[selection]->w/2-surfaces->Pmort->w/2;
positions->Vpositionmort.y=positions->Vpositionpersos[selection].y+surfaces->Tperso[selection]->h/2-surfaces->Pmort->h/2;
SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort);
}
else if(chr->hp>chr->max_hp)
chr->hp=chr->max_hp;
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);
}
if(Bdegats==DEGATS)
Fafficherdegats (surfaces,positions,degats,clan,selection, ally);
else
Faffichersoins (surfaces,positions,degats,clan,selection, ally);
if(clan==ENNEMI)
{
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
SDL_Flip (surfaces->Pecran);
}
ret = ACTION_PERFORMED;
break;
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, ENNEMIS ennemis[],int Vnbennemis)
{
enum action_state_t ret = ACTION_CANCELED;
unsigned int continuer=1;
SDL_Event event;
int max;
int min;
int soins;
int clan=ALLIE;
int delay=1;
int selection=0;
int Bdegats=SOINS;
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadreactions,surfaces->Pecran,&positions->Vpositioncadreactions);
while(!ally->chrs[selection].alive)
selection++;
Fchangercurseurpersos (surfaces,positions,selection);
while(continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
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;
SELECTION_CIBLE()
case SDLK_RETURN:
case SDLK_f:
max=Fcalculersoins(ally, &min,ennemis,selection);
soins=(rand()%(max-min+1))+min;
if(soins<0)
soins=0;
if(clan==ENNEMI)
{
if(Bdegats==DEGATS)
ennemis[selection].pv-=soins;
else
ennemis[selection].pv+=soins;
if(ennemis[selection].pv<=0)
{
ennemis[selection].pv=0;
ennemis[selection].etat=MORT;
positions->Vpositionmort.x=positions->Vpositionennemis[selection].x+surfaces->Tennemi[selection]->w/2-surfaces->Pmort->w/2;
positions->Vpositionmort.y=positions->Vpositionennemis[selection].y+surfaces->Tennemi[selection]->h/2-surfaces->Pmort->h/2;
SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort);
}
else if(ennemis[selection].pv>ennemis[selection].pvinitiaux)
ennemis[selection].pv=ennemis[selection].pvinitiaux;
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurennemis,surfaces->Pecran,&positions->Vpositioncurseurennemis);
}
else
{
if(Bdegats==DEGATS)
ally->chrs[selection].hp-=soins;
else
ally->chrs[selection].hp+=soins;
if(ally->chrs[selection].hp<=0)
{
ally->chrs[selection].hp=0;
ally->chrs[selection].alive = false;
positions->Vpositionmort.x=positions->Vpositionpersos[selection].x+surfaces->Tperso[selection]->w/2-surfaces->Pmort->w/2;
positions->Vpositionmort.y=positions->Vpositionpersos[selection].y+surfaces->Tperso[selection]->h/2-surfaces->Pmort->h/2;
SDL_BlitSurface(surfaces->Pmort,NULL,surfaces->Pecran,&positions->Vpositionmort);
}
else if(ally->chrs[selection].hp>ally->chrs[selection].max_hp)
ally->chrs[selection].hp=ally->chrs[selection].max_hp;
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncurseurallies,surfaces->Pecran,&positions->Vpositioncurseurallies);
}
if(Bdegats==DEGATS)
Fafficherdegats (surfaces,positions,soins,clan,selection, ally);
else
Faffichersoins (surfaces,positions,soins,clan,selection, ally);
if(clan==ENNEMI)
{
SDL_BlitSurface (surfaces->Pfondjeu,&positions->Vpositioncadrecible,surfaces->Pecran,&positions->Vpositioncadrecible);
SDL_Flip (surfaces->Pecran);
}
ret = ACTION_PERFORMED;
continuer=0;
break;
default:
break;
}
break;
}
}
if (delay)
SDL_Delay(1000);
SDL_BlitSurface(surfaces->Pfondjeu,&positions->Vpositiondegats,surfaces->Pecran,&positions->Vpositiondegats);
SDL_Flip(surfaces->Pecran);
return ret;
}
int Fcalculersoins(struct team_t *ally, int *min,ENNEMIS ennemis[],int selection)
{
unsigned int soins;
int max;
int taux;
/* TODO understand why these variables were passed to the function */
(void) ennemis;
(void) selection;
soins=ally->chrs[ally->chr_cur].magic*20;
taux=soins/4;
max=soins+taux;
*min=soins-taux;
return max;
}
|