Commit 79f188c2 authored by Valentin MEUNIER's avatar Valentin MEUNIER
Browse files

brouilllard v1 (ore dumped))

parent 7ce406dc
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <SDL2/SDL_image.h> #include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h> #include <SDL2/SDL_ttf.h>
#include "kruskal.h" #include "affichage_image.h"
/* /*
*chargement des textures *chargement des textures
...@@ -158,21 +158,52 @@ void affichage_fin(SDL_Texture *my_texture,SDL_Window *window,SDL_Renderer *rend ...@@ -158,21 +158,52 @@ void affichage_fin(SDL_Texture *my_texture,SDL_Window *window,SDL_Renderer *rend
SDL_RenderCopy(renderer,my_texture,&state, &destination); // Préparation de l'affichage SDL_RenderCopy(renderer,my_texture,&state, &destination); // Préparation de l'affichage
} }
void afficherImageBrouillard(SDL_Renderer *renderer,SDL_Window *window,int **tab,int taille_cell,SDL_Texture* texture, int pos_x, int pos_y)
{
int i1,j1,x,noeud=0;
int * voisin = malloc(4*sizeof(int));
void afficherImage(SDL_Renderer *renderer,SDL_Window *window,int **tab,int taille_cell,SDL_Texture* texture){ SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
SDL_RenderClear(renderer);
if (tab[pos_y][pos_x] & FLAG_N)
voisin[0]=pos_x+P*pos_y -P;
if (tab[pos_y][pos_x] & FLAG_S)
voisin[1]=pos_x+P*pos_y+P ;
if (tab[pos_y][pos_x] & FLAG_O)
voisin[2]=pos_x+P*pos_y -1;
if (tab[pos_y][pos_x] & FLAG_E)
voisin[3]=pos_x+P*pos_y+1;
for (int j=0; j<4; j++)
{
if (voisin[j]!=-1)
{
x=tab[voisin[j]%P][voisin[j]/P];
i1=(noeud%P); //coordonee colonne du noeud
j1=(noeud/P); // coordonee ligne du noeud
}
}
affichage_texture(texture,window,renderer,x,i1,j1,taille_cell);
free(voisin);
}
void afficherImage(SDL_Renderer *renderer,SDL_Window *window,int **tab,int taille_cell,SDL_Texture* texture)
{
int i1,j1,x,noeud=0; int i1,j1,x,noeud=0;
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
for (int i=0;i<N;i++){ for (int i=0;i<N;i++)
for (int j=0;j<P;j++){ {
for (int j=0;j<P;j++)
{
x=tab[j][i]; x=tab[j][i];
i1=(noeud%P); //coordonee colonne du noeud i1=(noeud%P); //coordonee colonne du noeud
j1=((int)noeud/P); // coordonee ligne du noeud j1=((int)noeud/P); // coordonee ligne du noeud
affichage_texture(texture,window,renderer,x,i1,j1,taille_cell); affichage_texture(texture,window,renderer,x,i1,j1,taille_cell);
noeud+=1; noeud+=1;
} }
} }
......
#ifndef _gard_affichage_image #ifndef _gard_affichage_image
#define _gard_affichage_image #define _gard_affichage_image
#include "main.h"
#include "kruskal.h"
SDL_Texture* load_texture_from_image(char * file_image_name, SDL_Renderer *renderer); SDL_Texture* load_texture_from_image(char * file_image_name, SDL_Renderer *renderer);
void affichage_texture(SDL_Texture *my_texture,SDL_Window *window,SDL_Renderer *renderer,int x,int coord_colonne,int coord_ligne,int taille_cell); void affichage_texture(SDL_Texture *my_texture,SDL_Window *window,SDL_Renderer *renderer,int x,int coord_colonne,int coord_ligne,int taille_cell);
void afficherImage(SDL_Renderer *renderer,SDL_Window *window,int **tab,int taille_cell,SDL_Texture* texture); void afficherImage(SDL_Renderer *renderer,SDL_Window *window,int **tab,int taille_cell,SDL_Texture* texture);
void afficherImageBrouillard(SDL_Renderer *renderer,SDL_Window *window,int **tab,int taille_cell,SDL_Texture* texture, int pos_x, int pos_y);
void affichage_fin(SDL_Texture *my_texture,SDL_Window *window,SDL_Renderer *renderer,int coord_colonne,int coord_ligne,int taille_cell); void affichage_fin(SDL_Texture *my_texture,SDL_Window *window,SDL_Renderer *renderer,int coord_colonne,int coord_ligne,int taille_cell);
void peindreMap(SDL_Texture * texture, SDL_Window* window ,SDL_Renderer *renderer, int noeuds, int taille_cell, int ** laby); void peindreMap(SDL_Texture * texture, SDL_Window* window ,SDL_Renderer *renderer, int noeuds, int taille_cell, int ** laby);
......
#include "dijkstra.h"
int * dijkstra(int ** laby, int noeuds, int depart)
{
int * parent = malloc(noeuds*sizeof(int));
parent[depart]=depart;
poids_t * distance = malloc(noeuds*sizeof(poids_t));
for (int i=0; i<noeuds; i++)
{
distance[i].poids=noeuds;
distance[i].val=i;
}
distance[depart].poids=0;
int* indice_valeur = malloc(noeuds*sizeof(int));
for (int i=0; i<noeuds; i++)
indice_valeur[i]=-1;
tas_t * tas=init_tas(noeuds+1);
for (int i=0; i<noeuds; i++)
tas->tab[i]=distance[i];
int * voisin=malloc(4*sizeof(int));
for (int i=0; i<4; i++)
voisin[i]=-1;
int sommet= depart;
ajouter_tas_min(tas,distance[depart],indice_valeur);
while (tas->taille>-1)
{
if (laby[sommet%P][sommet/P] & FLAG_N)
voisin[0]=sommet-P;
if (laby[sommet%P][sommet/P] & FLAG_S)
voisin[1]=sommet+P;
if (laby[sommet%P][sommet/P] & FLAG_O)
voisin[2]=sommet-1;
if (laby[sommet%P][sommet/P] & FLAG_E)
voisin[3]=sommet+1;
for (int j=0; j<4; j++)
{
if (voisin[j]!=-1)
{
if (indice_valeur[voisin[j]]!=-2)
{
if (indice_valeur[voisin[j]]==-1)
{
distance[voisin[j]].poids=1 + distance[sommet].poids;
ajouter_tas_min(tas,distance[voisin[j]],indice_valeur);
parent[voisin[j]]=sommet;
}
else
{
if (distance[voisin[j]].poids>1+distance[sommet].poids)
{
distance[voisin[j]].poids=1 + distance[sommet].poids;
percolation_bas_tas_min(tas,indice_valeur[voisin[j]],indice_valeur);
parent[voisin[j]]=sommet;
}
}
}
}
voisin[j]=-1;
}
indice_valeur[tas->tab[0].val]=-2;
indice_valeur[tas->tab[tas->taille].val]=0;
typetas aux=tas->tab[0];
tas->tab[0]=tas->tab[tas->taille];
tas->tab[tas->taille]=aux;
tas->taille+=-1;
percolation_bas_tas_min(tas,0,indice_valeur);
sommet=tas->tab[0].val;
}
free(distance);
free(indice_valeur);
liberer(tas);
return parent;
}
#ifndef _gard_dijsktra_
#define _gard_dijsktra_
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include <time.h>
#include "graph_aretes_tab.h"
#include "tas.h"
#include "kruskal.h"
#include "main.h"
int * dijkstra(int **, int, int);
#endif
...@@ -74,7 +74,8 @@ void play_with_elve_N(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Wind ...@@ -74,7 +74,8 @@ void play_with_elve_N(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Wind
state[9].h = offset_y; state[9].h = offset_y;
for(i=0;i<nb_images_animation;++i){ for(i=0;i<nb_images_animation;++i){
afficherImage(renderer,window,tab,taille_cell,background); afficherImageBrouillard(renderer,window,tab,taille_cell,background,pos_x,pos_y);
// afficherImage(renderer,window,tab,taille_cell,background);
affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell); affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
destination.y=destination.y-(deplacement/nb_images_animation); //déplacement du personnage ici de wind dim.h /32 en tout (diviser par nb animation pour chaque anim) destination.y=destination.y-(deplacement/nb_images_animation); //déplacement du personnage ici de wind dim.h /32 en tout (diviser par nb animation pour chaque anim)
SDL_RenderCopy(renderer,texture_elve, &state[i], &destination); SDL_RenderCopy(renderer,texture_elve, &state[i], &destination);
...@@ -156,7 +157,8 @@ void play_with_elve_N_l(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Wi ...@@ -156,7 +157,8 @@ void play_with_elve_N_l(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Wi
state[9].h = offset_y; state[9].h = offset_y;
for(i=0;i<nb_images_animation;++i){ for(i=0;i<nb_images_animation;++i){
afficherImage(renderer,window,tab,taille_cell,background); // afficherImage(renderer,window,tab,taille_cell,background);
afficherImageBrouillard(renderer,window,tab,taille_cell,background,pos_x,pos_y);
affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell); affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
destination.y=destination.y-(deplacement/nb_images_animation); destination.y=destination.y-(deplacement/nb_images_animation);
SDL_RenderCopy(renderer,texture_elve, &state[i], &destination); SDL_RenderCopy(renderer,texture_elve, &state[i], &destination);
...@@ -240,7 +242,8 @@ void play_with_elve_S(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Wind ...@@ -240,7 +242,8 @@ void play_with_elve_S(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Wind
state[9].h = offset_y; state[9].h = offset_y;
for(i=0;i<nb_images_animation;++i){ for(i=0;i<nb_images_animation;++i){
afficherImage(renderer,window,tab,taille_cell,background); // afficherImage(renderer,window,tab,taille_cell,background);
afficherImageBrouillard(renderer,window,tab,taille_cell,background,pos_x,pos_y);
affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell); affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
destination.y=destination.y+(deplacement/nb_images_animation); destination.y=destination.y+(deplacement/nb_images_animation);
SDL_RenderCopy(renderer,texture_elve, &state[i], &destination); SDL_RenderCopy(renderer,texture_elve, &state[i], &destination);
...@@ -325,7 +328,8 @@ void play_with_elve_S_l(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Wi ...@@ -325,7 +328,8 @@ void play_with_elve_S_l(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Wi
state[9].h = offset_y; state[9].h = offset_y;
for(i=0;i<nb_images_animation;++i){ for(i=0;i<nb_images_animation;++i){
afficherImage(renderer,window,tab,taille_cell,background); //afficherImage(renderer,window,tab,taille_cell,background);
afficherImageBrouillard(renderer,window,tab,taille_cell,background,pos_x,pos_y);
affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell); affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
destination.y=destination.y+(deplacement/nb_images_animation); destination.y=destination.y+(deplacement/nb_images_animation);
SDL_RenderCopy(renderer,texture_elve, &state[i], &destination); SDL_RenderCopy(renderer,texture_elve, &state[i], &destination);
...@@ -411,7 +415,8 @@ void play_with_elve_O(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Wind ...@@ -411,7 +415,8 @@ void play_with_elve_O(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Wind
state[9].h = offset_y; state[9].h = offset_y;
for(i=0;i<nb_images_animation;++i){ for(i=0;i<nb_images_animation;++i){
afficherImage(renderer,window,tab,taille_cell,background); // afficherImage(renderer,window,tab,taille_cell,background);
afficherImageBrouillard(renderer,window,tab,taille_cell,background,pos_x,pos_y);
affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell); affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
destination.x=destination.x-(deplacement/nb_images_animation); destination.x=destination.x-(deplacement/nb_images_animation);
SDL_RenderCopy(renderer,texture_elve, &state[i], &destination); SDL_RenderCopy(renderer,texture_elve, &state[i], &destination);
...@@ -495,7 +500,8 @@ void play_with_elve_E(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Wind ...@@ -495,7 +500,8 @@ void play_with_elve_E(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Wind
state[9].h = offset_y; state[9].h = offset_y;
for(i=0;i<nb_images_animation;++i){ for(i=0;i<nb_images_animation;++i){
afficherImage(renderer,window,tab,taille_cell,background); //afficherImage(renderer,window,tab,taille_cell,background);
afficherImageBrouillard(renderer,window,tab,taille_cell,background,pos_x,pos_y);
affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell); affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
destination.x=destination.x+(deplacement/nb_images_animation); destination.x=destination.x+(deplacement/nb_images_animation);
SDL_RenderCopy(renderer,texture_elve, &state[i], &destination); SDL_RenderCopy(renderer,texture_elve, &state[i], &destination);
...@@ -526,7 +532,8 @@ void play_standstill_1(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Win ...@@ -526,7 +532,8 @@ void play_standstill_1(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Win
state[0].y=0; state[0].y=0;
state[0].w=offset_x; state[0].w=offset_x;
state[0].h = offset_y; state[0].h = offset_y;
afficherImage(renderer,window,tab,taille_cell,background); // afficherImage(renderer,window,tab,taille_cell,background);
afficherImageBrouillard(renderer,window,tab,taille_cell,background,pos_x,pos_y);
affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell); affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
SDL_RenderCopy(renderer,texture_elve, &state[i], &destination); SDL_RenderCopy(renderer,texture_elve, &state[i], &destination);
} }
...@@ -553,7 +560,8 @@ void play_standstill_1_l(SDL_Texture* texture_elve,SDL_Texture* background,SDL_W ...@@ -553,7 +560,8 @@ void play_standstill_1_l(SDL_Texture* texture_elve,SDL_Texture* background,SDL_W
state[0].y=0; state[0].y=0;
state[0].w=offset_x; state[0].w=offset_x;
state[0].h = offset_y; state[0].h = offset_y;
afficherImage(renderer,window,tab,taille_cell,background); //afficherImage(renderer,window,tab,taille_cell,background);
afficherImageBrouillard(renderer,window,tab,taille_cell,background,pos_x,pos_y);
affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell); affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
SDL_RenderCopy(renderer,texture_elve, &state[i], &destination); SDL_RenderCopy(renderer,texture_elve, &state[i], &destination);
} }
...@@ -580,7 +588,8 @@ void play_standstill_2(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Win ...@@ -580,7 +588,8 @@ void play_standstill_2(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Win
state[0].y=0; state[0].y=0;
state[0].w=offset_x; state[0].w=offset_x;
state[0].h = offset_y; state[0].h = offset_y;
afficherImage(renderer,window,tab,taille_cell,background); // afficherImage(renderer,window,tab,taille_cell,background);
afficherImageBrouillard(renderer,window,tab,taille_cell,background,pos_x,pos_y);
affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell); affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
SDL_RenderCopy(renderer,texture_elve, &state[i], &destination); SDL_RenderCopy(renderer,texture_elve, &state[i], &destination);
} }
...@@ -607,7 +616,8 @@ void play_standstill_2_l(SDL_Texture* texture_elve,SDL_Texture* background,SDL_W ...@@ -607,7 +616,8 @@ void play_standstill_2_l(SDL_Texture* texture_elve,SDL_Texture* background,SDL_W
state[0].y=0; state[0].y=0;
state[0].w=offset_x; state[0].w=offset_x;
state[0].h = offset_y; state[0].h = offset_y;
afficherImage(renderer,window,tab,taille_cell,background); // afficherImage(renderer,window,tab,taille_cell,background);
afficherImageBrouillard(renderer,window,tab,taille_cell,background,pos_x,pos_y);
affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell); affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
SDL_RenderCopy(renderer,texture_elve, &state[i], &destination); SDL_RenderCopy(renderer,texture_elve, &state[i], &destination);
} }
...@@ -634,7 +644,8 @@ void play_standstill_3(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Win ...@@ -634,7 +644,8 @@ void play_standstill_3(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Win
state[0].y=0; state[0].y=0;
state[0].w=offset_x; state[0].w=offset_x;
state[0].h = offset_y; state[0].h = offset_y;
afficherImage(renderer,window,tab,taille_cell,background); // afficherImage(renderer,window,tab,taille_cell,background);
afficherImageBrouillard(renderer,window,tab,taille_cell,background,pos_x,pos_y);
affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell); affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
SDL_RenderCopy(renderer,texture_elve, &state[i], &destination); SDL_RenderCopy(renderer,texture_elve, &state[i], &destination);
} }
...@@ -661,7 +672,8 @@ void play_standstill_3_l(SDL_Texture* texture_elve,SDL_Texture* background,SDL_W ...@@ -661,7 +672,8 @@ void play_standstill_3_l(SDL_Texture* texture_elve,SDL_Texture* background,SDL_W
state[0].y=0; state[0].y=0;
state[0].w=offset_x; state[0].w=offset_x;
state[0].h = offset_y; state[0].h = offset_y;
afficherImage(renderer,window,tab,taille_cell,background); // afficherImage(renderer,window,tab,taille_cell,background);
afficherImageBrouillard(renderer,window,tab,taille_cell,background,pos_x,pos_y);
affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell); affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
SDL_RenderCopy(renderer,texture_elve, &state[i], &destination); SDL_RenderCopy(renderer,texture_elve, &state[i], &destination);
} }
...@@ -688,7 +700,8 @@ void play_standstill_4(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Win ...@@ -688,7 +700,8 @@ void play_standstill_4(SDL_Texture* texture_elve,SDL_Texture* background,SDL_Win
state[0].y=0; state[0].y=0;
state[0].w=offset_x; state[0].w=offset_x;
state[0].h = offset_y; state[0].h = offset_y;
afficherImage(renderer,window,tab,taille_cell,background); // afficherImage(renderer,window,tab,taille_cell,background);
afficherImageBrouillard(renderer,window,tab,taille_cell,background,pos_x,pos_y);
affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell); affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
SDL_RenderCopy(renderer,texture_elve, &state[i], &destination); SDL_RenderCopy(renderer,texture_elve, &state[i], &destination);
} }
...@@ -715,7 +728,8 @@ void play_standstill_4_l(SDL_Texture* texture_elve,SDL_Texture* background,SDL_W ...@@ -715,7 +728,8 @@ void play_standstill_4_l(SDL_Texture* texture_elve,SDL_Texture* background,SDL_W
state[0].y=0; state[0].y=0;
state[0].w=offset_x; state[0].w=offset_x;
state[0].h = offset_y; state[0].h = offset_y;
afficherImage(renderer,window,tab,taille_cell,background); // afficherImage(renderer,window,tab,taille_cell,background);
afficherImageBrouillard(renderer,window,tab,taille_cell,background,pos_x,pos_y);
affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell); affichage_fin(texture_fin,window,renderer,noeud_arrive/P,noeud_arrive%P,taille_cell);
SDL_RenderCopy(renderer,texture_elve, &state[i], &destination); SDL_RenderCopy(renderer,texture_elve, &state[i], &destination);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment