ajout de la librairie sdl mixer plus changement dans le makefile

This commit is contained in:
cyjullien1
2025-01-07 17:38:30 +01:00
parent e9b91e0e81
commit 40c0ede871
11 changed files with 71 additions and 1 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
CC = gcc CC = gcc
CFLAGS = -Wall -Wextra CFLAGS = -Wall -Wextra
LIBFLAGS = $(shell pkg-config --cflags --libs sdl2 SDL2_image SDL2_ttf) LIBFLAGS = $(shell pkg-config --cflags --libs sdl2 SDL2_image SDL2_ttf SDL2_mixer)
TARGET = sokoban TARGET = sokoban
SRCDIR = script SRCDIR = script
OBJDIR = obj OBJDIR = obj
+43
View File
@@ -9,6 +9,7 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <SDL2/SDL_image.h> #include <SDL2/SDL_image.h>
#include <SDL2/SDL_render.h> #include <SDL2/SDL_render.h>
#include <SDL2/SDL_mixer.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
@@ -47,6 +48,46 @@ int main ()
SDL_RenderClear(display_user.renderer); SDL_RenderClear(display_user.renderer);
SDL_Event event; SDL_Event event;
//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;
}
// 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;
}
// 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;
}
// Jouer le son une seule fois
Mix_PlayChannel(-1, son, 0);
// Loop pour le jeu entier menu et les jeux. // Loop pour le jeu entier menu et les jeux.
while(output != 0) while(output != 0)
{ {
@@ -125,6 +166,8 @@ int main ()
if (tab2d != NULL)free2D (tab2d, SIZE_PLAY); if (tab2d != NULL)free2D (tab2d, SIZE_PLAY);
if (playerPos != NULL)free (playerPos); if (playerPos != NULL)free (playerPos);
if (targets != NULL)free (targets); if (targets != NULL)free (targets);
Mix_FreeChunk(son);
Mix_CloseAudio();
SDL_Quit (); SDL_Quit ();
return 0; return 0;
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.