Commit 763ecabf authored by Valentin MEUNIER's avatar Valentin MEUNIER
Browse files

Merge branch 'valentinSDL' into 'master'

ajout du brouillard et des musiques

See merge request !8
parents 7921572e a5a80993
File deleted
......@@ -178,26 +178,15 @@ void afficherImage(SDL_Renderer *renderer,SDL_Window *window,int **tab,int taill
}
}
void point_minimap(SDL_Renderer * renderer, int taille_cell, int pos_x, int pos_y)
{
SDL_Rect rectangle;
SDL_SetRenderDrawColor(renderer,255,0,0,255);
rectangle.x=pos_x;
rectangle.y=pos_y;
rectangle.h=rectangle.w=taille_cell/2;
SDL_RenderFillRect(renderer, &rectangle);
SDL_SetRenderDrawColor(renderer,0,0,0,255);
}
void afficherImageBrouillard(SDL_Renderer *renderer,SDL_Window *window,int **tab,int taille_cell,SDL_Texture* texture, int pos_x, int pos_y)
void afficherImageBrouillard2(SDL_Renderer *renderer,SDL_Window *window,int **tab,int taille_cell,SDL_Texture* texture, int pos_x, int pos_y)
{
int i1,j1,j;
int * voisin = malloc(9*sizeof(int));
int x=pos_x/taille_cell;
int y=pos_y/taille_cell;
for (j=0;j<9;j++)
voisin[j]=-1;
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
......@@ -218,7 +207,7 @@ void afficherImageBrouillard(SDL_Renderer *renderer,SDL_Window *window,int **tab
voisin[5]=x+P*y-P-1;
}
if (x<P-1){
if (((tab[x][y] & FLAG_N) && (tab[x][y-1] & FLAG_E )) || ((tab[x][y] & FLAG_E) && (tab[x+1][y] & FLAG_N)))
if (((tab[x][y] & FLAG_N) && (tab[x+1][y-1] & FLAG_E )) || ((tab[x][y] & FLAG_E) && (tab[x][y-1] & FLAG_N)))
voisin[6]=x+P*y-P+1;
}
}
......@@ -246,16 +235,54 @@ void afficherImageBrouillard(SDL_Renderer *renderer,SDL_Window *window,int **tab
affichage_texture(texture,window,renderer,x,i1,j1,taille_cell);
}
}
free(voisin);
SDL_Rect rectangle, window_dimensions={0};
SDL_SetRenderDrawBlendMode(renderer,SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer, 0,0,0,150);
SDL_GetWindowSize(window, &window_dimensions.w, &window_dimensions.h);
rectangle.x=0;
rectangle.y=0;
rectangle.w=window_dimensions.w;
rectangle.h=window_dimensions.h;
SDL_RenderFillRect(renderer,&rectangle);
free(voisin);
SDL_Texture *texture_brouillard = load_texture_from_image("fog.png",renderer);
if (texture_brouillard==NULL) exit(EXIT_FAILURE);
SDL_Rect source={0},window_dimensions = {0},destination = {0};
SDL_QueryTexture(texture_brouillard, NULL, NULL,&source.w, &source.h);
SDL_GetWindowSize(window,&window_dimensions.w,&window_dimensions.h);
destination.w = 101*taille_cell;
destination.h = 91*taille_cell;
destination.y = pos_y-45*taille_cell;
destination.x = pos_x-50*taille_cell;
SDL_RenderCopy(renderer,texture_brouillard,&source,&destination);
SDL_DestroyTexture(texture_brouillard);
}
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;
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
for (int i=0;i<N;i++){
for (int j=0;j<P;j++){
x=tab[j][i];
i1=(noeud%P); //coordonee colonne du noeud
j1=((int)noeud/P); // coordonee ligne du noeud
affichage_texture(texture,window,renderer,x,i1,j1,taille_cell);
noeud+=1;
}
}
SDL_Texture *texture_brouillard = load_texture_from_image("fog.png",renderer);
if (texture_brouillard==NULL) exit(EXIT_FAILURE);
SDL_Rect source={0},window_dimensions = {0},destination = {0};
SDL_QueryTexture(texture_brouillard, NULL, NULL,&source.w, &source.h);
SDL_GetWindowSize(window,&window_dimensions.w,&window_dimensions.h);
destination.w = 101*taille_cell;
destination.h = 91*taille_cell;
destination.y = pos_y-45*taille_cell;
destination.x = pos_x-50*taille_cell;
SDL_RenderCopy(renderer,texture_brouillard,&source,&destination);
SDL_DestroyTexture(texture_brouillard);
}
......@@ -265,4 +292,16 @@ void peindreMap(SDL_Texture * texture, SDL_Window* window ,SDL_Renderer *rendere
affichage_texture(texture,window, renderer, laby[noeuds%P][noeuds/P], noeuds%P, noeuds/P, taille_cell);
}
void point_minimap(SDL_Renderer * renderer, int taille_cell, int pos_x, int pos_y)
{
SDL_Rect rectangle;
SDL_SetRenderDrawColor(renderer,255,0,0,255);
rectangle.x=pos_x;
rectangle.y=pos_y;
rectangle.h=rectangle.w=taille_cell/2;
SDL_RenderFillRect(renderer, &rectangle);
SDL_SetRenderDrawColor(renderer,0,0,0,255);
}
......@@ -7,11 +7,10 @@
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 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 point_minimap(SDL_Renderer * renderer, int taille_cell, 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 peindreMap(SDL_Texture * texture, SDL_Window* window ,SDL_Renderer *renderer, int noeuds, int taille_cell, int ** laby);
void afficherImageBrouillard(SDL_Renderer *renderer,SDL_Window *window,int **tab,int taille_cell,SDL_Texture* texture,int pos_x,int pos_y);
void point_minimap(SDL_Renderer * renderer, int taille_cell, int pos_x, int pos_y);
#endif
......@@ -96,6 +96,35 @@ int main (int argc, char** argv)
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());
// 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;
}
int running=1;
srand(time(0));
int noeuds=N*P;
......@@ -115,7 +144,7 @@ int main (int argc, char** argv)
SDL_Texture * texture,*texture_fin,* texture_elve,* texture_elve_reverse;
texture_elve = load_texture_from_image("Elve_lign.png",renderer);
if (texture_elve == NULL) end_sdl(0, "Echec du chargement de l'image dans la texture", window, renderer);
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);
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);
......@@ -177,6 +206,7 @@ int main (int argc, char** argv)
minimap[iter]=0;
int taille_cell2=min((screen.w/3)/(P+2),(screen.h/3)/(N+2));
Mix_PlayMusic(music_mama,-1);
printf("l : relancer \np,SPACE : pause \ncroix : quitter \nm : afficher la carte complète du labyrinthe pendant 2 secondes\n");
while (running)
......@@ -474,8 +504,10 @@ int main (int argc, char** argv)
affiche_carte=0;
affichage_txt_pause(window, renderer);
}
if (perdu)
if (perdu && !fin_mama)
{
Mix_HaltMusic();
Mix_PlayMusic(music_vie,-1);
affichage_txt_perdu(window,renderer);
temps++;
if (temps>50)
......@@ -491,6 +523,9 @@ int main (int argc, char** argv)
SDL_DestroyTexture(texture_fin);
SDL_DestroyTexture(texture_fin2);
SDL_DestroyTexture(texture2);
Mix_FreeMusic(music_mama);
Mix_FreeMusic(music_vie);
Mix_CloseAudio();
free(minimap);
free(graph->liste);
free(graph);
......
/*main.h*/
/*15 juin 2021*/
#ifndef main_gard
#define main_gard
#include <SDL2/SDL.h>
#include<SDL2/SDL.h>
#include "kruskal.h"
#include <math.h>
#include "affichage_image.h"
......@@ -12,10 +11,9 @@
#include "texture_perso.h"
#include "colision.h"
#include "DFS.h"
#include <SDL2/SDL_ttf.h>
#include<SDL2/SDL_ttf.h>
#include<SDL2/SDL_mixer.h>
#include "affichage_txt.h"
#include "main.h"
void end_sdl(char ok,char const* msg,SDL_Window* window, SDL_Renderer* renderer);
void afficheEcranIntelligement(SDL_Renderer*,int**,int);
......
File deleted
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