Commit df12b202 authored by Valentin MEUNIER's avatar Valentin MEUNIER
Browse files

la minimap

parent 79f188c2
......@@ -160,31 +160,37 @@ void affichage_fin(SDL_Texture *my_texture,SDL_Window *window,SDL_Renderer *rend
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));
int i1,j1,val=0;
int * voisin = malloc(5*sizeof(int));
for (int i=0; i<5; i++)
voisin[i]=-1;
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
int x=pos_x/taille_cell;
int y=pos_y/taille_cell;
voisin[4]=x+P*y;
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 (tab[x][y] & FLAG_N)
voisin[0]=x+P*y -P;
if (tab[x][y] & FLAG_S)
voisin[1]=x+P*y+P ;
if (tab[x][y] & FLAG_O)
voisin[2]=x+P*y -1;
if (tab[x][y] & FLAG_E)
voisin[3]=x+P*y+1;
for (int j=0; j<5; 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
val=tab[voisin[j]%P][voisin[j]/P];
i1=(voisin[j]%P); //coordonee colonne du noeud
j1=(voisin[j]/P); // coordonee ligne du noeud
affichage_texture(texture,window,renderer,val,i1,j1,taille_cell);
}
}
affichage_texture(texture,window,renderer,x,i1,j1,taille_cell);
free(voisin);
}
......
......@@ -130,183 +130,7 @@ int main (int argc, char** argv)
//tab_parents=dijkstra(tab,graph->noeuds,ND_ARRIVEE);
SDL_Event event;
/*while (running)
{
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
running = 0;
break;
case SDL_WINDOWEVENT:
switch (event.window.event)
{
case SDL_WINDOWEVENT_CLOSE:
running = 0;
break;
default:
break;
}
break;
break;
}
//afficherEcranIntelligemment(renderer,tab,taille_cell);
//SDL_RenderPresent(renderer);
//SDL_Delay(5000);
//SDL_RenderClear(renderer);
afficherImage(renderer,window,tab,taille_cell,texture);
affichage_fin(texture_fin,window,renderer,ND_ARRIVEE/P,ND_ARRIVEE%P,taille_cell);
SDL_RenderPresent(renderer);
SDL_Delay(10);
SDL_RenderClear(renderer);
}
}*/
/*
*application du plus court chemin calculé par dijkstra
int pause=1;
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_actuel=noeud_dep;
int noeud_arrive=rand()%TAILLE;
tab_parents=dijkstra(tab,graph->noeuds,noeud_arrive);
while ((running)||(temps<10))
{
if (noeud_actuel==noeud_arrive)
running=0;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
running = 0;
break;
case SDL_WINDOWEVENT:
switch (event.window.event)
{
case SDL_WINDOWEVENT_CLOSE:
running = 0;
temps=10;
break;
case SDL_WINDOWEVENT_SIZE_CHANGED:
screen.w = event.window.data1;
screen.h = event.window.data2;
break;
case SDL_WINDOWEVENT_EXPOSED:
break;
}
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_SPACE:
case SDLK_p:
pause=1-pause;
break;
default:
break;
}
break;
default:
break;
}
}
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;
}
}
SDL_Delay(30);
SDL_RenderPresent(renderer);
if (running==0){
temps++;
}
else
noeud_actuel=tab_parents[noeud_actuel];
}*/
//on initialise une fenêtre 2 pour une mini-map
//on initialise une fenêtre 2 pour une mini-map
SDL_Window *window2;
window2 = SDL_CreateWindow("SDL2 Programme 0.1", screen.w-screen.w/3, 0,screen.w/3,screen.h/4, SDL_WINDOW_RESIZABLE);
......@@ -342,6 +166,9 @@ int main (int argc, char** argv)
int colli;
int noeud_actuel;
int taille_cell2=min((screen.w/3)/(P+2),(screen.h/3)/(N+2));
int * minimap=malloc((TAILLE+1)*sizeof(int));
for (int i=0; i<(TAILLE +1); i++)
minimap[i]=0;
affichage_fin(texture_fin2,window2,renderer2,noeud_arrive/P,noeud_arrive%P,taille_cell2);
printf("l : relancer \np,SPACE : pause \ncroix : quitter\n");
......@@ -349,6 +176,8 @@ int main (int argc, char** argv)
while ((running)||(temps<50))
{
noeud_actuel=pos_y*P/taille_cell+pos_x/taille_cell;
minimap[0]++;
minimap[minimap[0]]=noeud_actuel;
if (noeud_actuel==noeud_arrive)
running=0;
while (SDL_PollEvent(&event))
......@@ -406,8 +235,11 @@ int main (int argc, char** argv)
}
const Uint8 *keystates = SDL_GetKeyboardState(NULL);
if (pause){
peindreMap(texture2,window2,renderer2,noeud_actuel,taille_cell2,tab);
SDL_RenderClear(renderer2);
for (int i=1; i<=minimap[0]; i++)
peindreMap(texture2,window2,renderer2,minimap[i],taille_cell2,tab);
SDL_RenderPresent(renderer2);
if ((keystates[SDL_SCANCODE_UP]||keystates[SDL_SCANCODE_W])) {
colli=collision_N(pos_x,pos_y,tab,taille_cell);
if(!colli){
......@@ -512,5 +344,6 @@ int main (int argc, char** argv)
SDL_DestroyTexture(texture_fin);
end_sdl(1, "Normal ending", window, renderer);
end_sdl(1,"Normal ending",window2,renderer2);
free(minimap);
return 1;
}
No preview for this file type
Markdown is supported
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