main.c 17.9 KB
Newer Older
Valentin MEUNIER's avatar
Valentin MEUNIER committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*main.c*/
/*15 juin 2021*/
/*make*/

#include "main.h"

void end_sdl(char ok,char const* msg,SDL_Window* window, SDL_Renderer* renderer)
{
	char msg_formated[255];
	int l;

	if (!ok) 
	{	                             
		strncpy(msg_formated, msg, 250);
		l = strlen(msg_formated);           
		strcpy(msg_formated + l, " : %s\n");
		SDL_Log(msg_formated, SDL_GetError());
	}

	if (renderer != NULL) SDL_DestroyRenderer(renderer);
	if (window != NULL)   SDL_DestroyWindow(window);


	if (!ok) exit(EXIT_FAILURE);
}
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
26

Valentin MEUNIER's avatar
Valentin MEUNIER committed
27
28
void afficherEcranIntelligemment(SDL_Renderer *renderer,int **tab,int taille_cell)
{
Valentin MEUNIER's avatar
enfin    
Valentin MEUNIER committed
29
	int x=0;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
30
31
	SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
	SDL_RenderClear(renderer);
32
33
34
35
	SDL_SetRenderDrawColor(renderer,0,0,0,0);
 	SDL_DisplayMode screen;
	SDL_GetCurrentDisplayMode(0,&screen);
	int decalage_horizontale=(screen.w/taille_cell-P)*taille_cell/3;
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
36
	int decalage_vertical=(screen.h/taille_cell-N)*taille_cell/20;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
37

Valentin MEUNIER's avatar
enfin    
Valentin MEUNIER committed
38
	SDL_SetRenderDrawColor(renderer,0,0,0,0);
Valentin MEUNIER's avatar
disj    
Valentin MEUNIER committed
39
	int i1,j1,noeud=0;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
40
	
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
41
42
43
	for (int i=0;i<N;i++){
                for (int j=0;j<P;j++){
                        x=tab[j][i];
Valentin MEUNIER's avatar
disj    
Valentin MEUNIER committed
44
			i1=(noeud%P);
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
45
                        j1=((int)noeud/P);
Valentin MEUNIER's avatar
disj    
Valentin MEUNIER committed
46

Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
47
48
49
50
51
52
53
54
55
                        if (!(x & FLAG_N)){
                                SDL_RenderDrawLine(renderer,i1*taille_cell+decalage_horizontale,j1*taille_cell+decalage_vertical,(i1+1)*taille_cell+decalage_horizontale,j1*taille_cell+decalage_vertical); //mur au nord
                                }
                        if ((x & FLAG_S)!=2)
                                SDL_RenderDrawLine(renderer,i1*taille_cell+decalage_horizontale,(j1+1)*taille_cell+decalage_vertical,(i1+1)*taille_cell+decalage_horizontale,(j1+1)*taille_cell+decalage_vertical); //mur au sud
                        if ((x & FLAG_E)!=4)
                                SDL_RenderDrawLine(renderer,(i1+1)*taille_cell+decalage_horizontale,j1*taille_cell+decalage_vertical,(i1+1)*taille_cell+decalage_horizontale,(j1+1)*taille_cell+decalage_vertical); //mur à l'est
                        if ((x & FLAG_O)!=8)
                                SDL_RenderDrawLine(renderer,i1*taille_cell+decalage_horizontale,j1*taille_cell+decalage_vertical,i1*taille_cell+decalage_horizontale,(j1+1)*taille_cell+decalage_vertical); //mur à l'ouest
Valentin MEUNIER's avatar
Valentin MEUNIER committed
56

Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
57
                        noeud+=1;
58

Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
59
60
                }
        }
Valentin MEUNIER's avatar
Valentin MEUNIER committed
61
62
}

Valentin MEUNIER's avatar
enfin    
Valentin MEUNIER committed
63
64
65
66
67
68
69
int min(int a, int b)
{
	if (a>b)
		return b;
	else
		return a;
}	
Valentin MEUNIER's avatar
Valentin MEUNIER committed
70
71


Valentin MEUNIER's avatar
Valentin MEUNIER committed
72
int main (int argc, char** argv)
Valentin MEUNIER's avatar
Valentin MEUNIER committed
73
{
Valentin MEUNIER's avatar
Valentin MEUNIER committed
74
	double p;
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
75
76

	//l'argument p regit l'affichage des murs : s'il vaut 0 il n'y a aucun mur, s'il vaut un on a un arbre
Valentin MEUNIER's avatar
Valentin MEUNIER committed
77
	if (argc==2)  p=atof(argv[1]);
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
78
79
	else p=0.75; 
	
Valentin MEUNIER's avatar
Valentin MEUNIER committed
80
81
82
83
84
85
	if (SDL_Init(SDL_INIT_VIDEO) == -1)
	{
		fprintf(stderr, "Erreur d'initialisation de la SDL : %s\n", SDL_GetError());
		return EXIT_FAILURE;
	}

Valentin MEUNIER's avatar
enfin    
Valentin MEUNIER committed
86
87
 	SDL_DisplayMode screen;
	SDL_GetCurrentDisplayMode(0,&screen);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
88
	SDL_Window *window;
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
89

Valentin MEUNIER's avatar
enfin    
Valentin MEUNIER committed
90
	window = SDL_CreateWindow("SDL2 Programme 0.1", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,screen.w,screen.h, SDL_WINDOW_RESIZABLE);
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
91
	
Valentin MEUNIER's avatar
Valentin MEUNIER committed
92
	if (window == 0) fprintf(stderr, "Erreur d'initialisation de la SDL : %s\n", SDL_GetError());
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
93
94
	
	SDL_SetWindowTitle(window, "Labyrinthe");
Valentin MEUNIER's avatar
Valentin MEUNIER committed
95
96
97
98

	SDL_Renderer *renderer;
	renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); /*  SDL_RENDERER_SOFTWARE */
	if (renderer == 0) fprintf(stderr, "Erreur d'initialisation de la SDL : %s\n", SDL_GetError());
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

       // Initialisation de SDL_Mixer
    if (Mix_OpenAudio(96000, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) < 0)
    {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Erreur initialisation SDL_mixer : %s", Mix_GetError());
        SDL_Quit();
        return -1; 
    }   

    Mix_Music* music_mama = Mix_LoadMUS("musique/mama.mp3"); // Charge notre musique

    if (music_mama == NULL)
    {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Erreur chargement de la musique : %s", Mix_GetError());
        Mix_CloseAudio();
        SDL_Quit();
        return -1; 
    }   
    
    Mix_Music* music_vie = Mix_LoadMUS("musique/vie.mp3"); // Charge notre musique

    if (music_vie == NULL)
    {
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Erreur chargement de la musique : %s", Mix_GetError());
        Mix_CloseAudio();
        SDL_Quit();
        return -1; 
    }   

Valentin MEUNIER's avatar
Valentin MEUNIER committed
128
	int running=1;
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
129
	srand(time(0));
Valentin MEUNIER's avatar
Valentin MEUNIER committed
130
	int noeuds=N*P;
Valentin MEUNIER's avatar
enfin    
Valentin MEUNIER committed
131
	int nb_aretes=2*N*P-N-P;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
132
	int **tab;
Valentin MEUNIER's avatar
enfin    
Valentin MEUNIER committed
133
134
	int cours=0;
	int taille_cell=min(screen.w/(P+2),screen.h/(N+2));
Valentin MEUNIER's avatar
Valentin MEUNIER committed
135
	int * tab_parents; // a decommenter pour l'utilisation de Dijkstra
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
136
	//initialisation du graph
Valentin MEUNIER's avatar
enfin    
Valentin MEUNIER committed
137
138
	graph_t * graph=creer_graph(noeuds,nb_aretes);
	generation(graph);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
139
	graph=Fisher(graph,nb_aretes);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
140
	graph=kruskal(graph,noeuds,nb_aretes,&cours,p);
Valentin MEUNIER's avatar
enfin    
Valentin MEUNIER committed
141
	tab=tableau_ligne(graph,cours);
142

Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
143
144
145
146
	//initialisation des differentes textures
	SDL_Texture * texture,*texture_fin,* texture_elve,* texture_elve_reverse;

	texture_elve = load_texture_from_image("Elve_lign.png",renderer);
147
    	if (texture_elve == NULL) fprintf(stderr, "Erreur de chargement de l'image : %s\n", SDL_GetError());//end_sdl(0, "Echec du chargement de l'image dans la texture", window, renderer);
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
148
149
150
151
152
153
154
155
156
157
158

    	texture_elve_reverse = load_texture_from_image("Elve_ligne_reverse.png",renderer);
    	if (texture_elve_reverse == NULL) end_sdl(0, "Echec du chargement de l'image dans la texture", window, renderer);
	
	texture = load_texture_from_image("road.png",renderer);
	if (texture==NULL) exit(EXIT_FAILURE);

	texture_fin = load_texture_from_image("roguelikeChar_transparent.png",renderer);
    	if (texture_fin==NULL) exit(EXIT_FAILURE);


Valentin MEUNIER's avatar
Valentin MEUNIER committed
159
	SDL_Event event;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
160
161
	
	//on initialise une fenêtre 2 pour une mini-map
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
162
163
	SDL_Window *window2;

Valentin MEUNIER's avatar
Valentin MEUNIER committed
164
	window2 = SDL_CreateWindow("SDL2 Programme 0.1", screen.w-screen.w/3, 0,screen.w/3,screen.h/3, SDL_WINDOW_RESIZABLE);
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
165
166
167
168
169
	
	if (window2 == 0) fprintf(stderr, "Erreur d'initialisation de la SDL : %s\n", SDL_GetError());
	
	SDL_SetWindowTitle(window2, "Carte d'exploration");

Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
170
	//on initialise le renderer de la mini-map
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
171
172
173
174
	SDL_Renderer *renderer2;
	renderer2 = SDL_CreateRenderer(window2, -1, SDL_RENDERER_ACCELERATED); /*  SDL_RENDERER_SOFTWARE */
	if (renderer2 == 0) fprintf(stderr, "Erreur d'initialisation de la SDL : %s\n", SDL_GetError());

Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
175
176
177
178
179
180
181
182
183
	//on initialise les textures pour la deuxième fenêtre
	SDL_Texture *texture2,*texture_fin2;

	texture2 = load_texture_from_image("road.png",renderer2);
	if (texture2==NULL) exit(EXIT_FAILURE);

	texture_fin2 = load_texture_from_image("roguelikeChar_transparent.png",renderer2);
    	if (texture_fin2==NULL) exit(EXIT_FAILURE);

Valentin MEUNIER's avatar
Valentin MEUNIER committed
184
	int pause=0;
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
185
186
187
188
189
190
191
192
193
194
195
	int noeud_dep=rand()%TAILLE;
	int right=1;
	int stand=0;
	int pos_x=noeud_dep%P*taille_cell;
	int pos_y=noeud_dep/P*taille_cell;
	float zoom = (float)taille_cell/(float)22;
	int temps=1;
	int deplacement=taille_cell;
	int noeud_arrive=rand()%TAILLE;
	int colli;
	int noeud_actuel;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
196
197
198
	int fin_mama=0;
	int relancer=0;
	int affiche_carte=0;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
199
	int dijkstra_ok=0;
200
	int premier=1;
201
202
203
	int temps_fin=20;
	int perdu=0;
	int compteur=0;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
204
	int * minimap=malloc((TAILLE+1)*sizeof(int));
Valentin MEUNIER's avatar
Valentin MEUNIER committed
205
206
207
	for (int iter=0;iter<TAILLE+1;iter++)
		minimap[iter]=0;
	int taille_cell2=min((screen.w/3)/(P+2),(screen.h/3)/(N+2));
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
208

209
	Mix_PlayMusic(music_mama,-1);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
210
	printf("l : relancer \np,SPACE : pause \ncroix : quitter \nm : afficher la carte complète du labyrinthe pendant 2 secondes\n");
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
211

Valentin MEUNIER's avatar
Valentin MEUNIER committed
212
213
	while (running)
	{
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
214
		noeud_actuel=pos_y*P/taille_cell+pos_x/taille_cell;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
215
216
		minimap[0]++;
		minimap[minimap[0]]=noeud_actuel;
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
217
		if (noeud_actuel==noeud_arrive)
Valentin MEUNIER's avatar
Valentin MEUNIER committed
218
			fin_mama=1;
219
220
		if (temps_fin==0)
			perdu=1;
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
221
		while (SDL_PollEvent(&event))
Valentin MEUNIER's avatar
Valentin MEUNIER committed
222
223
224
225
226
		{
			switch (event.type)
			{
				case SDL_QUIT:
					running = 0;
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
227
					break;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
228
229
230
231
232
233
234
235
236
237
238
239
240
				case SDL_WINDOWEVENT:
					switch (event.window.event)
					{
						case SDL_WINDOWEVENT_CLOSE:
							running = 0;
							break;  
						default:
							break;
					}
					break;
				case SDL_KEYDOWN:
					switch (event.key.keysym.sym)
					{
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
241
						case SDLK_l:
Valentin MEUNIER's avatar
Valentin MEUNIER committed
242
243
244
245
246
							relancer=1;
							break;
						case SDLK_SPACE:
						case SDLK_p:
							pause=!pause;
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
247
248
							break;
						case SDLK_m: //la fonction devra afficher la totalite du labyrinthe sans brouillard de guerre
Valentin MEUNIER's avatar
Valentin MEUNIER committed
249
250
							affiche_carte=1;
							break; 
Valentin MEUNIER's avatar
Valentin MEUNIER committed
251
						case SDLK_r:
Valentin MEUNIER's avatar
Valentin MEUNIER committed
252
							dijkstra_ok=1;
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
253
							break;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
254
255
256
257
258
259
						default:
							break;
					}
         		break;
			}
		}
Valentin MEUNIER's avatar
Valentin MEUNIER committed
260
		if (dijkstra_ok)
Valentin MEUNIER's avatar
Valentin MEUNIER committed
261
		{
262
			if  (premier){	
Valentin MEUNIER's avatar
Valentin MEUNIER committed
263
			tab_parents=dijkstra(tab,graph->noeuds,noeud_arrive);
264
			premier=0;}
Valentin MEUNIER's avatar
Valentin MEUNIER committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
		if(tab_parents[noeud_actuel]/P==(noeud_actuel/P)-1){
			if (right){
        			play_with_elve_N(texture_elve,texture,window,renderer,pos_x,pos_y,deplacement,zoom,tab,taille_cell,texture_fin,noeud_arrive);
        		}
        		else{
        			play_with_elve_N_l(texture_elve_reverse,texture,window,renderer,pos_x,pos_y,deplacement,zoom,tab,taille_cell,texture_fin,noeud_arrive);
       	 		}
        		pos_y=pos_y-deplacement;
        		stand=0;
        	}
		if(tab_parents[noeud_actuel]/P==(noeud_actuel/P)+1){
			if (right){
        			play_with_elve_S(texture_elve,texture,window,renderer,pos_x,pos_y,deplacement,zoom,tab,taille_cell,texture_fin,noeud_arrive);
        		}
        		else{
        			play_with_elve_S_l(texture_elve_reverse,texture,window,renderer,pos_x,pos_y,deplacement,zoom,tab,taille_cell,texture_fin,noeud_arrive);
        		}
        		pos_y=pos_y+deplacement;
        		stand=0;
        	}
		if(tab_parents[noeud_actuel]%P==(noeud_actuel%P)-1){
        		play_with_elve_O(texture_elve_reverse,texture,window,renderer,pos_x,pos_y,deplacement,zoom,tab,taille_cell,texture_fin,noeud_arrive);
        		pos_x=pos_x-deplacement;
        		stand=0;
        		right=0;
        	}
		if(tab_parents[noeud_actuel]%P==(noeud_actuel%P)+1){
			play_with_elve_E(texture_elve,texture,window,renderer,pos_x,pos_y,deplacement,zoom,tab,taille_cell,texture_fin,noeud_arrive);
        		pos_x=pos_x+deplacement;
        		stand=0;
        		right=1;
        	}
        	if (right){
        		switch (stand){
        		        case 0:
                			play_standstill_1(texture_elve,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
                			stand=(stand+1)%7;
                			break;
            			case 2:
                			play_standstill_2(texture_elve,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
                			stand=(stand+1)%7;
                			break;
            			case 4:
                			play_standstill_3(texture_elve,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
                			stand=(stand+1)%7;
                			break;
            			case 6:
                			play_standstill_4(texture_elve,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
                			stand=(stand+1)%7;
                			break;
            			default:
                			stand=(stand+1)%7;
					break;
        	    }
       		 }
        	else{
        		switch (stand){
        	    	case 0:
        	    	    play_standstill_1_l(texture_elve_reverse,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
                		stand=(stand+1)%7;
                		break;
            		case 2:
                		play_standstill_2_l(texture_elve_reverse,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
               	 		stand=(stand+1)%7;
                		break;
            		case 4:
                		play_standstill_3_l(texture_elve_reverse,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
                		stand=(stand+1)%7;
                		break;
            		case 6:
                		play_standstill_4_l(texture_elve_reverse,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
                		stand=(stand+1)%7;
                		break;
            		default:
                		stand=(stand+1)%7;
                	break;
            		}
        	}
Valentin MEUNIER's avatar
Valentin MEUNIER committed
343
		}
344
		if (affiche_carte && !pause && !dijkstra_ok)
Valentin MEUNIER's avatar
Valentin MEUNIER committed
345
346
347
348
349
350
351
352
353
		{
			afficherImage(renderer,window,tab,taille_cell,texture);
			affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
			SDL_RenderPresent(renderer);
			temps++;
				if (temps>50)
				{
					affiche_carte=0;
					SDL_RenderClear(renderer);
354
					temps=1;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
355
356
357
358
359
360
361
362
363
364
365
366
				}
		}
		if (relancer && !pause)
		{
			noeud_dep=rand()%TAILLE;
			right=1;
			stand=0;
			pos_x=noeud_dep%P*taille_cell;
			pos_y=noeud_dep/P*taille_cell;
			temps=1;
			noeud_arrive=rand()%TAILLE;
			relancer=0;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
367
			SDL_RenderClear(renderer2);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
368
			SDL_RenderPresent(renderer2);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
369
			for (int i=1; i<=minimap[0]; i++)
Valentin MEUNIER's avatar
Valentin MEUNIER committed
370
371
372
373
374
				minimap[i]=0;
			minimap[0]=1;
			minimap[1]=pos_y*P/taille_cell+pos_x/taille_cell;
			
		}
375
		if (!pause && !affiche_carte)
Valentin MEUNIER's avatar
Valentin MEUNIER committed
376
		{
377
			compteur+=30;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
378
 			SDL_RenderClear(renderer2);
379
380
381
382
383
384
			if (compteur>1000 && temps_fin>0)
			{
				temps_fin-=1;
				compteur-=1000;
			}
			timer(window2, renderer2,temps_fin);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
385
386
387
388
389
390
			for (int iter=1;iter<minimap[0];iter++)
			{
				peindreMap(texture2,window2,renderer2,minimap[iter],taille_cell2,tab);
				affichage_fin(texture_fin2,window2,renderer2,noeud_arrive/P,noeud_arrive%P,taille_cell2);
				point_minimap(renderer2,taille_cell2,taille_cell2*(noeud_actuel%P),taille_cell2*noeud_actuel/P);
			}	
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
391
			SDL_RenderPresent(renderer2);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
392
393
394
395
			
			const Uint8 *keystates = SDL_GetKeyboardState(NULL);
			if ((keystates[SDL_SCANCODE_UP]||keystates[SDL_SCANCODE_W])) 
			{	
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
396
				colli=collision_N(pos_x,pos_y,tab,taille_cell);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
397
398
399
				if(!colli)
				{
					if (right)
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
400
        					play_with_elve_N(texture_elve,texture,window,renderer,pos_x,pos_y,deplacement,zoom,tab,taille_cell,texture_fin,noeud_arrive);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
401
        				else
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
402
403
404
        					play_with_elve_N_l(texture_elve_reverse,texture,window,renderer,pos_x,pos_y,deplacement,zoom,tab,taille_cell,texture_fin,noeud_arrive);
        				pos_y=pos_y-deplacement;
        				stand=0;
405
					compteur+=100;
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
406
				}
Valentin MEUNIER's avatar
Valentin MEUNIER committed
407
			}
Valentin MEUNIER's avatar
Valentin MEUNIER committed
408
409
			if ((keystates[SDL_SCANCODE_DOWN]||keystates[SDL_SCANCODE_S])) 
			{	
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
410
				colli=collision_S(pos_x,pos_y,tab,taille_cell);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
411
412
413
				if(!colli)
				{
					if (right)
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
414
        					play_with_elve_S(texture_elve,texture,window,renderer,pos_x,pos_y,deplacement,zoom,tab,taille_cell,texture_fin,noeud_arrive);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
415
        				else
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
416
417
418
        					play_with_elve_S_l(texture_elve_reverse,texture,window,renderer,pos_x,pos_y,deplacement,zoom,tab,taille_cell,texture_fin,noeud_arrive);
        				pos_y=pos_y+deplacement;
        				stand=0;
419
					compteur+=100;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
420
        		}
Valentin MEUNIER's avatar
disj    
Valentin MEUNIER committed
421
			}
Valentin MEUNIER's avatar
Valentin MEUNIER committed
422
423
        	if ((keystates[SDL_SCANCODE_LEFT]||keystates[SDL_SCANCODE_A])) 
			{	
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
424
				colli=collision_O(pos_x,pos_y,tab,taille_cell);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
425
426
				if(!colli)
				{
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
427
					play_with_elve_O(texture_elve_reverse,texture,window,renderer,pos_x,pos_y,deplacement,zoom,tab,taille_cell,texture_fin,noeud_arrive);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
428
429
430
        			pos_x=pos_x-deplacement;
        			stand=0;
        			right=0;
431
					compteur+=100;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
432
        		}
Valentin MEUNIER's avatar
Valentin MEUNIER committed
433
			}
Valentin MEUNIER's avatar
Valentin MEUNIER committed
434
435
			if ((keystates[SDL_SCANCODE_RIGHT]||keystates[SDL_SCANCODE_D])) 
			{	
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
436
				colli=collision_E(pos_x,pos_y,tab,taille_cell);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
437
438
				if(!colli)
				{
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
439
					play_with_elve_E(texture_elve,texture,window,renderer,pos_x,pos_y,deplacement,zoom,tab,taille_cell,texture_fin,noeud_arrive);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
440
441
442
        			pos_x=pos_x+deplacement;
        			stand=0;
     				right=1;
443
					compteur+=100;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
444
     			}
445
			}
Valentin MEUNIER's avatar
Valentin MEUNIER committed
446
447
448
        	if (right)
			{
        		switch (stand){
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
        		        	case 0:
                				play_standstill_1(texture_elve,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
                				stand=(stand+1)%7;
                				break;
            				case 2:
                				play_standstill_2(texture_elve,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
                				stand=(stand+1)%7;
                				break;
            				case 4:
                				play_standstill_3(texture_elve,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
                				stand=(stand+1)%7;
                				break;
            				case 6:
                				play_standstill_4(texture_elve,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
                				stand=(stand+1)%7;
                				break;
            				default:
                				stand=(stand+1)%7;
						break;
        		    }
       			 }
        		else{
        			switch (stand){
        	    		case 0:
        	    		    play_standstill_1_l(texture_elve_reverse,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
                			stand=(stand+1)%7;
                			break;
            			case 2:
                			play_standstill_2_l(texture_elve_reverse,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
               	 			stand=(stand+1)%7;
                			break;
            			case 4:
                			play_standstill_3_l(texture_elve_reverse,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
                			stand=(stand+1)%7;
                			break;
            			case 6:
                			play_standstill_4_l(texture_elve_reverse,texture,window,renderer,pos_x,pos_y,zoom,tab,taille_cell,texture_fin,noeud_arrive);
                			stand=(stand+1)%7;
                			break;
            			default:
                			stand=(stand+1)%7;
                		break;
            			}
        		}
Valentin MEUNIER's avatar
Valentin MEUNIER committed
493
494
495
496
			}
			if (fin_mama)
			{
				affichage_txt(window,renderer);
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
497
				temps++;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
498
499
500
501
502
503
504
				if (temps>50)
					running=0;
        	}
			if (pause)
			{
				relancer=0;
				affiche_carte=0;
Valentin MEUNIER's avatar
Valentin MEUNIER committed
505
				affichage_txt_pause(window, renderer);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
506
			}
507
			if (perdu && !fin_mama)
508
			{
509
510
				Mix_HaltMusic();
				Mix_PlayMusic(music_vie,-1);
511
512
513
514
515
				affichage_txt_perdu(window,renderer);
				temps++;
				if (temps>50)
					running=0;
			}
Valentin MEUNIER's avatar
Valentin MEUNIER committed
516
517
        	SDL_Delay(30);
        	SDL_RenderPresent(renderer);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
518
	}
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
519
520
521
522
523

	SDL_DestroyTexture(texture_elve_reverse);
	SDL_DestroyTexture(texture_elve);
	SDL_DestroyTexture(texture);
	SDL_DestroyTexture(texture_fin);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
524
525
	SDL_DestroyTexture(texture_fin2);
	SDL_DestroyTexture(texture2);
526
527
528
	Mix_FreeMusic(music_mama);
	Mix_FreeMusic(music_vie);
	Mix_CloseAudio();
Valentin MEUNIER's avatar
Valentin MEUNIER committed
529
530
531
	free(minimap);	
	free(graph->liste);
	free(graph);
532
533
	if (dijkstra_ok)
		free(tab_parents);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
534
535
536
	for (int i=0; i<P; i++)
		free(tab[i]);
	free(tab);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
537
	end_sdl(1, "Normal ending", window, renderer);
Valentin MEUNIER's avatar
le    
Valentin MEUNIER committed
538
	end_sdl(1,"Normal ending",window2,renderer2);
Valentin MEUNIER's avatar
Valentin MEUNIER committed
539
	SDL_Quit();
Valentin MEUNIER's avatar
Valentin MEUNIER committed
540
541
	return 1;
}