From 0e0b1a2528392eda8e591eced3c3e7643224688c Mon Sep 17 00:00:00 2001 From: Aubin DORIVAL Date: Mon, 30 Dec 2024 11:20:30 +0100 Subject: [PATCH] fix bug lose --- image/lose.png | 3 +++ image/win.png | 3 +++ include/function.h | 1 + maps/custom_2.txt | 6 +++++ script/function.c | 56 ++++++++++++++++++++++++++++++++++++++++++++-- script/main.c | 3 +++ 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 image/lose.png create mode 100644 image/win.png create mode 100644 maps/custom_2.txt diff --git a/image/lose.png b/image/lose.png new file mode 100644 index 0000000..dc1cbbe --- /dev/null +++ b/image/lose.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72892e84e4d07c251f0fd859291936969a5d5a447ab0de79146907e807c1df34 +size 5464 diff --git a/image/win.png b/image/win.png new file mode 100644 index 0000000..3cba41a --- /dev/null +++ b/image/win.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e494247b2804e951457c9f71ee75e0c5a0238a599f531ca8218e692da1230f64 +size 4178 diff --git a/include/function.h b/include/function.h index 315bf78..a619a96 100644 --- a/include/function.h +++ b/include/function.h @@ -52,5 +52,6 @@ int inGameLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets, int nbr_targets, dis *display_user, score *score_user, bool menu); char *timeToText(time_t time); void nullScore(score *player_score); +void winOrLoseLoop(dis *display_user, bool win); #endif // FONCTION_H diff --git a/maps/custom_2.txt b/maps/custom_2.txt new file mode 100644 index 0000000..65df458 --- /dev/null +++ b/maps/custom_2.txt @@ -0,0 +1,6 @@ +############# +##### I # +# C # +# # +# P # +############# diff --git a/script/function.c b/script/function.c index 3595416..58c1657 100644 --- a/script/function.c +++ b/script/function.c @@ -9,7 +9,9 @@ #include "../include/display.h" #include +#include #include +#include #include #include #include @@ -308,7 +310,7 @@ int inGameLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets, { case SDL_SCANCODE_ESCAPE: if(menu) return 0; - return -1; + return -1000; finish = true; break; case SDL_SCANCODE_D: @@ -353,11 +355,13 @@ int inGameLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets, if (isWin (tab2d, targets, nbr_targets)) { puts ("Win!"); + return 1; finish = true; } if (islose (tab2d, dim_tab->x)) { puts ("lose!"); + return 0; finish = true; } } @@ -580,22 +584,29 @@ bool blockBox (char **tab2d, vect box_coor) for (int i = 0; i < 2; ++i) { + wall = false; vect current = plusVect (box_coor, dir_test[i]); while (!wall) { char val = tab2d[current.x][current.y]; + printf("val : %d ", val); vect cur_nor = plusVect (current, normal); char val_nor = tab2d[cur_nor.x][cur_nor.y]; + printf("val_nor : %d\n", val_nor); if (val == WALL) wall = true; else if (val == TARGET) return false; - else if (val_nor != WALL || val_nor != BOX || val_nor != BOX_ON_TARGET) + if (val_nor != WALL) { + printf("coor (%d, %d), val_nor : %d\n", box_coor.x, box_coor.y, val_nor); return false; } + current = plusVect(current, dir_test[i]); } } + + printf("coor (%d, %d)\n", box_coor.x, box_coor.y); return true; } @@ -614,6 +625,11 @@ char *timeToText (time_t time) return result; } +/** + * \brief Mets à 0 le score. + * \param player_score Le score a mettre à 0. + * \return void +*/ void nullScore(score *player_score) { player_score->after = 0; @@ -621,3 +637,39 @@ void nullScore(score *player_score) player_score->move_box = 0; player_score->move_player = 0; } + +/** + * \brief Fonction de loop pour la win ou la lose. + * \param display_user Tout les information du display de l'utilisateur utile. + * \param win Si on veut un affichage de victoire ou non. +*/ +void winOrLoseLoop(dis *display_user, bool win) +{ + puts("dedans"); + printf("%b \n", win); + SDL_Surface *img; + SDL_Texture *texture; + + if(win) img = IMG_Load("image/win.png"); + else img = IMG_Load("image/lose.png"); + + texture = SDL_CreateTextureFromSurface (display_user->renderer, img); + printf("text : %p", texture); + + vect pos = {0, 0}; + displayImage(display_user->renderer, texture, pos, display_user->size_window); + SDL_RenderPresent (display_user->renderer); + + bool finish = false; + SDL_Event event; + SDL_Delay(100); + while(!finish) + { + SDL_PollEvent(&event); + if(event.type == SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_RETURN) finish = true; + SDL_Delay(16); + } + puts("fini"); + + return; +} diff --git a/script/main.c b/script/main.c index c8f8d7f..1f18ac0 100644 --- a/script/main.c +++ b/script/main.c @@ -72,6 +72,9 @@ int main () tab2d = creatArea2D(SIZE_PLAY, SIZE_PLAY); targets = fileToTab2D(txt, tab2d, SIZE_PLAY, playerPos, &nbr_targets); output = inGameLoop(tab2d, &dim, playerPos, targets, nbr_targets, &display_user, &score_user, false); + SDL_RenderClear(display_user.renderer); + if(output != -1000) winOrLoseLoop(&display_user, output==1); + output = -1; } }