fix bug lose
This commit is contained in:
BIN
image/lose.png
LFS
Normal file
BIN
image/lose.png
LFS
Normal file
Binary file not shown.
BIN
image/win.png
LFS
Normal file
BIN
image/win.png
LFS
Normal file
Binary file not shown.
@@ -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);
|
int nbr_targets, dis *display_user, score *score_user, bool menu);
|
||||||
char *timeToText(time_t time);
|
char *timeToText(time_t time);
|
||||||
void nullScore(score *player_score);
|
void nullScore(score *player_score);
|
||||||
|
void winOrLoseLoop(dis *display_user, bool win);
|
||||||
|
|
||||||
#endif // FONCTION_H
|
#endif // FONCTION_H
|
||||||
|
|||||||
6
maps/custom_2.txt
Normal file
6
maps/custom_2.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#############
|
||||||
|
##### I #
|
||||||
|
# C #
|
||||||
|
# #
|
||||||
|
# P #
|
||||||
|
#############
|
||||||
@@ -9,7 +9,9 @@
|
|||||||
#include "../include/display.h"
|
#include "../include/display.h"
|
||||||
|
|
||||||
#include <SDL2/SDL_events.h>
|
#include <SDL2/SDL_events.h>
|
||||||
|
#include <SDL2/SDL_image.h>
|
||||||
#include <SDL2/SDL_keycode.h>
|
#include <SDL2/SDL_keycode.h>
|
||||||
|
#include <SDL2/SDL_rect.h>
|
||||||
#include <SDL2/SDL_render.h>
|
#include <SDL2/SDL_render.h>
|
||||||
#include <SDL2/SDL_scancode.h>
|
#include <SDL2/SDL_scancode.h>
|
||||||
#include <SDL2/SDL_timer.h>
|
#include <SDL2/SDL_timer.h>
|
||||||
@@ -308,7 +310,7 @@ int inGameLoop (char **tab2d, vect *dim_tab, vect *playerPos, vect *targets,
|
|||||||
{
|
{
|
||||||
case SDL_SCANCODE_ESCAPE:
|
case SDL_SCANCODE_ESCAPE:
|
||||||
if(menu) return 0;
|
if(menu) return 0;
|
||||||
return -1;
|
return -1000;
|
||||||
finish = true;
|
finish = true;
|
||||||
break;
|
break;
|
||||||
case SDL_SCANCODE_D:
|
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))
|
if (isWin (tab2d, targets, nbr_targets))
|
||||||
{
|
{
|
||||||
puts ("Win!");
|
puts ("Win!");
|
||||||
|
return 1;
|
||||||
finish = true;
|
finish = true;
|
||||||
}
|
}
|
||||||
if (islose (tab2d, dim_tab->x))
|
if (islose (tab2d, dim_tab->x))
|
||||||
{
|
{
|
||||||
puts ("lose!");
|
puts ("lose!");
|
||||||
|
return 0;
|
||||||
finish = true;
|
finish = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -580,22 +584,29 @@ bool blockBox (char **tab2d, vect box_coor)
|
|||||||
|
|
||||||
for (int i = 0; i < 2; ++i)
|
for (int i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
|
wall = false;
|
||||||
vect current = plusVect (box_coor, dir_test[i]);
|
vect current = plusVect (box_coor, dir_test[i]);
|
||||||
while (!wall)
|
while (!wall)
|
||||||
{
|
{
|
||||||
char val = tab2d[current.x][current.y];
|
char val = tab2d[current.x][current.y];
|
||||||
|
printf("val : %d ", val);
|
||||||
vect cur_nor = plusVect (current, normal);
|
vect cur_nor = plusVect (current, normal);
|
||||||
char val_nor = tab2d[cur_nor.x][cur_nor.y];
|
char val_nor = tab2d[cur_nor.x][cur_nor.y];
|
||||||
|
printf("val_nor : %d\n", val_nor);
|
||||||
if (val == WALL)
|
if (val == WALL)
|
||||||
wall = true;
|
wall = true;
|
||||||
else if (val == TARGET)
|
else if (val == TARGET)
|
||||||
return false;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
current = plusVect(current, dir_test[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("coor (%d, %d)\n", box_coor.x, box_coor.y);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,6 +625,11 @@ char *timeToText (time_t time)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Mets à 0 le score.
|
||||||
|
* \param player_score Le score a mettre à 0.
|
||||||
|
* \return void
|
||||||
|
*/
|
||||||
void nullScore(score *player_score)
|
void nullScore(score *player_score)
|
||||||
{
|
{
|
||||||
player_score->after = 0;
|
player_score->after = 0;
|
||||||
@@ -621,3 +637,39 @@ void nullScore(score *player_score)
|
|||||||
player_score->move_box = 0;
|
player_score->move_box = 0;
|
||||||
player_score->move_player = 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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ int main ()
|
|||||||
tab2d = creatArea2D(SIZE_PLAY, SIZE_PLAY);
|
tab2d = creatArea2D(SIZE_PLAY, SIZE_PLAY);
|
||||||
targets = fileToTab2D(txt, tab2d, SIZE_PLAY, playerPos, &nbr_targets);
|
targets = fileToTab2D(txt, tab2d, SIZE_PLAY, playerPos, &nbr_targets);
|
||||||
output = inGameLoop(tab2d, &dim, playerPos, targets, nbr_targets, &display_user, &score_user, false);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user