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

20
maps/custom_1.txt Normal file
View File

@@ -0,0 +1,20 @@
####################
# #
# #
# #
# # #
# #
# # #
# I #
# P #
# #
# C #
# #
# # #
# #
# #
# #
# #
# #
# #
####################

20
maps/custom_2.txt Normal file
View File

@@ -0,0 +1,20 @@
####################
# #
# #
# #
# #
# #
# #
# I #
# #
# P #
# C #
# I #
# I #
# #
# #
# #
# #
# #
# #
####################

View File

@@ -178,15 +178,16 @@ void move (char **tab, vect *playerPos, vect direction, score *score_user)
switch (returnValue) switch (returnValue)
{ {
case 0: case 0:
playAudio(2);
break; break;
case 1: case 1:
//move player //move player
playAudio(4);
tab[playerPos->x + direction.x][playerPos->y + direction.y] = PLAYER; tab[playerPos->x + direction.x][playerPos->y + direction.y] = PLAYER;
break; break;
case 2: case 2:
// move player and the box // move player and the box
playAudio(5);
tab[playerPos->x + direction.x][playerPos->y + direction.y] = PLAYER; tab[playerPos->x + direction.x][playerPos->y + direction.y] = PLAYER;
tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2] tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2]
= BOX; = BOX;
@@ -194,7 +195,7 @@ void move (char **tab, vect *playerPos, vect direction, score *score_user)
break; break;
case 3: case 3:
// move player and the box is well-placed // 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][playerPos->y + direction.y] = PLAYER;
tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2] tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2]
= BOX_ON_TARGET; = BOX_ON_TARGET;
@@ -202,13 +203,13 @@ void move (char **tab, vect *playerPos, vect direction, score *score_user)
break; break;
case 4: case 4:
// move player on a target // move player on a target
playAudio(4);
tab[playerPos->x + direction.x][playerPos->y + direction.y] tab[playerPos->x + direction.x][playerPos->y + direction.y]
= PLAYER_ON_TARGET; = PLAYER_ON_TARGET;
break; break;
case 5: case 5:
// move box and player on a target // move box and player on a target
playAudio(4);
tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2] tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2]
= BOX; = BOX;
tab[playerPos->x + direction.x][playerPos->y + direction.y] 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; break;
case 6: case 6:
// move player on a target and box on a target // move player on a target and box on a target
playAudio(3);
tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2] tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2]
= BOX_ON_TARGET; = BOX_ON_TARGET;
tab[playerPos->x + direction.x][playerPos->y + direction.y] 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++; score_user->move_box++;
break; break;
case 7: case 7:
playAudio(3);
tab[playerPos->x + direction.x][playerPos->y + direction.y] tab[playerPos->x + direction.x][playerPos->y + direction.y]
= PLAYER_ON_BUTTON; = PLAYER_ON_BUTTON;
break; break;
@@ -837,8 +839,8 @@ void winOrLoseLoop(dis *display_user,score *score_user, bool win)
SDL_Surface *img; SDL_Surface *img;
SDL_Texture *texture; SDL_Texture *texture;
if(win) img = IMG_Load("image/win.png"); if(win){ img = IMG_Load("image/win.png");playAudio(0);}
else img = IMG_Load("image/lose.png"); else {img = IMG_Load("image/lose.png");playAudio(1);}
texture = SDL_CreateTextureFromSurface (display_user->renderer, img); texture = SDL_CreateTextureFromSurface (display_user->renderer, img);

View File

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

Binary file not shown.