diff --git a/maps/custom_1.txt b/maps/custom_1.txt new file mode 100644 index 0000000..960f687 --- /dev/null +++ b/maps/custom_1.txt @@ -0,0 +1,20 @@ +#################### +# # +# # +# # +# # # +# # +# # # +# I # +# P # +# # +# C # +# # +# # # +# # +# # +# # +# # +# # +# # +#################### diff --git a/maps/custom_2.txt b/maps/custom_2.txt new file mode 100644 index 0000000..67d79f0 --- /dev/null +++ b/maps/custom_2.txt @@ -0,0 +1,20 @@ +#################### +# # +# # +# # +# # +# # +# # +# I # +# # +# P # +# C # +# I # +# I # +# # +# # +# # +# # +# # +# # +#################### diff --git a/script/function.c b/script/function.c index 4b99cf3..273faf4 100644 --- a/script/function.c +++ b/script/function.c @@ -178,15 +178,16 @@ void move (char **tab, vect *playerPos, vect direction, score *score_user) switch (returnValue) { case 0: - + playAudio(2); break; case 1: - // move player + //move player + playAudio(4); tab[playerPos->x + direction.x][playerPos->y + direction.y] = PLAYER; break; case 2: // move player and the box - + playAudio(5); tab[playerPos->x + direction.x][playerPos->y + direction.y] = PLAYER; tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2] = BOX; @@ -194,7 +195,7 @@ void move (char **tab, vect *playerPos, vect direction, score *score_user) break; case 3: // move player and the box is well-placed - + playAudio(3); tab[playerPos->x + direction.x][playerPos->y + direction.y] = PLAYER; tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2] = BOX_ON_TARGET; @@ -202,13 +203,13 @@ void move (char **tab, vect *playerPos, vect direction, score *score_user) break; case 4: // move player on a target - + playAudio(4); tab[playerPos->x + direction.x][playerPos->y + direction.y] = PLAYER_ON_TARGET; break; case 5: // move box and player on a target - + playAudio(4); tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2] = BOX; tab[playerPos->x + direction.x][playerPos->y + direction.y] @@ -217,7 +218,7 @@ void move (char **tab, vect *playerPos, vect direction, score *score_user) break; case 6: // move player on a target and box on a target - + playAudio(3); tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2] = BOX_ON_TARGET; tab[playerPos->x + direction.x][playerPos->y + direction.y] @@ -225,6 +226,7 @@ void move (char **tab, vect *playerPos, vect direction, score *score_user) score_user->move_box++; break; case 7: + playAudio(3); tab[playerPos->x + direction.x][playerPos->y + direction.y] = PLAYER_ON_BUTTON; break; @@ -837,8 +839,8 @@ void winOrLoseLoop(dis *display_user,score *score_user, bool win) SDL_Surface *img; SDL_Texture *texture; - if(win) img = IMG_Load("image/win.png"); - else img = IMG_Load("image/lose.png"); + if(win){ img = IMG_Load("image/win.png");playAudio(0);} + else {img = IMG_Load("image/lose.png");playAudio(1);} texture = SDL_CreateTextureFromSurface (display_user->renderer, img); diff --git a/script/main.c b/script/main.c index 349441d..5170767 100644 --- a/script/main.c +++ b/script/main.c @@ -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 (); diff --git a/sfx/levelPlay.mp3 b/sfx/levelPlay.mp3 index 0d97474..e828136 100644 --- a/sfx/levelPlay.mp3 +++ b/sfx/levelPlay.mp3 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:da18e13d06c95c2e063def13b44258caf8566e5edbdf5b8b20dad11394806437 -size 3232633 +oid sha256:6fb2015bedf388949dc5d8c026820404c690cef3c561cb46c4607585223dbeba +size 2440181