~ubuntu-branches/ubuntu/saucy/dossizola/saucy

« back to all changes in this revision

Viewing changes to .pc/debian-changes-1.0-8.3/dossizola/jeu.c

  • Committer: Bazaar Package Importer
  • Author(s): Jari Aalto
  • Date: 2010-11-05 16:16:25 UTC
  • Revision ID: james.westby@ubuntu.com-20101105161625-sih2fme049kwo4th
Tags: 1.0-8.3
* Non-maintainer upload.
  - Move to packaging format "3.0 (quilt)" due to desktop image files.
  - NMU approved by maintainer, see #549545.
* debian/compat
  - Update obsolete 5 to 8.
* debian/control
  - (Build-Depends): Add autotools-dev due to config.{sub,guess}.
    Update to debhelper 8.
  - (Depends) update tag "Source-Version" to "source:Version"
    to correct binNMU. Patch tanks to Lior Kaplan <kaplan@debian.org>
    (normal; Closes: #435939).
  - (Homepage): New field.
  - (Standards-Version): Update to 3.9.1.
  - Package dossizola
    + (Depends): Add ${misc:Depends} (Lintian).
  - Package dossizola-data
    + (Depends): New. Add ${misc:Depends} (Lintian).
    + (Description): Extend (Lintian).
* debian/copyright
  - Point to GPL-2, save as UTF-8, add copyright years (Lintian).
  - Add FSF preamble (Lintian).
  - Point URL to canonical Sourceforge project.
* debian/dossizola.{desktop,png,xcf}
  - New. Supplied by Stéphane Blondon <stephane.blondon@gmail.com>.
    (minor; Closes: #573870).
* debian/dossizola.sgml
  - (refnamediv): Fix bad whatis entry. Must be same as <refmeta> (Lintian).
* debian/rules
  - (PACKAGE, PKGDIR, SHAREROOTDIR, ICONDIR, DESKTOPDIR): New variables.
  - (binary-indep): Comment out dh_installchangelogs because upsream
    ChangeLog is empty (Lintian).
  - (clean): Cann makefile only if it exists. Delete Makefile.
  - (configure-stamp): use latest config.{sub,guess}
    (wishlist, FTBFS avr32; Closes: #549545).
  - (install): Change obsolete "dh_clean -k" to "dh_prep" (Lintian).
    Add install commands for *.desktop file and icons.
* debian/preinst
  - Add "set -e" (Lintian).
* debian/source/{format,include-binaries}
  - New files.
* debian/watch
  - New file (Lintian).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <SDL/SDL.h>
 
2
#include <SDL/SDL_image.h>
 
3
#include "isola.h"
 
4
 
 
5
// ****************************************************************************
 
6
// ******************************* Tester_Menu ********************************
 
7
// ****************************************************************************
 
8
CHXMENU Tester_Menu (SDL_Event *evt, BOOL fQuitter, BOOL fMenu, BOOL fRefaire, BOOL fConseil, JEU *jeu)
 
9
{
 
10
        int i;
 
11
        int x, y;
 
12
        
 
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))
 
16
                        return QUITTER;
 
17
        
 
18
        // Place le curseur aux bonnes coordonn�es
 
19
        if (evt->type == SDL_MOUSEMOTION)
 
20
        {       x = evt->motion.x;
 
21
                y = evt->motion.y;
 
22
        }
 
23
        else if (evt->type == SDL_MOUSEBUTTONDOWN)
 
24
        {       x = evt->button.x;
 
25
                y = evt->button.y;
 
26
        }
 
27
        else return RIEN;
 
28
        
 
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]);
 
32
        
 
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);
 
42
        
 
43
        SDL_UpdateRects (jeu->ecran, 4, jeu->rMenu);
 
44
        
 
45
        if (evt->type == SDL_MOUSEBUTTONDOWN && evt->button.button == 1)                // Clic bouton gauche
 
46
        {
 
47
                if (fQuitter && Dans_Rect (x, y, jeu->rMenu[0]))
 
48
                        if (Questionner (TXT_QSTQUITTER, jeu->police1, jeu->police2, jeu->police3, jeu->ecran))
 
49
                                return QUITTER;
 
50
                if (fMenu && Dans_Rect (x, y, jeu->rMenu[1]))
 
51
                        if (Questionner (TXT_QSTMENU, jeu->police1, jeu->police2, jeu->police3, jeu->ecran))
 
52
                                return MENU;
 
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);
 
57
                                return REFAIRE;
 
58
                        }
 
59
                if (fConseil && Dans_Rect (x, y, jeu->rMenu[3]))
 
60
                        return CONSEIL;
 
61
                
 
62
                SDL_GetMouseState (&x, &y);
 
63
                evt->type = SDL_MOUSEMOTION;
 
64
                evt->motion.x = x;
 
65
                evt->motion.y = y;
 
66
                SDL_PeepEvents (evt, 1, SDL_ADDEVENT, SDL_MOUSEMOTIONMASK);
 
67
        }
 
68
        
 
69
        return RIEN;
 
70
}
 
71
 
 
72
 
 
73
// ****************************************************************************
 
74
// ***************************** Afficher_Joueur ******************************
 
75
// ****************************************************************************
 
76
void Afficher_Joueur (JOUEUR *j, SDL_Surface *ecran)
 
77
{       
 
78
        SDL_Surface *img;               // Surface contenant l'animation en cours
 
79
        int n;                                  // Nombre d'images de l'animation en cours
 
80
        
 
81
        // Si l'animation est l'un des 4 d�placements
 
82
        if (j->anim >= COURSB && j->anim <= COURSD)
 
83
        {       
 
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);
 
90
                return;
 
91
        }
 
92
        
 
93
        // Autre type d'animation
 
94
        else
 
95
        {
 
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; }
 
101
                
 
102
                // Place le rectangle source � la bonne position en fonction de l'image � afficher dans l'animation
 
103
                j->src.w = img->w / n;
 
104
                j->src.h = img->h;      
 
105
                j->src.x = j->src.w * j->frame;
 
106
                j->src.y = 0;
 
107
                SDL_BlitSurface (img, &j->src, ecran, &j->rect);
 
108
        }
 
109
}
 
110
 
 
111
 
 
112
// ****************************************************************************
 
113
// ****************************** Secouer_Ecran *******************************
 
114
// ****************************************************************************
 
115
void Secouer_Ecran (JOUEUR j[], GRILLE grille, SDL_Surface *ecran)
 
116
{
 
117
        SDL_Rect fond, rect;
 
118
        int xDecal, yDecal;
 
119
        int i;
 
120
 
 
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;
 
128
        
 
129
        // D�place al�atoirement la grille
 
130
        for (i = 0; i <= TREMBLE_NB / TREMBLE_VITESSE; i ++)
 
131
    {
 
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;
 
137
                
 
138
                // Affiche le fond
 
139
                SDL_BlitSurface (grille.imgFond, &fond, ecran, &fond);
 
140
                
 
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);
 
146
                
 
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;
 
152
                
 
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);
 
155
                
 
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;
 
161
                
 
162
                Attendre_FPS ();
 
163
                SDL_UpdateRects (ecran, 1, &fond);
 
164
        }
 
165
}
 
166
 
 
167
 
 
168
// ****************************************************************************
 
169
// ******************************** Intemperie ********************************
 
170
// ****************************************************************************
 
171
BOOL Intemperie (JOUEUR j[], GRILLE *grille, JEU *jeu, CHXMENU *chxmenu)
 
172
{
 
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
 
183
        *chxmenu = RIEN;
 
184
        
 
185
        // Choisit al�atoirement une case de la grille
 
186
        x = Alea (0, grille->xc);
 
187
        y = Alea (0, grille->yc);
 
188
        
 
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;
 
192
        
 
193
        // Choisit al�atoirement une animation
 
194
        n = Alea (0, 2);
 
195
        if (n != 0 || n != 1) n = 0;
 
196
        
 
197
        // Choisit al�atoirement le bord de l'�cran d'o� sera lanc� la boule de feu
 
198
        switch (Alea (0, 2))
 
199
        {
 
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;
 
202
                                break;
 
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);
 
205
                                break;
 
206
                default:        xDep = yDep = 0;
 
207
        }
 
208
        
 
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;
 
212
        
 
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;
 
216
        src.x = src.y = 0;
 
217
        dest.x = dest.y = 0;
 
218
        
 
219
        // Boucle de l'animation tant que toutes l'animation de la boule de feu n'a pas �t� faite
 
220
        do
 
221
        {
 
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;
 
226
                }
 
227
                else
 
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);
 
234
                }
 
235
 
 
236
                // R�affiche le d�cor sur l'ancienne position
 
237
                SDL_BlitSurface (jeu->back, &dest, jeu->ecran, &dest);
 
238
                
 
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);
 
242
                
 
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);
 
246
                
 
247
                // Copie l'image de la boule de feu sur l'�cran
 
248
                prec = dest;
 
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);
 
252
                
 
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;
 
257
                
 
258
                // Attend d'�tre synchronis� sur la vitesse d'affichage et rafra�chit l'�cran
 
259
                Attendre_FPS ();
 
260
                SDL_UpdateRects (jeu->ecran, 1, &dest);
 
261
                SDL_UpdateRects (jeu->ecran, 1, &prec);
 
262
        }
 
263
        while (++ frame <= j[n].nFeu*2);
 
264
        
 
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);
 
269
        
 
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);
 
274
        
 
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);
 
279
        
 
280
        // Fait trembler l'�cran
 
281
        Secouer_Ecran (j, *grille, jeu->ecran);
 
282
        
 
283
        return OUI;
 
284
}
 
285
 
 
286
 
 
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)
 
291
{
 
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
 
302
        *chxmenu = RIEN;
 
303
        
 
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;
 
307
        
 
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);
 
311
        
 
312
        // Si un conseil est demand�, l'affiche et rend le joueur et la boule transparents
 
313
        if (conseil)
 
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);
 
317
        }
 
318
        
 
319
        // Animation du joueur qui lance la boule
 
320
        j[n].anim = LANCE;
 
321
        j[n].frame = 0;
 
322
        frame = -30;
 
323
        
 
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;
 
333
        src.x = src.y = 0;
 
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);
 
338
        
 
339
        // Boucle de l'animation tant que toutes l'animation de la boule de feu n'a pas �t� faite
 
340
        do
 
341
        {
 
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;
 
346
                }
 
347
                else
 
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);
 
354
                }
 
355
                
 
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);
 
359
                
 
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 ++;
 
363
                
 
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);
 
367
                
 
368
                // Anime la boule � partir de la frame 0 (on a commenc� � -30)
 
369
                if (frame > 0)
 
370
                {
 
371
                        // Copie l'image de la boule de feu sur l'�cran
 
372
                        prec = dest;
 
373
                        if (frame < 30)
 
374
                        {       xPos += xDecal/2.0;
 
375
                                yPos += yDecal/2.0;
 
376
                        }
 
377
                        else if (frame < 45)
 
378
                        {       xPos += xDecal;
 
379
                                yPos += yDecal;
 
380
                        }
 
381
                        else
 
382
                        {       xPos += xDecal*2.0;
 
383
                                yPos += yDecal*2.0;
 
384
                        }
 
385
                        dest.x = (int) xPos;
 
386
                        dest.y = (int) yPos;
 
387
                        SDL_BlitSurface (j[n].imgFeu, &src, jeu->ecran, &dest);
 
388
                        
 
389
                        // La boule monte ou descend ? affiche l'image suivante ou pr�cedente dans l'animation
 
390
                        if (monte) src.x += src.w;
 
391
                        else       src.x -= src.w;
 
392
                        if (src.x >= j[n].nFeu * src.w - src.w) monte = NON;
 
393
                }
 
394
                
 
395
                // Attend d'�tre synchronis� sur la vitesse d'affichage et rafra�chit l'�cran
 
396
                Attendre_FPS ();
 
397
                SDL_UpdateRects (jeu->ecran, 1, &j[n].rect);
 
398
                if (frame > 0)
 
399
                {       SDL_UpdateRects (jeu->ecran, 1, &dest);
 
400
                        SDL_UpdateRects (jeu->ecran, 1, &prec);
 
401
                }
 
402
        }
 
403
        while (++ frame < j[n].nFeu * 2);
 
404
        
 
405
        // Si un conseil �tait demand� remet les animations � leur transparence d'origine et efface la boule
 
406
        if (conseil)
 
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);
 
414
        }
 
415
        else
 
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);
 
420
                
 
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);
 
425
                
 
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);
 
430
                
 
431
                // Fait trembler l'�cran
 
432
                Secouer_Ecran (j, *grille, jeu->ecran);
 
433
        }
 
434
        
 
435
        return OUI;
 
436
}
 
437
 
 
438
 
 
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)
 
443
{
 
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
 
449
        int frame;
 
450
        *chxmenu = RIEN;
 
451
        
 
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;
 
454
        
 
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);
 
458
        
 
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;
 
464
        j[n].frame = 0;
 
465
        
 
466
        // Si c'est un conseil qui est demand�, sauvegarde la position du joueur et affiche le titre "CONSEIL"
 
467
        if (conseil)
 
468
        {       save = j[n].rect;
 
469
                src.x = src.y = 0;
 
470
                src.w = j[n].src.w;
 
471
                src.h = j[n].src.h;
 
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);
 
473
        }
 
474
        
 
475
        // Animation du joueur qui court d'une case � l'autre
 
476
        for (frame = 0; frame < grille->imgCase->w; frame += 2)
 
477
        {
 
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;
 
482
                }
 
483
                else
 
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);
 
490
                }
 
491
                
 
492
                // Efface l'ancienne position du joueur
 
493
                SDL_BlitSurface (jeu->back, &j[n].rect, jeu->ecran, &j[n].rect);
 
494
                
 
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;
 
497
                
 
498
                // D�place le rectangle destination sur l'�cran selon la direction o� se d�place le joueur
 
499
                prec = j[n].rect;
 
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;
 
504
                
 
505
                // Affiche les joueurs avec le plus en avant par dessus l'autre
 
506
                if (conseil)
 
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);
 
510
                }
 
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);
 
513
                if (conseil)
 
514
                {       SDL_SetAlpha (j[n].imgCours, SDL_SRCALPHA, 0);
 
515
                }
 
516
                
 
517
                // Attend d'�tre synchronis� sur la vitesse d'affichage et rafra�chit l'�cran
 
518
                Attendre_FPS ();
 
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);
 
522
                
 
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;
 
526
        }
 
527
        
 
528
        if (conseil)
 
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);
 
533
                j[n].rect = save;
 
534
        }
 
535
        else
 
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
 
539
                j[n].x = x;
 
540
                j[n].y = y;
 
541
                // Et entre sa nouvelle position dans la grille
 
542
                grille->c[j[n].x][j[n].y] = j[n].n;
 
543
        }
 
544
        return OUI;
 
545
}
 
546
 
 
547
 
 
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)
 
552
{
 
553
        int alpha;                                      // Valeur de la transparence de l'image du joueur
 
554
        SDL_Event evt;
 
555
        int xSouris, ySouris;           // Coords de la souris
 
556
        *chxmenu = RIEN;
 
557
        
 
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;
 
560
        
 
561
        // Coordonn�es du joueur dans la grille
 
562
        if (!conseil) grille->c[x][y] = j[n].n;
 
563
        j[n].x = x;
 
564
        j[n].y = y;
 
565
        
 
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;
 
569
        
 
570
        // Le joueur appara�t progressivement (en diminuant sa transparence)
 
571
        for (alpha = 250; alpha >= 0; alpha -= 10)
 
572
        {
 
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;
 
577
                }
 
578
                else
 
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);
 
585
                }
 
586
                
 
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);
 
590
                
 
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);
 
594
                
 
595
                // Attend d'�tre synchronis� sur la vitesse d'affichage et rafra�chit l'�cran
 
596
                Attendre_FPS ();
 
597
                SDL_UpdateRects (jeu->ecran, 1, &j[n].rect);
 
598
        }
 
599
        
 
600
        if (conseil)
 
601
        {       SDL_BlitSurface (jeu->back, &j[n].rect, jeu->ecran, &j[n].rect);
 
602
                SDL_UpdateRects (jeu->ecran, 1, &j[n].rect);
 
603
        }
 
604
        
 
605
        return OUI;
 
606
}
 
607
 
 
608
 
 
609
// ****************************************************************************
 
610
// ******************************** Placer_Joueurs ****************************
 
611
// ****************************************************************************
 
612
void Placer_Joueurs (JEU *jeu, JOUEUR j[], GRILLE *grille, CHXMENU *chxmenu)
 
613
{
 
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
 
617
        *chxmenu = RIEN;
 
618
        
 
619
        while (1)
 
620
        {
 
621
                // Placement d'un joueur dirig� par l'ordinateur
 
622
                if (j[tour].type == ORDI)
 
623
                {       
 
624
                        Ordi_Place (&x, &y, j[tour], *grille);
 
625
                        Placer_Joueur (x, y, j, tour, grille, jeu, NON, chxmenu);
 
626
                        if (*chxmenu) return;
 
627
                        
 
628
                        // Incr�mente le tour et quitte si tous les joueurs ont �t� plac�s
 
629
                        if (++ tour == 2) return;
 
630
                        continue;
 
631
                }
 
632
                
 
633
                if (SDL_PollEvent (&evt))
 
634
                {
 
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);
 
640
                
 
641
                        if (evt.type == SDL_MOUSEBUTTONDOWN && evt.button.button == 1)  // Bouton gauche enfonc�
 
642
                        {
 
643
                                x = Clic2CaseX (evt.button.x, *grille);         // R�cup�re les coords
 
644
                                y = Clic2CaseY (evt.button.y, *grille);         // de la case cliqu�e
 
645
                                
 
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;
 
652
                        }
 
653
                        
 
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;
 
660
                        }
 
661
                        else if (*chxmenu) return;
 
662
                        //if (*chxmenu != RIEN && *chxmenu != CONSEIL) return;
 
663
                }
 
664
                else
 
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;
 
668
                        evt.motion.x = x;
 
669
                        evt.motion.y = y;
 
670
                        SDL_PeepEvents (&evt, 1, SDL_ADDEVENT, SDL_MOUSEMOTIONMASK);
 
671
                }
 
672
        }
 
673
}
 
674
 
 
675
 
 
676
// ****************************************************************************
 
677
// ****************************** Constructeur ********************************
 
678
// ****************************************************************************
 
679
void Constructeur (JOUEUR j[], GRILLE *grille, BOOL c, SDL_Surface *ecran, SDL_Surface *back)
 
680
{
 
681
        SDL_Surface *img;                       // Surface contenant temporairement une image
 
682
        SDL_Rect src, dest;                     // Rectangles de copie d'image
 
683
        int x, y;
 
684
        
 
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);
 
689
                exit (1);
 
690
        }
 
691
        
 
692
        // Charge l'image de fond ...
 
693
        switch (Alea (1, 6))
 
694
        {
 
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;
 
701
        }
 
702
        if (!(img = IMG_Load (fichier))) ImageErreur (fichier);
 
703
        
 
704
        // ... et l'affiche en mosaique dans l'arri�re plan
 
705
        src.x = src.y = 0;
 
706
        
 
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)
 
709
                {       
 
710
                        src.w = dest.w = img->w;
 
711
                        src.h = dest.h = img->h;
 
712
                        SDL_BlitSurface (img, &src, grille->imgFond, &dest);
 
713
                }
 
714
        
 
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);
 
718
        
 
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);
 
721
        IMG_InvertAlpha (0);
 
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);
 
757
        
 
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;
 
766
        
 
767
        // Animation courante et image � afficher
 
768
        j[c].anim = j[!c].anim = COURSB;
 
769
        j[c].frame = j[!c].frame = 0;
 
770
        
 
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));
 
786
        
 
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);
 
793
                
 
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;
 
799
        
 
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;
 
804
        
 
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;
 
811
        
 
812
        // Copie les cases de la grille dans le back buffer
 
813
        dest.w = dest.h = grille->tc;
 
814
        
 
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);
 
818
 
 
819
        // Met � jour l'�cran entier
 
820
        SDL_BlitSurface (back, NULL, ecran, NULL);
 
821
        SDL_UpdateRect (ecran, 0, 0, ecran->w, ecran->h);
 
822
}
 
823
 
 
824
 
 
825
// ****************************************************************************
 
826
// ****************************** Destructeur *********************************
 
827
// ****************************************************************************
 
828
void Destructeur (JOUEUR j[], GRILLE *grille)
 
829
{
 
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);
 
843
}
 
844
 
 
845
 
 
846
// ****************************************************************************
 
847
// ****************************** Tester_Perdu ********************************
 
848
// ****************************************************************************
 
849
BOOL Tester_Perdu (JOUEUR j, GRILLE grille)
 
850
{
 
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;
 
855
        
 
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;
 
858
        
 
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;
 
862
        
 
863
        return OUI;
 
864
}
 
865
 
 
866
 
 
867
// ****************************************************************************
 
868
// ************************** Animer_Perdant_Gagnant **************************
 
869
// ****************************************************************************
 
870
void Animer_Perdant_Gagnant (JOUEUR *j1, JOUEUR *j2, JEU *jeu, CHXMENU *chxmenu)
 
871
{
 
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
 
876
        const int xmin = 50;
 
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;
 
880
        int duree = 0;
 
881
        int vitesse = 1;
 
882
        int xdir = 0, ydir = 0;
 
883
        *chxmenu = RIEN;
 
884
        
 
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;
 
888
        j2->rect.x -= 32;
 
889
        j2->rect.y -= 16;
 
890
        // R�gle les animations
 
891
        j1->anim = GAGNE;
 
892
        j2->anim = PERDU;
 
893
        j1->frame = 0;
 
894
        j2->frame = 10;
 
895
        
 
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);
 
899
        
 
900
        // Animation des joueurs
 
901
        while (1)
 
902
        {
 
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;
 
907
                }
 
908
                else
 
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);
 
915
                }
 
916
                
 
917
                // Impulsion du saut p�rilleux
 
918
                prec1 = j1->rect;
 
919
                if (j1->frame > 3  && j1->frame <= 11) j1->rect.y -= 6;
 
920
                if (j1->frame > 11 && j1->frame <= 19)  j1->rect.y += 6;
 
921
                
 
922
                // Impulsion des ailes
 
923
                if (j2->frame == 10)
 
924
                        vitesse = 3;
 
925
                if (j2->frame == 16)
 
926
                        vitesse = 1;
 
927
                
 
928
                // Direction de l'ange fix� pendant dur�e
 
929
                if (--duree < 0)
 
930
                {       duree = Alea (25, 40);
 
931
                        xdir = Alea (-1, 2);
 
932
                        ydir = Alea (-1, 2);
 
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;
 
937
                }
 
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;
 
943
                prec2 = j2->rect;
 
944
                j2->rect.x += vitesse * xdir;
 
945
                j2->rect.y += vitesse * ydir;
 
946
                
 
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);
 
952
                
 
953
                // Affiche les joueurs anim�s
 
954
                Afficher_Joueur (j1, jeu->ecran);
 
955
                Afficher_Joueur (j2, jeu->ecran);
 
956
                
 
957
                // Attend d'�tre synchronis� sur la vitesse d'affichage et rafra�chit l'�cran
 
958
                Attendre_FPS ();
 
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);
 
963
                
 
964
                // Passe � l'image suivante dans l'animation et reboucle si besoin
 
965
                if (bis = !bis)
 
966
                {       j1->frame ++;
 
967
                        j2->frame ++;
 
968
                }
 
969
                if (j1->frame >= j1->nGagne) j1->frame = 0;
 
970
                if (j2->frame >= j2->nPerdu) j2->frame = 0;
 
971
        }
 
972
}
 
973
 
 
974
 
 
975
// ****************************************************************************
 
976
// *********************************** Jeu ************************************
 
977
// ****************************************************************************
 
978
BOOL Jeu (JEU *jeu)
 
979
{
 
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
 
988
        int n;
 
989
        
 
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;
 
993
        
 
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;
 
1005
        
 
1006
debut_jeu:
 
1007
        Constructeur (j, &grille, jeu->J1ROUGE, jeu->ecran, jeu->back); // Charge les images, la grille, ...
 
1008
        
 
1009
        // Valeurs de d�part
 
1010
        action = J1_DEPLACE;
 
1011
        bis = OUI;
 
1012
        repimg = OUI;
 
1013
        chxmenu = RIEN;
 
1014
        
 
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;
 
1020
        
 
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);
 
1028
        
 
1029
        Placer_Joueurs (jeu, j, &grille, &chxmenu);     // Pour choisir la position de d�part
 
1030
        if (chxmenu) goto chx_menu;
 
1031
        
 
1032
        // Boucle de jeu principale
 
1033
        while (1)
 
1034
        {
 
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)))
 
1037
                {       
 
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);
 
1041
                        
 
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);
 
1049
                        
 
1050
                        // Quel joueur a perdu ?
 
1051
                        if ((action == J1_DEPLACE || action == J2_TROU) && Tester_Perdu (j[0], grille)) n = 0;
 
1052
                        else n = 1;
 
1053
                        
 
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;
 
1058
                        
 
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;
 
1062
                }
 
1063
                
 
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))
 
1066
                {       
 
1067
                        // Affiche l'action en cours
 
1068
                        SDL_BlitSurface (jeu->back, &jeu->titre, jeu->ecran, &jeu->titre);
 
1069
                        switch (action)
 
1070
                        {
 
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);
 
1072
                                                                        break;
 
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);
 
1074
                                                                        break;
 
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);
 
1076
                                                                        break;
 
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);
 
1078
                                                                        break;
 
1079
                        }
 
1080
                        SDL_UpdateRects (jeu->ecran, 1, &jeu->titre);
 
1081
                        
 
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);
 
1089
                        Attendre_FPS ();
 
1090
                        
 
1091
                        if (SDL_PollEvent (&evt))               // Attend un �v�nement
 
1092
                        {
 
1093
                                if (evt.type == SDL_MOUSEBUTTONDOWN && evt.button.button == 1)          // Clic bouton gauche
 
1094
                                {
 
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);
 
1098
                                        
 
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;
 
1101
                                }
 
1102
                                
 
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)
 
1106
                                {       
 
1107
                                        if (action == J1_DEPLACE || action == J1_TROU) n = 0;
 
1108
                                        else n = 1;
 
1109
                                        
 
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);
 
1113
                                        }
 
1114
                                        else
 
1115
                                        {       Ordi_Trou (&x, &y, j, !n, grille);
 
1116
                                                Placer_Trou (x, y, j, n, &grille, jeu, OUI, &chxmenu);
 
1117
                                        }
 
1118
                                        
 
1119
                                        if (chxmenu) goto chx_menu;
 
1120
                                }
 
1121
                                else if (chxmenu != RIEN) goto chx_menu;
 
1122
                        }
 
1123
                        else
 
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;
 
1127
                                evt.motion.x = x;
 
1128
                                evt.motion.y = y;
 
1129
                                SDL_PeepEvents (&evt, 1, SDL_ADDEVENT, SDL_MOUSEMOTIONMASK);
 
1130
                        }
 
1131
                        
 
1132
                        // R�gle les animations pour le joueur qui attend de jouer et celui qui ne bouge pas
 
1133
                        switch (action)
 
1134
                        {
 
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;
 
1138
                                                                        j[1].anim = COURSB;
 
1139
                                                                        j[1].frame = 0;
 
1140
                                                                        break;
 
1141
                                
 
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;
 
1145
                                                                        j[1].anim = COURSB;
 
1146
                                                                        j[1].frame = 0;
 
1147
                                                                        break;
 
1148
                                
 
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;
 
1152
                                                                        j[0].anim = COURSB;
 
1153
                                                                        j[0].frame = 0;
 
1154
                                                                        break;
 
1155
                                
 
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;
 
1159
                                                                        j[0].anim = COURSB;
 
1160
                                                                        j[0].frame = 0;
 
1161
                                                                        break;
 
1162
                        }
 
1163
                }
 
1164
                
 
1165
                // Fait jouer les joueurs humains ou ordis
 
1166
                switch (action)
 
1167
                {
 
1168
                        case J1_DEPLACE:
 
1169
                                if (j[0].type == ORDI) Ordi_Deplace (&x, &y, j, 0, grille);
 
1170
                                
 
1171
                                if (Deplacer_Joueur (x, y, j, 0, &grille, jeu, NON, &chxmenu))
 
1172
                                {       
 
1173
                                        if (chxmenu) goto chx_menu;
 
1174
                                        if (jeu->DOUBLE_DEPLACE && !(bis = !bis)) break;
 
1175
                                        action = J1_TROU;
 
1176
                                }
 
1177
                                break;
 
1178
                        
 
1179
                        case J1_TROU:
 
1180
                                if (j[0].type == ORDI) Ordi_Trou (&x, &y, j, 1, grille);
 
1181
                                
 
1182
                                if (Placer_Trou (x, y, j, 0, &grille, jeu, NON, &chxmenu))
 
1183
                                {       
 
1184
                                        if (chxmenu) goto chx_menu;
 
1185
                                        if (jeu->DOUBLE_BOULEFEU && !(bis = !bis)) break;
 
1186
                                        action = J2_DEPLACE;
 
1187
                                }
 
1188
                                break;
 
1189
                        
 
1190
                        case J2_DEPLACE:
 
1191
                                if (j[1].type == ORDI) Ordi_Deplace (&x, &y, j, 1, grille);
 
1192
                                
 
1193
                                if (Deplacer_Joueur (x, y, j, 1, &grille, jeu, NON, &chxmenu))
 
1194
                                {       
 
1195
                                        if (chxmenu) goto chx_menu;
 
1196
                                        if (jeu->DOUBLE_DEPLACE && !(bis = !bis)) break;
 
1197
                                        action = J2_TROU;
 
1198
                                }
 
1199
                                break;
 
1200
                        
 
1201
                        case J2_TROU:
 
1202
                                if (j[1].type == ORDI) Ordi_Trou (&x, &y, j, 0, grille);
 
1203
                                
 
1204
                                if (Placer_Trou (x, y, j, 1, &grille, jeu, NON, &chxmenu))
 
1205
                                {       
 
1206
                                        if (chxmenu) goto chx_menu;
 
1207
                                        if (jeu->DOUBLE_BOULEFEU && !(bis = !bis)) break;
 
1208
                                        action = J1_DEPLACE;
 
1209
                                        
 
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;
 
1213
                                }
 
1214
                                break;
 
1215
                }
 
1216
        }
 
1217
 
 
1218
chx_menu:
 
1219
        if (chxmenu == QUITTER)
 
1220
        {       Destructeur (j, &grille);
 
1221
                return OUI;
 
1222
        }
 
1223
        if (chxmenu == MENU)
 
1224
        {       Destructeur (j, &grille);
 
1225
                return NON;
 
1226
        }
 
1227
        if (chxmenu == REFAIRE)
 
1228
        {       Destructeur (j, &grille);
 
1229
                goto debut_jeu;
 
1230
        }
 
1231
}