This commit is contained in:
cyjullien1
2025-01-07 18:30:38 +01:00
parent 40c0ede871
commit 2c39110885
5 changed files with 110 additions and 46 deletions

View File

@@ -17,6 +17,50 @@
#define SIZE_PLAY 20
#define SIZE_MENU 200
/**
* \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);
}
int main ()
{
dis display_user;
@@ -50,52 +94,28 @@ int main ()
//mixeur audio
// Initialisation de SDL_mixer
if (Mix_Init(MIX_INIT_MP3) == 0) {
printf("Erreur Mix_Init : %s\n", Mix_GetError());
SDL_Quit();
return -1;
}
Mix_Init(MIX_INIT_MP3);
// Ouverture du mixeur audio
if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) < 0) {
printf("Erreur Mix_OpenAudio : %s\n", Mix_GetError());
Mix_Quit();
SDL_Quit();
return -1;
}
// Charger un fichier son
Mix_Chunk* son = Mix_LoadWAV("sfx/win.mp3");
if (!son) {
printf("Erreur Mix_LoadWAV : %s\n", Mix_GetError());
Mix_CloseAudio();
Mix_Quit();
SDL_Quit();
return -1;
}
Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096);
// Charger une musique
Mix_Music* musique = Mix_LoadMUS("musique.mp3");
if (!musique) {
printf("Erreur Mix_LoadMUS : %s\n", Mix_GetError());
Mix_FreeChunk(son);
Mix_CloseAudio();
Mix_Quit();
SDL_Quit();
return -1;
}
Mix_Music* music_menu = Mix_LoadMUS("sfx/musicMenu.mp3");
Mix_Music* music_game = Mix_LoadMUS("sfx/levelPlay.mp3");
Mix_Music* music_editor = Mix_LoadMUS("sfx/editor.mp3");
// Jouer le son une seule fois
Mix_PlayChannel(-1, son, 0);
Mix_Volume(-1,MIX_MAX_VOLUME); // Définit le volume maximal pour tous les canaux
Mix_VolumeMusic(MIX_MAX_VOLUME / 2);
// Loop pour le jeu entier menu et les jeux.
while(output != 0)
{
SDL_RenderClear(display_user.renderer);
if(output == -1)
{
Mix_PlayMusic(music_menu, -1);
backgroundDisplay(&display_user,0);
menu = generatorMenu("maps", &dim_menu, &pos);
pos.x = 4; pos.y = 1;
@@ -104,11 +124,13 @@ int main ()
}
else if(output == -2)
{
Mix_PlayMusic(music_editor, -1);
backgroundDisplay(&display_user,2);
output = inEditorLoop(tab2d, &dim, playerPos, targets, nbr_targets, &display_user,&score_user ,num_fichier);
}
else
{
Mix_PlayMusic(music_game, -1);
backgroundDisplay(&display_user,1);
score_user.before = time(NULL);
char txt[30] = "";
@@ -166,7 +188,7 @@ int main ()
if (tab2d != NULL)free2D (tab2d, SIZE_PLAY);
if (playerPos != NULL)free (playerPos);
if (targets != NULL)free (targets);
Mix_FreeChunk(son);
Mix_CloseAudio();
SDL_Quit ();