ajout de la librairie sdl mixer plus changement dans le makefile
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
CC = gcc
|
||||
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
|
||||
SRCDIR = script
|
||||
OBJDIR = obj
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_render.h>
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
@@ -46,6 +47,46 @@ int main ()
|
||||
nullScore(&score_user);
|
||||
SDL_RenderClear(display_user.renderer);
|
||||
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.
|
||||
while(output != 0)
|
||||
@@ -125,6 +166,8 @@ 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 ();
|
||||
|
||||
return 0;
|
||||
|
||||
BIN
Binary file not shown.
LFS
BIN
Binary file not shown.
LFS
BIN
Binary file not shown.
BIN
Binary file not shown.
LFS
BIN
Binary file not shown.
LFS
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
LFS
BIN
Binary file not shown.
Reference in New Issue
Block a user