@@ -52,31 +52,13 @@ void deplacerjoueur(int carte[][45], SDL_Rect *pos, int direction)
52
52
}
53
53
}
54
54
55
- void epee (SDL_Surface * LinkActuel , SDL_Rect positionjoueur , SDL_Renderer * rendu , int carte [][45 ])
55
+ void epee (SDL_Surface * LinkActuel , SDL_Rect positionjoueur , SDL_Renderer * rendu , int carte [][45 ], int direction )
56
56
{
57
- int etat , i ;
57
+ int i ;
58
58
const Uint8 * keystates = SDL_GetKeyboardState (NULL );
59
59
SDL_Surface * LinkEpee ;
60
- if ((LinkActuel == BAS [1 ]) || (LinkActuel == BAS [2 ]) || (LinkActuel == BAS [3 ]))
61
- {
62
- etat = 1 ;
63
- }
64
- else if ((LinkActuel == HAUT [1 ]) || (LinkActuel == HAUT [2 ]) || (LinkActuel == HAUT [3 ]))
65
- {
66
- etat = 2 ;
67
- }
68
- else if ((LinkActuel == GAUCHE [1 ]) || (LinkActuel == GAUCHE [2 ]) || (LinkActuel == GAUCHE [3 ]))
69
- {
70
- etat = 3 ;
71
- }
72
- else if ((LinkActuel == DROITE [1 ]) || (LinkActuel == DROITE [2 ]) || (LinkActuel == DROITE [3 ]))
73
- {
74
- etat = 4 ;
75
- }
76
60
77
- switch (etat )
78
- {
79
- case 1 :
61
+ if (direction == bas ){
80
62
while (keystates [SDL_SCANCODE_SPACE ])
81
63
{
82
64
i = 1 ;
@@ -105,7 +87,8 @@ void epee(SDL_Surface *LinkActuel, SDL_Rect positionjoueur, SDL_Renderer *rendu,
105
87
afficher (rendu , LinkEpee , positionjoueur );
106
88
SDL_Delay (70 );
107
89
}
108
- case 2 :
90
+ }
91
+ else if (direction == haut ){
109
92
while (keystates [SDL_SCANCODE_SPACE ])
110
93
{
111
94
i = 1 ;
@@ -126,8 +109,8 @@ void epee(SDL_Surface *LinkActuel, SDL_Rect positionjoueur, SDL_Renderer *rendu,
126
109
afficher (rendu , LinkEpee , positionjoueur );
127
110
SDL_Delay (100 );
128
111
}
129
- break ;
130
- case 3 :
112
+ }
113
+ else if ( direction == gauche ){
131
114
while (keystates [SDL_SCANCODE_SPACE ])
132
115
{
133
116
i = 1 ;
@@ -155,8 +138,8 @@ void epee(SDL_Surface *LinkActuel, SDL_Rect positionjoueur, SDL_Renderer *rendu,
155
138
afficher (rendu , LinkEpee , positionjoueur );
156
139
SDL_Delay (100 );
157
140
}
158
- break ;
159
- case 4 :
141
+ }
142
+ else if ( direction == droite ){
160
143
while (keystates [SDL_SCANCODE_SPACE ])
161
144
{
162
145
i = 1 ;
@@ -184,9 +167,6 @@ void epee(SDL_Surface *LinkActuel, SDL_Rect positionjoueur, SDL_Renderer *rendu,
184
167
afficher (rendu , LinkEpee , positionjoueur );
185
168
SDL_Delay (100 );
186
169
}
187
- break ;
188
- default :
189
- break ;
190
170
}
191
171
}
192
172
@@ -224,7 +204,7 @@ void celebretion(SDL_Rect positionjoueur, SDL_Renderer *rendu){
224
204
225
205
226
206
227
- void mouvement (SDL_Renderer * rendu , SDL_Surface * LinkActuel , SDL_Rect * positionjoueur , int carte [][45 ], bool keys [322 ]){
207
+ void mouvement (SDL_Renderer * rendu , SDL_Surface * LinkActuel , SDL_Rect * positionjoueur , int carte [][45 ], bool keys [322 ], int * direction ){
228
208
const Uint8 * keystates = SDL_GetKeyboardState (NULL );
229
209
int i ,j ;
230
210
if (keys [SDL_SCANCODE_UP ])
@@ -243,6 +223,7 @@ void mouvement(SDL_Renderer *rendu, SDL_Surface *LinkActuel, SDL_Rect *positionj
243
223
}
244
224
LinkActuel = HAUT [3 ];
245
225
afficher (rendu , LinkActuel , * positionjoueur );
226
+ * direction = haut ;
246
227
}
247
228
else if (keys [SDL_SCANCODE_DOWN ])
248
229
{
@@ -260,6 +241,7 @@ void mouvement(SDL_Renderer *rendu, SDL_Surface *LinkActuel, SDL_Rect *positionj
260
241
}
261
242
LinkActuel = BAS [3 ];
262
243
afficher (rendu , LinkActuel , * positionjoueur );
244
+ * direction = bas ;
263
245
}
264
246
else if (keys [SDL_SCANCODE_RIGHT ])
265
247
{
@@ -277,6 +259,7 @@ void mouvement(SDL_Renderer *rendu, SDL_Surface *LinkActuel, SDL_Rect *positionj
277
259
}
278
260
LinkActuel = DROITE [3 ];
279
261
afficher (rendu , LinkActuel , * positionjoueur );
262
+ * direction = droite ;
280
263
}
281
264
else if (keys [SDL_SCANCODE_LEFT ])
282
265
{
@@ -294,6 +277,7 @@ void mouvement(SDL_Renderer *rendu, SDL_Surface *LinkActuel, SDL_Rect *positionj
294
277
}
295
278
LinkActuel = GAUCHE [3 ];
296
279
afficher (rendu , LinkActuel , * positionjoueur );
280
+ * direction = gauche ;
297
281
}
298
282
}
299
283
@@ -325,7 +309,15 @@ bool devantPort(SDL_Rect positionjoueur, SDL_Renderer *rendu, int carte[][45])
325
309
bool sortmaison (SDL_Rect positionjoueur , SDL_Renderer * rendu , int carte [][45 ])
326
310
{
327
311
bool porte = false;
328
- if (positionjoueur .x == 7 && positionjoueur .y == 11 )
312
+ if (positionjoueur .x == 7 && positionjoueur .y == 10 )
313
+ {
314
+ porte = true;
315
+ }
316
+ else if (positionjoueur .x == 8 && positionjoueur .y == 10 )
317
+ {
318
+ porte = true;
319
+ }
320
+ else if (positionjoueur .x == 7 && positionjoueur .y == 11 )
329
321
{
330
322
porte = true;
331
323
}
0 commit comments