2
#include <SDL/SDL_image.h>
5
// ****************************************************************************
6
// ******************************* Tester_Menu ********************************
7
// ****************************************************************************
8
CHXMENU Tester_Menu (SDL_Event *evt, BOOL fQuitter, BOOL fMenu, BOOL fRefaire, BOOL fConseil, JEU *jeu)
13
// Demande de quitter le jeu
14
if (evt->type == SDL_QUIT || (evt->type == SDL_KEYDOWN && evt->key.keysym.sym == SDLK_ESCAPE))
15
if (Questionner (TXT_QSTQUITTER, jeu->police1, jeu->police2, jeu->police3, jeu->ecran))
18
// Place le curseur aux bonnes coordonn�es
19
if (evt->type == SDL_MOUSEMOTION)
23
else if (evt->type == SDL_MOUSEBUTTONDOWN)
29
// R�affiche les textes en alpha blending !
30
for (i = 0; i < 4; i ++)
31
SDL_BlitSurface (jeu->back, &jeu->rMenu[i], jeu->ecran, &jeu->rMenu[i]);
33
// Affiche en opaque le texte sous le curseur
34
if (fQuitter && Dans_Rect (x, y, jeu->rMenu[0]))
35
Afficher_Chaine (jeu->rMenu[0].x, jeu->rMenu[0].y, 0, TXT_QUITTER, jeu->police3, jeu->ecran, jeu->ecran);
36
if (fMenu && Dans_Rect (x, y, jeu->rMenu[1]))
37
Afficher_Chaine (jeu->rMenu[1].x, jeu->rMenu[1].y, 0, TXT_MENU, jeu->police3, jeu->ecran, jeu->ecran);
38
if (fRefaire && Dans_Rect (x, y, jeu->rMenu[2]))
39
Afficher_Chaine (jeu->rMenu[2].x, jeu->rMenu[2].y, 0, TXT_REFAIRE, jeu->police3, jeu->ecran, jeu->ecran);
40
if (fConseil && Dans_Rect (x, y, jeu->rMenu[3]))
41
Afficher_Chaine (jeu->rMenu[3].x, jeu->rMenu[3].y, 0, TXT_CONSEIL, jeu->police3, jeu->ecran, jeu->ecran);
43
SDL_UpdateRects (jeu->ecran, 4, jeu->rMenu);
45
if (evt->type == SDL_MOUSEBUTTONDOWN && evt->button.button == 1) // Clic bouton gauche
47
if (fQuitter && Dans_Rect (x, y, jeu->rMenu[0]))
48
if (Questionner (TXT_QSTQUITTER, jeu->police1, jeu->police2, jeu->police3, jeu->ecran))
50
if (fMenu && Dans_Rect (x, y, jeu->rMenu[1]))
51
if (Questionner (TXT_QSTMENU, jeu->police1, jeu->police2, jeu->police3, jeu->ecran))
53
if (fRefaire && Dans_Rect (x, y, jeu->rMenu[2]))
54
if (Questionner (TXT_QSTREFAIRE, jeu->police1, jeu->police2, jeu->police3, jeu->ecran))
55
{ // Message d'attente
56
Informer (TXT_PATIENTEZ, jeu->police1, jeu->ecran);
59
if (fConseil && Dans_Rect (x, y, jeu->rMenu[3]))
62
SDL_GetMouseState (&x, &y);
63
evt->type = SDL_MOUSEMOTION;
66
SDL_PeepEvents (evt, 1, SDL_ADDEVENT, SDL_MOUSEMOTIONMASK);
73
// ****************************************************************************
74
// ***************************** Afficher_Joueur ******************************
75
// ****************************************************************************
76
void Afficher_Joueur (JOUEUR *j, SDL_Surface *ecran)
78
SDL_Surface *img; // Surface contenant l'animation en cours
79
int n; // Nombre d'images de l'animation en cours
81
// Si l'animation est l'un des 4 d�placements
82
if (j->anim >= COURSB && j->anim <= COURSD)
84
// Place le rectangle source � la bonne position en fonction de l'image � afficher dans l'animation
85
j->src.w = j->imgCours->w / j->nCours;
86
j->src.h = j->imgCours->h / 4;
87
j->src.x = j->src.w * j->frame;
88
j->src.y = j->src.h * j->anim;
89
SDL_BlitSurface (j->imgCours, &j->src, ecran, &j->rect);
93
// Autre type d'animation
96
if (j->anim == LANCE) { img = j->imgLance; n = j->nLance; }
97
if (j->anim == GAGNE) { img = j->imgGagne; n = j->nGagne; }
98
if (j->anim == PERDU) { img = j->imgPerdu; n = j->nPerdu; }
99
if (j->anim == ATTEND) { img = j->imgAttend; n = j->nAttend; }
100
if (j->anim == ATTENDFEU) { img = j->imgAttendFeu; n = j->nAttendFeu; }
102
// Place le rectangle source � la bonne position en fonction de l'image � afficher dans l'animation
103
j->src.w = img->w / n;
105
j->src.x = j->src.w * j->frame;
107
SDL_BlitSurface (img, &j->src, ecran, &j->rect);
112
// ****************************************************************************
113
// ****************************** Secouer_Ecran *******************************
114
// ****************************************************************************
115
void Secouer_Ecran (JOUEUR j[], GRILLE grille, SDL_Surface *ecran)
121
// Rectangle de copie du fond d'�cran
122
fond.x = grille.x1 - (j[0].imgCours->w / j[0].nCours - grille.imgCase->w) / 2 - 16;
123
fond.y = grille.y1 - (j[0].imgCours->h / 4 - grille.imgCase->h) / 2 - 16;
124
fond.w = grille.x2 - grille.x1 + 64;
125
fond.h = grille.y2 - grille.y1 + 64;
126
// Rectangle de copie des cases
127
rect.w = rect.h = grille.tc;
129
// D�place al�atoirement la grille
130
for (i = 0; i <= TREMBLE_NB / TREMBLE_VITESSE; i ++)
132
// D�callage al�atoire
133
xDecal = Alea (-TREMBLE_DECAL, TREMBLE_DECAL);
134
yDecal = Alea (-TREMBLE_DECAL, TREMBLE_DECAL);
135
// Replace la grille � la position de d�part
136
if (i == TREMBLE_NB / TREMBLE_VITESSE) xDecal = yDecal = 0;
139
SDL_BlitSurface (grille.imgFond, &fond, ecran, &fond);
141
// Affiche les cases l� o� il y en a, avec le d�callage du tremblement
142
for (rect.x = grille.x1 + xDecal; rect.x < grille.x2 + xDecal; rect.x += rect.w)
143
for (rect.y = grille.y1 + yDecal; rect.y < grille.y2 + yDecal; rect.y += rect.h)
144
if (grille.c[(rect.x-xDecal-grille.x1)/rect.w][(rect.y-yDecal-grille.y1)/rect.h] != TROU)
145
SDL_BlitSurface (grille.imgCase, NULL, ecran, &rect);
147
// Affiche les joueurs avec le d�callage du tremblement
148
j[0].rect.x += xDecal;
149
j[0].rect.y += yDecal;
150
j[1].rect.x += xDecal;
151
j[1].rect.y += yDecal;
153
Afficher_Joueur (j[0].y <= j[1].y ? &j[0] : &j[1], ecran);
154
Afficher_Joueur (j[0].y <= j[1].y ? &j[1] : &j[0], ecran);
156
// R�tablit les positions des joueurs sans le tremblement
157
j[0].rect.x -= xDecal;
158
j[0].rect.y -= yDecal;
159
j[1].rect.x -= xDecal;
160
j[1].rect.y -= yDecal;
163
SDL_UpdateRects (ecran, 1, &fond);
168
// ****************************************************************************
169
// ******************************** Intemperie ********************************
170
// ****************************************************************************
171
BOOL Intemperie (JOUEUR j[], GRILLE *grille, JEU *jeu, CHXMENU *chxmenu)
173
SDL_Rect src, dest, prec; // Rectangles pour la copie d'image
174
int xDep, yDep; // Coordonn�es o� la boule d�colle
175
int xDest, yDest; // Coordonn�es o� la boule s'�crase
176
int x, y; // Case � d�truire
177
int n; // Anime � utiliser (celle du j1 ou du j2)
178
int frame = 0; // Image courante dans l'animation de la boule
179
int alpha; // Transparence de l'animation
180
BOOL monte = OUI; // La boule de feu monte ou descend ?
181
SDL_Event evt; // Pour d�tecter un appui sur [ESC]
182
int xSouris, ySouris; // Coords de la souris
185
// Choisit al�atoirement une case de la grille
186
x = Alea (0, grille->xc);
187
y = Alea (0, grille->yc);
189
// V�rifie s'il l'on peut placer le trou
190
if (grille->c[x][y] != VIDE) return NON;
191
grille->c[x][y] = TROU;
193
// Choisit al�atoirement une animation
195
if (n != 0 || n != 1) n = 0;
197
// Choisit al�atoirement le bord de l'�cran d'o� sera lanc� la boule de feu
200
case 0: xDep = Alea (0, jeu->ecran->w - j[n].imgFeu->w / j[n].nFeu);
201
yDep = Alea (0, 2) ? 0 : jeu->ecran->h - j[n].imgFeu->h;
203
case 1: xDep = Alea (0, 2) ? 0 : jeu->ecran->w - j[n].imgFeu->w / j[n].nFeu;
204
yDep = Alea (0, jeu->ecran->h - j[n].imgFeu->h);
206
default: xDep = yDep = 0;
209
// La boule de feu est centr�e au centre de la case � d�truire � l'arriv�e
210
xDest = Case2CoordX (x, *grille) - (j[n].imgFeu->w / j[n].nFeu - grille->imgCase->w) / 2;
211
yDest = Case2CoordY (y, *grille) - (j[n].imgFeu->h - grille->imgCase->h) / 2;
213
// Rectangle sur l'image dans la s�quence d'animation de la boule de feu
214
src.w = dest.w = j[n].imgFeu->w / j[n].nFeu;
215
src.h = dest.h = j[n].imgFeu->h;
219
// Boucle de l'animation tant que toutes l'animation de la boule de feu n'a pas �t� faite
222
if (SDL_PollEvent (&evt)) // Attend un �v�nement
223
{ // Teste si le curseur passe sur l'un des boutons du menu, ou si on clique dessus, ou si on veut quitter
224
*chxmenu = Tester_Menu (&evt, OUI, OUI, OUI, NON, jeu);
225
if (*chxmenu) return OUI;
228
{ // Fait d�placer la souris s'il n'y a pas eu d'�v�nements
229
SDL_GetMouseState (&xSouris, &ySouris);
230
evt.type = SDL_MOUSEMOTION;
231
evt.motion.x = xSouris;
232
evt.motion.y = ySouris;
233
SDL_PeepEvents (&evt, 1, SDL_ADDEVENT, SDL_MOUSEMOTIONMASK);
236
// R�affiche le d�cor sur l'ancienne position
237
SDL_BlitSurface (jeu->back, &dest, jeu->ecran, &dest);
239
// Affiche les joueurs avec le plus en avant par dessus l'autre
240
Afficher_Joueur (j[n].y <= j[!n].y ? &j[n] : &j[!n], jeu->ecran);
241
Afficher_Joueur (j[n].y <= j[!n].y ? &j[!n] : &j[n], jeu->ecran);
243
// Diminue la transparence de la boule
244
if (frame <= j[n].nFeu) alpha = 255 - 191 * frame / j[n].nFeu;
245
SDL_SetAlpha (j[n].imgFeu, SDL_SRCALPHA, alpha);
247
// Copie l'image de la boule de feu sur l'�cran
249
dest.x = xDep + frame * (xDest - xDep) / (j[n].nFeu * 2);
250
dest.y = yDep + frame * (yDest - yDep) / (j[n].nFeu * 2);
251
SDL_BlitSurface (j[n].imgFeu, &src, jeu->ecran, &dest);
253
// La boule monte ou descend ? affiche l'image suivante ou pr�cedente dans l'animation
254
if (monte) src.x += src.w * BOULE_VITESSE;
255
else src.x -= src.w * BOULE_VITESSE;
256
if (src.x >= j[n].nFeu * src.w - src.w * BOULE_VITESSE) monte = NON;
258
// Attend d'�tre synchronis� sur la vitesse d'affichage et rafra�chit l'�cran
260
SDL_UpdateRects (jeu->ecran, 1, &dest);
261
SDL_UpdateRects (jeu->ecran, 1, &prec);
263
while (++ frame <= j[n].nFeu*2);
265
// Rectangle du trou cr�e
266
dest.w = dest.h = grille->imgCase->w;
267
dest.x = Case2CoordX (x, *grille);
268
dest.y = Case2CoordY (y, *grille);
270
// Copie l'image du trou sur l'�cran et dans le back buffer
271
SDL_BlitSurface (grille->imgFond, &dest, jeu->ecran, &dest);
272
SDL_BlitSurface (grille->imgFond, &dest, jeu->back, &dest);
273
SDL_UpdateRects (jeu->ecran, 1, &dest);
275
// R�affiche les joueurs
276
Afficher_Joueur (j[n].y <= j[!n].y ? &j[n] : &j[!n], jeu->ecran);
277
Afficher_Joueur (j[n].y <= j[!n].y ? &j[!n] : &j[n], jeu->ecran);
278
SDL_UpdateRects (jeu->ecran, 1, &dest);
280
// Fait trembler l'�cran
281
Secouer_Ecran (j, *grille, jeu->ecran);
287
// ****************************************************************************
288
// ******************************** Placer_Trou ********************************
289
// ****************************************************************************
290
BOOL Placer_Trou (int x, int y, JOUEUR j[], int n, GRILLE *grille, JEU *jeu, BOOL conseil, CHXMENU *chxmenu)
292
SDL_Rect src, dest, prec; // Rectangles pour la copie d'image
293
int xDep, yDep; // Coordonn�es o� la boule d�colle
294
int xDest, yDest; // Coordonn�es o� la boule s'�crase
295
float xDecal, yDecal; // Unit� de d�placement de la boule
296
float xPos, yPos; // Position de la boule
297
int frame; // Image courante dans l'animation de la boule
298
BOOL monte = OUI; // La boule de feu monte ou descend ?
299
BOOL bis = OUI; // R�p�te la m�me image d'animation
300
SDL_Event evt; // Pour d�tecter un appui sur [ESC]
301
int xSouris, ySouris; // Coords de la souris
304
// V�rifie s'il l'on peut placer le trou
305
if (grille->c[x][y] != VIDE) return NON;
306
if (!conseil) grille->c[x][y] = TROU;
308
// Efface l'affichage de l'action en cours
309
SDL_BlitSurface (jeu->back, &jeu->titre, jeu->ecran, &jeu->titre);
310
SDL_UpdateRects (jeu->ecran, 1, &jeu->titre);
312
// Si un conseil est demand�, l'affiche et rend le joueur et la boule transparents
314
{ Afficher_Chaine ((jeu->ecran->w - strlen (TXT_CONSEIL) * jeu->police1.rect.w) / 2, jeu->titre.y, 0, TXT_CONSEIL, jeu->police1, jeu->ecran, jeu->ecran);
315
SDL_SetAlpha (j[n].imgLance, SDL_SRCALPHA, 128);
316
SDL_SetAlpha (j[n].imgFeu, SDL_SRCALPHA, 128);
319
// Animation du joueur qui lance la boule
324
// La boule de feu est centr�e au centre de la case � d�truire � l'arriv�e
325
xDest = Case2CoordX (x, *grille) - (j[n].imgFeu->w / j[n].nFeu - grille->imgCase->w) / 2;
326
yDest = Case2CoordY (y, *grille) - (j[n].imgFeu->h - grille->imgCase->h) / 2;
327
// La boule de feu est centr�e sur le point du joueur au d�part
328
xDep = Case2CoordX (j[n].x, *grille) - (j[n].imgFeu->w / j[n].nFeu - grille->imgCase->w) / 2 - 24;
329
yDep = Case2CoordY (j[n].y, *grille) - (j[n].imgFeu->h - grille->imgCase->h) / 2 - 16;
330
// Rectangle sur l'image dans la s�quence d'animation de la boule de feu
331
src.w = dest.w = j[n].imgFeu->w / j[n].nFeu;
332
src.h = dest.h = j[n].imgFeu->h;
334
dest.x = xPos = xDep;
335
dest.y = yPos = yDep;
336
xDecal = (float)(xDest - xDep) / (float)(j[n].nFeu * 2 - 1);
337
yDecal = (float)(yDest - yDep) / (float)(j[n].nFeu * 2 - 1);
339
// Boucle de l'animation tant que toutes l'animation de la boule de feu n'a pas �t� faite
342
if (SDL_PollEvent (&evt)) // Attend un �v�nement
343
{ // Teste si le curseur passe sur l'un des boutons du menu, ou si on clique dessus, ou si on veut quitter
344
*chxmenu = Tester_Menu (&evt, OUI, OUI, OUI, NON, jeu);
345
if (*chxmenu) return OUI;
348
{ // Fait d�placer la souris s'il n'y a pas eu d'�v�nements
349
SDL_GetMouseState (&xSouris, &ySouris);
350
evt.type = SDL_MOUSEMOTION;
351
evt.motion.x = xSouris;
352
evt.motion.y = ySouris;
353
SDL_PeepEvents (&evt, 1, SDL_ADDEVENT, SDL_MOUSEMOTIONMASK);
356
// R�affiche le d�cor sur les anciennes positions
357
SDL_BlitSurface (jeu->back, &dest, jeu->ecran, &dest);
358
SDL_BlitSurface (jeu->back, &j[n].rect, jeu->ecran, &j[n].rect);
360
// Passe � l'image suivante dans l'animation du joueur (avec une pause entre les frames 0 et 20)
361
if ((frame < 0 || frame > 20) && j[n].frame < j[n].nLance - 1)
362
if (bis = !bis) j[n].frame ++;
364
// Affiche les joueurs avec le plus en avant par dessus l'autre
365
Afficher_Joueur (j[n].y <= j[!n].y ? &j[n] : &j[!n], jeu->ecran);
366
Afficher_Joueur (j[n].y <= j[!n].y ? &j[!n] : &j[n], jeu->ecran);
368
// Anime la boule � partir de la frame 0 (on a commenc� � -30)
371
// Copie l'image de la boule de feu sur l'�cran
374
{ xPos += xDecal/2.0;
382
{ xPos += xDecal*2.0;
387
SDL_BlitSurface (j[n].imgFeu, &src, jeu->ecran, &dest);
389
// La boule monte ou descend ? affiche l'image suivante ou pr�cedente dans l'animation
390
if (monte) src.x += src.w;
392
if (src.x >= j[n].nFeu * src.w - src.w) monte = NON;
395
// Attend d'�tre synchronis� sur la vitesse d'affichage et rafra�chit l'�cran
397
SDL_UpdateRects (jeu->ecran, 1, &j[n].rect);
399
{ SDL_UpdateRects (jeu->ecran, 1, &dest);
400
SDL_UpdateRects (jeu->ecran, 1, &prec);
403
while (++ frame < j[n].nFeu * 2);
405
// Si un conseil �tait demand� remet les animations � leur transparence d'origine et efface la boule
407
{ SDL_SetAlpha (j[n].imgLance, SDL_SRCALPHA, 0);
408
SDL_SetAlpha (j[n].imgFeu, SDL_SRCALPHA, 64);
409
SDL_BlitSurface (jeu->back, &dest, jeu->ecran, &dest);
410
SDL_BlitSurface (jeu->back, &j[n].rect, jeu->ecran, &j[n].rect);
411
Afficher_Joueur (j[n].y <= j[!n].y ? &j[n] : &j[!n], jeu->ecran);
412
Afficher_Joueur (j[n].y <= j[!n].y ? &j[!n] : &j[n], jeu->ecran);
413
SDL_UpdateRects (jeu->ecran, 1, &dest);
416
{ // Rectangle du trou cr�e
417
dest.w = dest.h = grille->imgCase->w;
418
dest.x = Case2CoordX (x, *grille);
419
dest.y = Case2CoordY (y, *grille);
421
// Copie l'image du trou sur l'�cran et dans le back buffer
422
SDL_BlitSurface (grille->imgFond, &dest, jeu->ecran, &dest);
423
SDL_BlitSurface (grille->imgFond, &dest, jeu->back, &dest);
424
SDL_UpdateRects (jeu->ecran, 1, &dest);
426
// R�affiche les joueurs
427
Afficher_Joueur (j[n].y <= j[!n].y ? &j[n] : &j[!n], jeu->ecran);
428
Afficher_Joueur (j[n].y <= j[!n].y ? &j[!n] : &j[n], jeu->ecran);
429
SDL_UpdateRects (jeu->ecran, 1, &dest);
431
// Fait trembler l'�cran
432
Secouer_Ecran (j, *grille, jeu->ecran);
439
// ****************************************************************************
440
// ****************************** Deplacer_Joueur *****************************
441
// ****************************************************************************
442
BOOL Deplacer_Joueur (int x, int y, JOUEUR j[], int n, GRILLE *grille, JEU *jeu, BOOL conseil, CHXMENU *chxmenu)
444
SDL_Rect prec; // Rectangle de l'ancienne position du joueur (� effacer)
445
SDL_Rect save, src; // Rectangles de l'ancienne position du joueur (� sauvegarder pour un conseil)
446
SDL_Event evt; // Pour d�tecter un appui sur [ESC]
447
BOOL bis = OUI; // R�p�te la m�me image d'animation
448
int xSouris, ySouris; // Coords de la souris
452
// V�rifie si l'on peut d�placer le joueur, le d�placement autoris� est d'une case autour de sa position
453
if (grille->c[x][y] != VIDE || j[n].x < x-1 || j[n].x > x+1 || j[n].y < y-1 || j[n].y > y+1) return NON;
455
// Efface l'affichage de l'action en cours
456
SDL_BlitSurface (jeu->back, &jeu->titre, jeu->ecran, &jeu->titre);
457
SDL_UpdateRects (jeu->ecran, 1, &jeu->titre);
459
// Choisit la bonne animation pour le joueur
460
if (j[n].x > x) j[n].anim = COURSG;
461
if (j[n].y > y) j[n].anim = COURSH;
462
if (j[n].x < x) j[n].anim = COURSD;
463
if (j[n].y < y) j[n].anim = COURSB;
466
// Si c'est un conseil qui est demand�, sauvegarde la position du joueur et affiche le titre "CONSEIL"
472
Afficher_Chaine ((jeu->ecran->w - strlen (TXT_CONSEIL) * jeu->police1.rect.w) / 2, jeu->titre.y, 0, TXT_CONSEIL, jeu->police1, jeu->ecran, jeu->ecran);
475
// Animation du joueur qui court d'une case � l'autre
476
for (frame = 0; frame < grille->imgCase->w; frame += 2)
478
if (SDL_PollEvent (&evt)) // Attend un �v�nement
479
{ // Teste si le curseur passe sur l'un des boutons du menu, ou si on clique dessus, ou si on veut quitter
480
*chxmenu = Tester_Menu (&evt, OUI, OUI, OUI, NON, jeu);
481
if (*chxmenu) return OUI;
484
{ // Fait d�placer la souris s'il n'y a pas eu d'�v�nements
485
SDL_GetMouseState (&xSouris, &ySouris);
486
evt.type = SDL_MOUSEMOTION;
487
evt.motion.x = xSouris;
488
evt.motion.y = ySouris;
489
SDL_PeepEvents (&evt, 1, SDL_ADDEVENT, SDL_MOUSEMOTIONMASK);
492
// Efface l'ancienne position du joueur
493
SDL_BlitSurface (jeu->back, &j[n].rect, jeu->ecran, &j[n].rect);
495
// Place le rectangle source sur l'image en cours dans l'animation
496
j[n].src.x = j[n].frame * j[n].imgCours->w / j[n].nCours;
498
// D�place le rectangle destination sur l'�cran selon la direction o� se d�place le joueur
500
if (j[n].x > x) j[n].rect.x -= 2;
501
if (j[n].y > y) j[n].rect.y -= 2;
502
if (j[n].x < x) j[n].rect.x += 2;
503
if (j[n].y < y) j[n].rect.y += 2;
505
// Affiche les joueurs avec le plus en avant par dessus l'autre
507
{ SDL_BlitSurface (jeu->back, &save, jeu->ecran, &save);
508
SDL_BlitSurface (j[n].imgCours, &src, jeu->ecran, &save);
509
SDL_SetAlpha (j[n].imgCours, SDL_SRCALPHA, 128);
511
Afficher_Joueur (j[n].y < j[!n].y ? &j[n] : &j[!n], jeu->ecran);
512
Afficher_Joueur (j[n].y < j[!n].y ? &j[!n] : &j[n], jeu->ecran);
514
{ SDL_SetAlpha (j[n].imgCours, SDL_SRCALPHA, 0);
517
// Attend d'�tre synchronis� sur la vitesse d'affichage et rafra�chit l'�cran
519
SDL_UpdateRects (jeu->ecran, 1, &j[n].rect);
520
SDL_UpdateRects (jeu->ecran, 1, &prec);
521
if (conseil) SDL_UpdateRects (jeu->ecran, 1, &save);
523
// Passe � l'image suivante dans l'animation o� r�p�te la m�me (reboucle si termin�)
524
if (bis = !bis) j[n].frame ++;
525
if (j[n].frame >= j[n].nCours) j[n].frame = 0;
529
{ // Restaure le joueur � sa position
530
SDL_BlitSurface (jeu->back, &j[n].rect, jeu->ecran, &j[n].rect);
531
Afficher_Joueur (&j[!n], jeu->ecran);
532
SDL_UpdateRects (jeu->ecran, 1, &j[n].rect);
536
{ // Lib�re la place anciennement occup�e par le joueur
537
grille->c[j[n].x][j[n].y] = VIDE;
538
// Modifie ses coordonn�es
541
// Et entre sa nouvelle position dans la grille
542
grille->c[j[n].x][j[n].y] = j[n].n;
548
// ****************************************************************************
549
// ******************************* Placer_Joueur ******************************
550
// ****************************************************************************
551
BOOL Placer_Joueur (int x, int y, JOUEUR j[], int n, GRILLE *grille, JEU *jeu, BOOL conseil, CHXMENU *chxmenu)
553
int alpha; // Valeur de la transparence de l'image du joueur
555
int xSouris, ySouris; // Coords de la souris
558
// V�rifie qu'il y a de la place pour placer le joueur et le place
559
if (grille->c[x][y] != VIDE) return NON;
561
// Coordonn�es du joueur dans la grille
562
if (!conseil) grille->c[x][y] = j[n].n;
566
// Coordonn�es du joueur sur l'�cran
567
j[n].rect.x = Case2CoordX (j[n].x, *grille) - (j[n].imgCours->w / j[n].nCours - grille->imgCase->w) / 2;
568
j[n].rect.y = Case2CoordY (j[n].y, *grille) - (j[n].imgCours->h / 4 - grille->imgCase->h) / 2;
570
// Le joueur appara�t progressivement (en diminuant sa transparence)
571
for (alpha = 250; alpha >= 0; alpha -= 10)
573
if (SDL_PollEvent (&evt))
574
{ // Teste si le curseur passe sur l'un des boutons du menu, ou si on clique dessus, ou si on veut quitter
575
*chxmenu = Tester_Menu (&evt, OUI, OUI, OUI, NON, jeu);
576
if (*chxmenu) return OUI;
579
{ // Fait d�placer la souris s'il n'y a pas eu d'�v�nements
580
SDL_GetMouseState (&xSouris, &ySouris);
581
evt.type = SDL_MOUSEMOTION;
582
evt.motion.x = xSouris;
583
evt.motion.y = ySouris;
584
SDL_PeepEvents (&evt, 1, SDL_ADDEVENT, SDL_MOUSEMOTIONMASK);
587
// R�gle la transparence du joueur et l'affiche
588
SDL_SetAlpha (j[n].imgCours, SDL_SRCALPHA, alpha);
589
SDL_BlitSurface (jeu->back, &j[n].rect, jeu->ecran, &j[n].rect);
591
// Si c'est au tour du 2e joueur, on r�affiche le premier
592
if (n == 1) Afficher_Joueur (&j[0], jeu->ecran);
593
Afficher_Joueur (&j[n], jeu->ecran);
595
// Attend d'�tre synchronis� sur la vitesse d'affichage et rafra�chit l'�cran
597
SDL_UpdateRects (jeu->ecran, 1, &j[n].rect);
601
{ SDL_BlitSurface (jeu->back, &j[n].rect, jeu->ecran, &j[n].rect);
602
SDL_UpdateRects (jeu->ecran, 1, &j[n].rect);
609
// ****************************************************************************
610
// ******************************** Placer_Joueurs ****************************
611
// ****************************************************************************
612
void Placer_Joueurs (JEU *jeu, JOUEUR j[], GRILLE *grille, CHXMENU *chxmenu)
614
SDL_Event evt; // R�cup�re les infos d'un �v�nement
615
int tour = 0; // Tour du joueur pour se placer
616
int x, y; // Coordonn�es du clic de souris
621
// Placement d'un joueur dirig� par l'ordinateur
622
if (j[tour].type == ORDI)
624
Ordi_Place (&x, &y, j[tour], *grille);
625
Placer_Joueur (x, y, j, tour, grille, jeu, NON, chxmenu);
626
if (*chxmenu) return;
628
// Incr�mente le tour et quitte si tous les joueurs ont �t� plac�s
629
if (++ tour == 2) return;
633
if (SDL_PollEvent (&evt))
635
// Affiche l'action en cours
636
SDL_BlitSurface (jeu->back, &jeu->titre, jeu->ecran, &jeu->titre);
637
if (tour == 0) Afficher_Chaine ((jeu->ecran->w - strlen (TXT_J1PLACE) * jeu->police2.rect.w) / 2, jeu->titre.y, 0, TXT_J1PLACE, jeu->J1ROUGE ? jeu->police3 : jeu->police2, jeu->ecran, jeu->ecran);
638
if (tour == 1) Afficher_Chaine ((jeu->ecran->w - strlen (TXT_J2PLACE) * jeu->police2.rect.w) / 2, jeu->titre.y, 0, TXT_J2PLACE, jeu->J1ROUGE ? jeu->police2 : jeu->police3, jeu->ecran, jeu->ecran);
639
SDL_UpdateRects (jeu->ecran, 1, &jeu->titre);
641
if (evt.type == SDL_MOUSEBUTTONDOWN && evt.button.button == 1) // Bouton gauche enfonc�
643
x = Clic2CaseX (evt.button.x, *grille); // R�cup�re les coords
644
y = Clic2CaseY (evt.button.y, *grille); // de la case cliqu�e
646
// S'il s'agit bien d'une case de la grille
647
if (x != -1 && y != -1)
648
// Si le joueur a put �tre plac�
649
if (Placer_Joueur (x, y, j, tour, grille, jeu, NON, chxmenu))
650
// Incr�mente le tour et quitte si tous les joueurs ont �t� plac�s
651
if (++ tour == 2) return;
654
// Teste si le curseur passe sur l'un des boutons du menu, ou si on clique dessus, ou si on veut quitter
655
*chxmenu = Tester_Menu (&evt, OUI, OUI, OUI, OUI, jeu);
656
if (*chxmenu == CONSEIL)
657
{ Ordi_Place (&x, &y, j[tour], *grille);
658
Placer_Joueur (x, y, j, tour, grille, jeu, OUI, chxmenu);
659
if (*chxmenu) return;
661
else if (*chxmenu) return;
662
//if (*chxmenu != RIEN && *chxmenu != CONSEIL) return;
665
{ // Fait d�placer la souris s'il n'y a pas eu d'�v�nements
666
SDL_GetMouseState (&x, &y);
667
evt.type = SDL_MOUSEMOTION;
670
SDL_PeepEvents (&evt, 1, SDL_ADDEVENT, SDL_MOUSEMOTIONMASK);
676
// ****************************************************************************
677
// ****************************** Constructeur ********************************
678
// ****************************************************************************
679
void Constructeur (JOUEUR j[], GRILLE *grille, BOOL c, SDL_Surface *ecran, SDL_Surface *back)
681
SDL_Surface *img; // Surface contenant temporairement une image
682
SDL_Rect src, dest; // Rectangles de copie d'image
685
// Cr�er une surface qui contiendra l'arri�re plan
686
if (!(grille->imgFond = SDL_DisplayFormat (ecran)))
687
{ fprintf (stderr, "Impossible de cr�er le fond d'�cran (%s)\n", SDL_GetError ());
688
SDL_FreeSurface (grille->imgFond);
692
// Charge l'image de fond ...
695
case 1: sprintf (fichier, "%s%s", imgpath, IMG_FOND1); break;
696
case 2: sprintf (fichier, "%s%s", imgpath, IMG_FOND2); break;
697
case 3: sprintf (fichier, "%s%s", imgpath, IMG_FOND3); break;
698
case 4: sprintf (fichier, "%s%s", imgpath, IMG_FOND4); break;
699
case 5: sprintf (fichier, "%s%s", imgpath, IMG_FOND5); break;
700
default: sprintf (fichier, "%s%s", imgpath, IMG_FOND1); break;
702
if (!(img = IMG_Load (fichier))) ImageErreur (fichier);
704
// ... et l'affiche en mosaique dans l'arri�re plan
707
for (dest.y = 0; dest.y < grille->imgFond->h; dest.y += dest.h)
708
for (dest.x = 0; dest.x < grille->imgFond->w; dest.x += dest.w)
710
src.w = dest.w = img->w;
711
src.h = dest.h = img->h;
712
SDL_BlitSurface (img, &src, grille->imgFond, &dest);
715
// Lib�re l'image de fond et copie l'arri�re plan dans le back buffer
716
SDL_FreeSurface (img);
717
SDL_BlitSurface (grille->imgFond, NULL, back, NULL);
719
// Charge les images dans des surfaces et teste si elles sont pr�sentes
720
/*img = SDL_CreateRGBSurface (SDL_HWSURFACE | SDL_SRCALPHA, 3840, 128, 32, 0xff, 0x00ff, 0x0000ff, 0x000000ff);
722
if (!(img = IMG_Load (IMG_FEU))) ImageErreur (IMG_FEU);
723
j[c].imgFeu = SDL_CreateRGBSurface (SDL_HWSURFACE | SDL_SRCALPHA, img->w, img->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
724
j[!c].imgFeu = SDL_CreateRGBSurface (SDL_HWSURFACE | SDL_SRCALPHA, img->w, img->h, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
725
SDL_BlitSurface (img, NULL, j[c].imgFeu, NULL);
726
SDL_BlitSurface (img, NULL, j[!c].imgFeu, NULL);
727
SDL_FreeSurface (img);*/
728
sprintf (fichier, "%s%s", imgpath, IMG_CASE);
729
if (!(grille->imgCase = IMG_Load (fichier))) ImageErreur (fichier);
730
sprintf (fichier, "%s%s", imgpath, IMG_FEU);
731
if (!(j[c].imgFeu = IMG_Load (fichier))) ImageErreur (fichier);
732
if (!(j[!c].imgFeu = IMG_Load (fichier))) ImageErreur (fichier);
733
sprintf (fichier, "%s%s", imgpath, IMG_J1COURS);
734
if (!(j[c].imgCours = IMG_Load (fichier))) ImageErreur (fichier);
735
sprintf (fichier, "%s%s", imgpath, IMG_J2COURS);
736
if (!(j[!c].imgCours = IMG_Load (fichier))) ImageErreur (fichier);
737
sprintf (fichier, "%s%s", imgpath, IMG_J1LANCE);
738
if (!(j[c].imgLance = IMG_Load (fichier))) ImageErreur (fichier);
739
sprintf (fichier, "%s%s", imgpath, IMG_J2LANCE);
740
if (!(j[!c].imgLance = IMG_Load (fichier))) ImageErreur (fichier);
741
sprintf (fichier, "%s%s", imgpath, IMG_J1GAGNE);
742
if (!(j[c].imgGagne = IMG_Load (fichier))) ImageErreur (fichier);
743
sprintf (fichier, "%s%s", imgpath, IMG_J2GAGNE);
744
if (!(j[!c].imgGagne = IMG_Load (fichier))) ImageErreur (fichier);
745
sprintf (fichier, "%s%s", imgpath, IMG_J1PERDU);
746
if (!(j[c].imgPerdu = IMG_Load (fichier))) ImageErreur (fichier);
747
sprintf (fichier, "%s%s", imgpath, IMG_J2PERDU);
748
if (!(j[!c].imgPerdu = IMG_Load (fichier))) ImageErreur (fichier);
749
sprintf (fichier, "%s%s", imgpath, IMG_J1ATTEND);
750
if (!(j[c].imgAttend = IMG_Load (fichier))) ImageErreur (fichier);
751
sprintf (fichier, "%s%s", imgpath, IMG_J2ATTEND);
752
if (!(j[!c].imgAttend = IMG_Load (fichier))) ImageErreur (fichier);
753
sprintf (fichier, "%s%s", imgpath, IMG_J1ATTENDFEU);
754
if (!(j[c].imgAttendFeu = IMG_Load (fichier))) ImageErreur (fichier);
755
sprintf (fichier, "%s%s", imgpath, IMG_J2ATTENDFEU);
756
if (!(j[!c].imgAttendFeu = IMG_Load (fichier))) ImageErreur (fichier);
758
// D�finit le nombres d'images pour les animations
759
j[c].nFeu = j[!c].nFeu = 30;
760
j[c].nCours = j[!c].nCours = 16;
761
j[c].nLance = j[!c].nLance = 18;
762
j[c].nGagne = j[!c].nGagne = 35;
763
j[c].nPerdu = j[!c].nPerdu = 20;
764
j[c].nAttend = j[!c].nAttend = 30;
765
j[c].nAttendFeu = j[!c].nAttendFeu = 20;
767
// Animation courante et image � afficher
768
j[c].anim = j[!c].anim = COURSB;
769
j[c].frame = j[!c].frame = 0;
771
// D�finit la couleur qui d�termine la transparence (le violet)
772
SDL_SetColorKey (j[c].imgFeu, SDL_SRCCOLORKEY, SDL_MapRGB (j[c].imgFeu->format, 255, 0, 255));
773
SDL_SetColorKey (j[!c].imgFeu, SDL_SRCCOLORKEY, SDL_MapRGB (j[!c].imgFeu->format, 255, 0, 255));
774
SDL_SetColorKey (j[c].imgCours, SDL_SRCCOLORKEY, SDL_MapRGB (j[c].imgCours->format, 255, 0, 255));
775
SDL_SetColorKey (j[!c].imgCours, SDL_SRCCOLORKEY, SDL_MapRGB (j[!c].imgCours->format, 255, 0, 255));
776
SDL_SetColorKey (j[c].imgLance, SDL_SRCCOLORKEY, SDL_MapRGB (j[c].imgLance->format, 255, 0, 255));
777
SDL_SetColorKey (j[!c].imgLance, SDL_SRCCOLORKEY, SDL_MapRGB (j[!c].imgLance->format, 255, 0, 255));
778
SDL_SetColorKey (j[c].imgGagne, SDL_SRCCOLORKEY, SDL_MapRGB (j[c].imgGagne->format, 255, 0, 255));
779
SDL_SetColorKey (j[!c].imgGagne, SDL_SRCCOLORKEY, SDL_MapRGB (j[!c].imgGagne->format, 255, 0, 255));
780
SDL_SetColorKey (j[c].imgPerdu, SDL_SRCCOLORKEY, SDL_MapRGB (j[c].imgPerdu->format, 255, 0, 255));
781
SDL_SetColorKey (j[!c].imgPerdu, SDL_SRCCOLORKEY, SDL_MapRGB (j[!c].imgPerdu->format, 255, 0, 255));
782
SDL_SetColorKey (j[c].imgAttend, SDL_SRCCOLORKEY, SDL_MapRGB (j[c].imgAttend->format, 255, 0, 255));
783
SDL_SetColorKey (j[!c].imgAttend, SDL_SRCCOLORKEY, SDL_MapRGB (j[!c].imgAttend->format, 255, 0, 255));
784
SDL_SetColorKey (j[c].imgAttendFeu, SDL_SRCCOLORKEY, SDL_MapRGB (j[c].imgAttendFeu->format, 255, 0, 255));
785
SDL_SetColorKey (j[!c].imgAttendFeu, SDL_SRCCOLORKEY, SDL_MapRGB (j[!c].imgAttendFeu->format, 255, 0, 255));
787
// D�finit la transparence des cases et de la boule de feu
788
SDL_SetAlpha (grille->imgCase, SDL_SRCALPHA, 100);
789
SDL_SetAlpha (j[c].imgFeu, SDL_SRCALPHA, 64);
790
SDL_SetAlpha (j[!c].imgFeu, SDL_SRCALPHA, 64);
791
SDL_SetAlpha (j[c].imgPerdu, SDL_SRCALPHA, 100);
792
SDL_SetAlpha (j[!c].imgPerdu, SDL_SRCALPHA, 100);
794
// D�finit la taille des rectangles des joueurs
795
j[c].rect.w = j[c].imgCours->w / j[c].nCours;
796
j[c].rect.h = j[c].imgCours->h / 4;
797
j[!c].rect.w = j[!c].imgCours->w / j[c].nCours;
798
j[!c].rect.h = j[!c].imgCours->h / 4;
800
// Remplit la grille de cases vides
801
for (x = 0; x < grille->xc; x ++)
802
for (y = 0; y < grille->yc; y ++)
803
grille->c [x][y] = VIDE;
805
// Grille positionn�e au milieu de l'�cran
806
grille->tc = grille->imgCase->w;
807
grille->x1 = (ecran->w - grille->tc * grille->xc) / 2;
808
grille->y1 = (ecran->h - grille->tc * grille->yc) / 2;
809
grille->x2 = ecran->w - grille->x1;
810
grille->y2 = ecran->h - grille->y1;
812
// Copie les cases de la grille dans le back buffer
813
dest.w = dest.h = grille->tc;
815
for (dest.x = grille->x1; dest.x < grille->x2; dest.x += dest.w)
816
for (dest.y = grille->y1; dest.y < grille->y2; dest.y += dest.h)
817
SDL_BlitSurface (grille->imgCase, NULL, back, &dest);
819
// Met � jour l'�cran entier
820
SDL_BlitSurface (back, NULL, ecran, NULL);
821
SDL_UpdateRect (ecran, 0, 0, ecran->w, ecran->h);
825
// ****************************************************************************
826
// ****************************** Destructeur *********************************
827
// ****************************************************************************
828
void Destructeur (JOUEUR j[], GRILLE *grille)
830
// Enl�ve les images de la m�moire
831
SDL_FreeSurface (grille->imgCase);
832
SDL_FreeSurface (grille->imgFond);
833
SDL_FreeSurface (j[0].imgFeu);
834
SDL_FreeSurface (j[1].imgFeu);
835
SDL_FreeSurface (j[0].imgCours);
836
SDL_FreeSurface (j[1].imgCours);
837
SDL_FreeSurface (j[0].imgLance);
838
SDL_FreeSurface (j[1].imgLance);
839
SDL_FreeSurface (j[0].imgGagne);
840
SDL_FreeSurface (j[1].imgGagne);
841
SDL_FreeSurface (j[0].imgPerdu);
842
SDL_FreeSurface (j[1].imgPerdu);
846
// ****************************************************************************
847
// ****************************** Tester_Perdu ********************************
848
// ****************************************************************************
849
BOOL Tester_Perdu (JOUEUR j, GRILLE grille)
851
// Teste si les 8 cases entourants le joueur existent et si elles sont vides
852
if (j.x-1 >= 0 && j.y-1 >= 0 && grille.c[j.x-1][j.y-1] == VIDE) return NON;
853
if (j.x-1 >= 0 && grille.c[j.x-1][j.y] == VIDE) return NON;
854
if (j.x-1 >= 0 && j.y+1 < grille.yc && grille.c[j.x-1][j.y+1] == VIDE) return NON;
856
if (j.y-1 >= 0 && grille.c[j.x][j.y-1] == VIDE) return NON;
857
if (j.y+1 < grille.yc && grille.c[j.x][j.y+1] == VIDE) return NON;
859
if (j.x+1 < grille.xc && j.y-1 >= 0 && grille.c[j.x+1][j.y-1] == VIDE) return NON;
860
if (j.x+1 < grille.xc && grille.c[j.x+1][j.y] == VIDE) return NON;
861
if (j.x+1 < grille.xc && j.y+1 < grille.yc && grille.c[j.x+1][j.y+1] == VIDE) return NON;
867
// ****************************************************************************
868
// ************************** Animer_Perdant_Gagnant **************************
869
// ****************************************************************************
870
void Animer_Perdant_Gagnant (JOUEUR *j1, JOUEUR *j2, JEU *jeu, CHXMENU *chxmenu)
872
SDL_Rect prec1, prec2; // Pr�c�dente position des joueurs
873
SDL_Event evt; // Pour d�tecter un appui sur [ESC]
874
BOOL bis = OUI; // R�p�te la m�me image d'animation
875
int xSouris, ySouris; // Coords de la souris
877
const int xmax = jeu->ecran->w - (j2->imgPerdu->w / j2->nPerdu) - 50;
878
const int ymin = jeu->titre.y + jeu->titre.h;
879
const int ymax = jeu->rMenu[0].y - j2->imgPerdu->h;
882
int xdir = 0, ydir = 0;
885
// R�ajuste le rectangles du joueur qui se transforme en ange
886
j2->rect.w = j2->imgPerdu->w / j2->nPerdu;
887
j2->rect.h = j2->imgPerdu->h;
890
// R�gle les animations
896
// Affiche qui a gagn�
897
if (j1->n == J2) Afficher_Chaine ((jeu->ecran->w - strlen (TXT_J2GAGNE) * jeu->police1.rect.w) / 2, jeu->titre.y, 0, TXT_J2GAGNE, jeu->police1, jeu->ecran, jeu->back);
898
else Afficher_Chaine ((jeu->ecran->w - strlen (TXT_J1GAGNE) * jeu->police1.rect.w) / 2, jeu->titre.y, 0, TXT_J1GAGNE, jeu->police1, jeu->ecran, jeu->back);
900
// Animation des joueurs
903
if (SDL_PollEvent (&evt)) // Attend un �v�nement
904
{ // Teste si le curseur passe sur l'un des boutons du menu, ou si on clique dessus, ou si on veut quitter
905
*chxmenu = Tester_Menu (&evt, OUI, OUI, OUI, NON, jeu);
906
if (*chxmenu) return;
909
{ // Fait d�placer la souris s'il n'y a pas eu d'�v�nements
910
SDL_GetMouseState (&xSouris, &ySouris);
911
evt.type = SDL_MOUSEMOTION;
912
evt.motion.x = xSouris;
913
evt.motion.y = ySouris;
914
SDL_PeepEvents (&evt, 1, SDL_ADDEVENT, SDL_MOUSEMOTIONMASK);
917
// Impulsion du saut p�rilleux
919
if (j1->frame > 3 && j1->frame <= 11) j1->rect.y -= 6;
920
if (j1->frame > 11 && j1->frame <= 19) j1->rect.y += 6;
922
// Impulsion des ailes
928
// Direction de l'ange fix� pendant dur�e
930
{ duree = Alea (25, 40);
933
if (xdir != 1 && j2->rect.x < xmin) xdir = 1;
934
if (xdir != -1 && j2->rect.x > xmax) xdir = -1;
935
if (ydir != 1 && j2->rect.y < ymin) ydir = 1;
936
if (ydir != -1 && j2->rect.y > ymax) ydir = -1;
938
// Stop son mvt s'il s'approche d'un bord de l'�cran
939
if (xdir != 1 && j2->rect.x < xmin) duree = 0;
940
if (xdir != -1 && j2->rect.x > xmax) duree = 0;
941
if (ydir != 1 && j2->rect.y < ymin) duree = 0;
942
if (ydir != -1 && j2->rect.y > ymax) duree = 0;
944
j2->rect.x += vitesse * xdir;
945
j2->rect.y += vitesse * ydir;
947
// Efface les anciennes positions des joueurs
948
SDL_BlitSurface (jeu->back, &prec1, jeu->ecran, &prec1);
949
SDL_BlitSurface (jeu->back, &prec2, jeu->ecran, &prec2);
950
SDL_BlitSurface (jeu->back, &j1->rect, jeu->ecran, &j1->rect);
951
SDL_BlitSurface (jeu->back, &j2->rect, jeu->ecran, &j2->rect);
953
// Affiche les joueurs anim�s
954
Afficher_Joueur (j1, jeu->ecran);
955
Afficher_Joueur (j2, jeu->ecran);
957
// Attend d'�tre synchronis� sur la vitesse d'affichage et rafra�chit l'�cran
959
SDL_UpdateRects (jeu->ecran, 1, &j1->rect);
960
SDL_UpdateRects (jeu->ecran, 1, &j2->rect);
961
SDL_UpdateRects (jeu->ecran, 1, &prec1);
962
SDL_UpdateRects (jeu->ecran, 1, &prec2);
964
// Passe � l'image suivante dans l'animation et reboucle si besoin
969
if (j1->frame >= j1->nGagne) j1->frame = 0;
970
if (j2->frame >= j2->nPerdu) j2->frame = 0;
975
// ****************************************************************************
976
// *********************************** Jeu ************************************
977
// ****************************************************************************
980
SDL_Event evt; // Sert � recueillir des infos sur les �v�nements
981
int x, y; // Coordonn�es des clics de souris
982
ACTION action; // Action du jeu en cours
983
GRILLE grille = {jeu->XGRILLE, jeu->YGRILLE}; // Grille du jeu (initialise dimensions)
984
JOUEUR j[2] = {{J1, jeu->J1TYPE, jeu->J1NIVO}, {J2, jeu->J2TYPE, jeu->J2NIVO}}; // Joueurs
985
BOOL bis; // Si l'option double est activ�e: compteur d'action double
986
BOOL repimg; // R�p�te la m�me image d'animation
987
CHXMENU chxmenu; // Valeur retourn�e apr�s un test du menu
990
// Si le joueur est humain met son IA au niveau 3
991
if (j[0].type == HUMAIN) j[0].nivo = 3;
992
if (j[1].type == HUMAIN) j[1].nivo = 3;
994
// Rectangles des boutons du menu
995
jeu->rMenu[0].y = jeu->rMenu[1].y = jeu->rMenu[2].y = jeu->rMenu[3].y = jeu->ecran->h - jeu->police3.rect.h - 5;
996
jeu->rMenu[0].h = jeu->rMenu[1].h = jeu->rMenu[2].h = jeu->rMenu[3].h = jeu->police3.rect.h;
997
jeu->rMenu[0].w = jeu->police3.rect.w * strlen (TXT_QUITTER);
998
jeu->rMenu[1].w = jeu->police3.rect.w * strlen (TXT_MENU);
999
jeu->rMenu[2].w = jeu->police3.rect.w * strlen (TXT_REFAIRE);
1000
jeu->rMenu[3].w = jeu->police3.rect.w * strlen (TXT_CONSEIL);
1001
jeu->rMenu[0].x = (jeu->ecran->w - (strlen (TXT_QUITTER) + strlen (TXT_MENU) + strlen (TXT_REFAIRE) + strlen (TXT_CONSEIL) + 3) * jeu->police3.rect.w) / 2;
1002
jeu->rMenu[1].x = jeu->rMenu[0].x + jeu->rMenu[0].w + jeu->police3.rect.w;
1003
jeu->rMenu[2].x = jeu->rMenu[1].x + jeu->rMenu[1].w + jeu->police3.rect.w;
1004
jeu->rMenu[3].x = jeu->rMenu[2].x + jeu->rMenu[2].w + jeu->police3.rect.w;
1007
Constructeur (j, &grille, jeu->J1ROUGE, jeu->ecran, jeu->back); // Charge les images, la grille, ...
1009
// Valeurs de d�part
1010
action = J1_DEPLACE;
1015
// Rectangle d'affichage de l'action en cours
1016
jeu->titre.w = strlen (TXT_J1PLACE) * jeu->police2.rect.w;
1017
jeu->titre.h = jeu->police2.rect.h;
1018
jeu->titre.x = (jeu->ecran->w - jeu->titre.w) / 2;
1019
jeu->titre.y = (grille.y1 - jeu->titre.h) / 2;
1021
// Affiche le menu en bas de l'�cran
1022
SDL_SetAlpha (jeu->police3.img, SDL_SRCALPHA, 128);
1023
Afficher_Chaine (jeu->rMenu[0].x, jeu->rMenu[0].y, 0, TXT_QUITTER, jeu->police3, jeu->ecran, jeu->back);
1024
Afficher_Chaine (jeu->rMenu[1].x, jeu->rMenu[1].y, 0, TXT_MENU, jeu->police3, jeu->ecran, jeu->back);
1025
Afficher_Chaine (jeu->rMenu[2].x, jeu->rMenu[2].y, 0, TXT_REFAIRE, jeu->police3, jeu->ecran, jeu->back);
1026
Afficher_Chaine (jeu->rMenu[3].x, jeu->rMenu[3].y, 0, TXT_CONSEIL, jeu->police3, jeu->ecran, jeu->back);
1027
SDL_SetAlpha (jeu->police3.img, SDL_SRCALPHA, 0);
1029
Placer_Joueurs (jeu, j, &grille, &chxmenu); // Pour choisir la position de d�part
1030
if (chxmenu) goto chx_menu;
1032
// Boucle de jeu principale
1035
// Teste si l'un des joueurs a perdu
1036
if (((action == J1_DEPLACE || action == J2_TROU) && Tester_Perdu (j[0], grille)) || ((action == J2_DEPLACE || action == J1_TROU) && Tester_Perdu (j[1], grille)))
1038
// Efface l'affichage de l'action en cours
1039
SDL_BlitSurface (jeu->back, &jeu->titre, jeu->ecran, &jeu->titre);
1040
SDL_UpdateRects (jeu->ecran, 1, &jeu->titre);
1042
// Affiche les joueurs sur l'�cran
1043
SDL_BlitSurface (jeu->back, &j[0].rect, jeu->ecran, &j[0].rect);
1044
SDL_BlitSurface (jeu->back, &j[1].rect, jeu->ecran, &j[1].rect);
1045
Afficher_Joueur (j[0].y > j[1].y ? &j[1] : &j[0], jeu->ecran);
1046
Afficher_Joueur (j[0].y > j[1].y ? &j[0] : &j[1], jeu->ecran);
1047
SDL_UpdateRects (jeu->ecran, 1, &j[0].rect);
1048
SDL_UpdateRects (jeu->ecran, 1, &j[1].rect);
1050
// Quel joueur a perdu ?
1051
if ((action == J1_DEPLACE || action == J2_TROU) && Tester_Perdu (j[0], grille)) n = 0;
1054
// Le perdant se suicide
1055
grille.c[j[n].x][j[n].y] = VIDE;
1056
Placer_Trou (j[n].x, j[n].y, j, n, &grille, jeu, NON, &chxmenu);
1057
if (chxmenu) goto chx_menu;
1059
// Anime les joueurs (le gagnant danse et le perdant s'envole en ange)
1060
Animer_Perdant_Gagnant (&j[!n], &j[n], jeu, &chxmenu);
1061
if (chxmenu) goto chx_menu;
1064
// Si c'est � un humain de jouer, anime le joueur en attendant un �v�nement
1065
while ((action / 2 == 0 && j[0].type == HUMAIN) || (action / 2 == 1 && j[1].type == HUMAIN))
1067
// Affiche l'action en cours
1068
SDL_BlitSurface (jeu->back, &jeu->titre, jeu->ecran, &jeu->titre);
1071
case J1_DEPLACE: Afficher_Chaine ((jeu->ecran->w - strlen (TXT_J1DEPLACE) * jeu->police2.rect.w) / 2, jeu->titre.y, 0, TXT_J1DEPLACE, jeu->J1ROUGE ? jeu->police3 : jeu->police2, jeu->ecran, jeu->ecran);
1073
case J1_TROU: Afficher_Chaine ((jeu->ecran->w - strlen (TXT_J1TROU) * jeu->police2.rect.w) / 2, jeu->titre.y, 0, TXT_J1TROU, jeu->J1ROUGE ? jeu->police3 : jeu->police2, jeu->ecran, jeu->ecran);
1075
case J2_DEPLACE: Afficher_Chaine ((jeu->ecran->w - strlen (TXT_J2DEPLACE) * jeu->police2.rect.w) / 2, jeu->titre.y, 0, TXT_J2DEPLACE, jeu->J1ROUGE ? jeu->police2 : jeu->police3, jeu->ecran, jeu->ecran);
1077
case J2_TROU: Afficher_Chaine ((jeu->ecran->w - strlen (TXT_J2TROU) * jeu->police2.rect.w) / 2, jeu->titre.y, 0, TXT_J2TROU, jeu->J1ROUGE ? jeu->police2 : jeu->police3, jeu->ecran, jeu->ecran);
1080
SDL_UpdateRects (jeu->ecran, 1, &jeu->titre);
1082
// Affiche les joueurs sur l'�cran
1083
SDL_BlitSurface (jeu->back, &j[0].rect, jeu->ecran, &j[0].rect);
1084
SDL_BlitSurface (jeu->back, &j[1].rect, jeu->ecran, &j[1].rect);
1085
Afficher_Joueur (j[0].y > j[1].y ? &j[1] : &j[0], jeu->ecran);
1086
Afficher_Joueur (j[0].y > j[1].y ? &j[0] : &j[1], jeu->ecran);
1087
SDL_UpdateRects (jeu->ecran, 1, &j[0].rect);
1088
SDL_UpdateRects (jeu->ecran, 1, &j[1].rect);
1091
if (SDL_PollEvent (&evt)) // Attend un �v�nement
1093
if (evt.type == SDL_MOUSEBUTTONDOWN && evt.button.button == 1) // Clic bouton gauche
1095
// R�cup�re les coordonn�es de la case cliqu�e, -1 si en dehors de la grille
1096
x = Clic2CaseX (evt.button.x, grille);
1097
y = Clic2CaseY (evt.button.y, grille);
1099
// Arr�te l'attente d'�v�nement si le clic est sur une case de la grille
1100
if (x != -1 && y != -1) break;
1103
// Teste si le curseur passe sur l'un des boutons du menu, ou si on clique dessus, ou si on veut quitter
1104
chxmenu = Tester_Menu (&evt, OUI, OUI, OUI, OUI, jeu);
1105
if (chxmenu == CONSEIL)
1107
if (action == J1_DEPLACE || action == J1_TROU) n = 0;
1110
if (action == J1_DEPLACE || action == J2_DEPLACE)
1111
{ Ordi_Deplace (&x, &y, j, n, grille);
1112
Deplacer_Joueur (x, y, j, n, &grille, jeu, OUI, &chxmenu);
1115
{ Ordi_Trou (&x, &y, j, !n, grille);
1116
Placer_Trou (x, y, j, n, &grille, jeu, OUI, &chxmenu);
1119
if (chxmenu) goto chx_menu;
1121
else if (chxmenu != RIEN) goto chx_menu;
1124
{ // Fait d�placer la souris s'il n'y a pas eu d'�v�nements
1125
SDL_GetMouseState (&x, &y);
1126
evt.type = SDL_MOUSEMOTION;
1129
SDL_PeepEvents (&evt, 1, SDL_ADDEVENT, SDL_MOUSEMOTIONMASK);
1132
// R�gle les animations pour le joueur qui attend de jouer et celui qui ne bouge pas
1135
case J1_DEPLACE: j[0].anim = ATTEND;
1136
if (repimg = !repimg) j[0].frame ++;
1137
if (j[0].frame >= j[0].nAttend) j[0].frame = 0;
1142
case J1_TROU: j[0].anim = ATTENDFEU;
1143
if (repimg = !repimg) j[0].frame ++;
1144
if (j[0].frame >= j[0].nAttendFeu) j[0].frame = 0;
1149
case J2_DEPLACE: j[1].anim = ATTEND;
1150
if (repimg = !repimg) j[1].frame ++;
1151
if (j[1].frame >= j[1].nAttend) j[1].frame = 0;
1156
case J2_TROU: j[1].anim = ATTENDFEU;
1157
if (repimg = !repimg) j[1].frame ++;
1158
if (j[1].frame >= j[1].nAttendFeu) j[1].frame = 0;
1165
// Fait jouer les joueurs humains ou ordis
1169
if (j[0].type == ORDI) Ordi_Deplace (&x, &y, j, 0, grille);
1171
if (Deplacer_Joueur (x, y, j, 0, &grille, jeu, NON, &chxmenu))
1173
if (chxmenu) goto chx_menu;
1174
if (jeu->DOUBLE_DEPLACE && !(bis = !bis)) break;
1180
if (j[0].type == ORDI) Ordi_Trou (&x, &y, j, 1, grille);
1182
if (Placer_Trou (x, y, j, 0, &grille, jeu, NON, &chxmenu))
1184
if (chxmenu) goto chx_menu;
1185
if (jeu->DOUBLE_BOULEFEU && !(bis = !bis)) break;
1186
action = J2_DEPLACE;
1191
if (j[1].type == ORDI) Ordi_Deplace (&x, &y, j, 1, grille);
1193
if (Deplacer_Joueur (x, y, j, 1, &grille, jeu, NON, &chxmenu))
1195
if (chxmenu) goto chx_menu;
1196
if (jeu->DOUBLE_DEPLACE && !(bis = !bis)) break;
1202
if (j[1].type == ORDI) Ordi_Trou (&x, &y, j, 0, grille);
1204
if (Placer_Trou (x, y, j, 1, &grille, jeu, NON, &chxmenu))
1206
if (chxmenu) goto chx_menu;
1207
if (jeu->DOUBLE_BOULEFEU && !(bis = !bis)) break;
1208
action = J1_DEPLACE;
1210
// Place al�atoirement une boule si l'option est activ�e
1211
if (jeu->INTEMP) while (!(Intemperie (j, &grille, jeu, &chxmenu)));
1212
if (chxmenu) goto chx_menu;
1219
if (chxmenu == QUITTER)
1220
{ Destructeur (j, &grille);
1223
if (chxmenu == MENU)
1224
{ Destructeur (j, &grille);
1227
if (chxmenu == REFAIRE)
1228
{ Destructeur (j, &grille);