fix emplacement de function

This commit is contained in:
2025-01-08 13:33:42 +01:00
parent 2d6a251f3c
commit 488f9a5fb0
6 changed files with 82 additions and 77 deletions

View File

@@ -16,5 +16,6 @@ void initSDL (dis *display_user);
void displayTextSDL(dis *display_user,char *text, vect coor, vect size, int font_size);
void screenDisplayGameSDL (char **tab,vect dim_tab, dis *display_user, vect *player_pos, int fov, vect direction);
void backgroundDisplay(dis *display_user,int bg);
void playAudio(int sfx);
#endif // !DISPLAY_H

View File

@@ -5,4 +5,5 @@ vect *fileToTab2D (const char *name_file, char **tab,
const unsigned N, vect *player, int *nbr_targets);
int countCustomMaps(char *name_directory);
char ** generatorMenu(char *name_directory, vect *size, vect *pos_player);
void save_grid_to_file(int filename, char **tab2D);
#endif // !READ_H

View File

@@ -7,6 +7,7 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mutex.h>
#include <SDL2/SDL_mixer.h>
#include <SDL2/SDL_rect.h>
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_surface.h>
@@ -311,3 +312,50 @@ void backgroundDisplay(dis *display_user,int bg)
SDL_DestroyTexture (texture);
return;
}
/**
* \brief Cette fonction permet de joueur des effet sonor.
* \param sfx un int designant le numero du son a jouer.
* du joueur.
* \return Void
*
*/
void playAudio(int sfx)
{
// Charger un fichier son
Mix_Chunk* sfx_win = Mix_LoadWAV("sfx/win.wav");
Mix_Chunk* sfx_lose = Mix_LoadWAV("sfx/lose.wav");
Mix_Chunk* sfx_cant_move = Mix_LoadWAV("sfx/cantmove.wav");
Mix_Chunk* sfx_block_on_target = Mix_LoadWAV("sfx/blockontarget.wav");
Mix_Chunk* sfx_move = Mix_LoadWAV("sfx/move.mp3");
Mix_Chunk* sfx_move_block = Mix_LoadWAV("sfx/moveblock.wav");
switch (sfx)
{
case 0:
Mix_PlayChannel(-1, sfx_win, 0);
return;
case 1:
Mix_PlayChannel(-1, sfx_lose, 0);
return;
case 2:
Mix_PlayChannel(-1, sfx_cant_move, 0);
return;
case 3:
Mix_PlayChannel(-1, sfx_block_on_target, 0);
return;
case 4:
Mix_PlayChannel(-1, sfx_move, 0);
return;
case 5:
Mix_PlayChannel(-1, sfx_move_block, 0);
return;
}
Mix_FreeChunk(sfx_win);
Mix_FreeChunk(sfx_lose);
Mix_FreeChunk(sfx_cant_move);
Mix_FreeChunk(sfx_block_on_target);
Mix_FreeChunk(sfx_move);
Mix_FreeChunk(sfx_move_block);
}

View File

@@ -7,6 +7,7 @@
#include "../include/function.h"
#include "../include/display.h"
#include "../include/read.h"
#include <SDL2/SDL_events.h>
#include <SDL2/SDL_image.h>
@@ -435,38 +436,6 @@ int inGameLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
return -1;
}
/**
*
* \brief La fonction permet de retranscrire un niveau creer du tableau vers le fichier.txt
* \param filename Le nom du fichier a remplir.
* \param tab2d Le tableau 2d carre.
*/
void save_grid_to_file(int filename, char **tab2D) {
char path[250];
snprintf(path, sizeof(path), "maps/custom_%d.txt", filename);
FILE *file = fopen(path, "w");
// Parcours et sauvegarde du tableau 2D dans le fichier
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
switch (tab2D[i][j]) {
case EMPTY: fputc(' ',file);break;
case WALL: fputc('#',file); break;
case BOX: fputc('C',file);break;
case TARGET: fputc('I',file); break;
case BOX_ON_TARGET: fputc(' ',file); break;
case PLAYER: fputc('P',file); break;
case PLAYER_ON_TARGET: fputc('P',file); break;
default: return;
}
}
fputc('\n',file); // Nouvelle ligne pour chaque ligne du tableau
}
fclose(file);
}
/**
*

View File

@@ -22,51 +22,6 @@
unsigned int seed;
/**
* \brief Cette fonction permet de joueur des effet sonor.
* \param sfx un int designant le numero du son a jouer.
* du joueur.
* \return Void
*
*/
void playAudio(int sfx)
{
// Charger un fichier son
Mix_Chunk* sfx_win = Mix_LoadWAV("sfx/win.wav");
Mix_Chunk* sfx_lose = Mix_LoadWAV("sfx/lose.wav");
Mix_Chunk* sfx_cant_move = Mix_LoadWAV("sfx/cantmove.wav");
Mix_Chunk* sfx_block_on_target = Mix_LoadWAV("sfx/blockontarget.wav");
Mix_Chunk* sfx_move = Mix_LoadWAV("sfx/move.mp3");
Mix_Chunk* sfx_move_block = Mix_LoadWAV("sfx/moveblock.wav");
switch (sfx)
{
case 0:
Mix_PlayChannel(-1, sfx_win, 0);
return;
case 1:
Mix_PlayChannel(-1, sfx_lose, 0);
return;
case 2:
Mix_PlayChannel(-1, sfx_cant_move, 0);
return;
case 3:
Mix_PlayChannel(-1, sfx_block_on_target, 0);
return;
case 4:
Mix_PlayChannel(-1, sfx_move, 0);
return;
case 5:
Mix_PlayChannel(-1, sfx_move_block, 0);
return;
}
Mix_FreeChunk(sfx_win);
Mix_FreeChunk(sfx_lose);
Mix_FreeChunk(sfx_cant_move);
Mix_FreeChunk(sfx_block_on_target);
Mix_FreeChunk(sfx_move);
Mix_FreeChunk(sfx_move_block);
}
int main ()
{

View File

@@ -145,3 +145,34 @@ char ** generatorMenu(char *name_directory, vect *size, vect *pos_player)
}
/**
*
* \brief La fonction permet de retranscrire un niveau creer du tableau vers le fichier.txt
* \param filename Le nom du fichier a remplir.
* \param tab2d Le tableau 2d carre.
*/
void save_grid_to_file(int filename, char **tab2D) {
char path[250];
snprintf(path, sizeof(path), "maps/custom_%d.txt", filename);
FILE *file = fopen(path, "w");
// Parcours et sauvegarde du tableau 2D dans le fichier
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
switch (tab2D[i][j]) {
case EMPTY: fputc(' ',file);break;
case WALL: fputc('#',file); break;
case BOX: fputc('C',file);break;
case TARGET: fputc('I',file); break;
case BOX_ON_TARGET: fputc(' ',file); break;
case PLAYER: fputc('P',file); break;
case PLAYER_ON_TARGET: fputc('P',file); break;
default: return;
}
}
fputc('\n',file); // Nouvelle ligne pour chaque ligne du tableau
}
fclose(file);
}