fix bug lose
This commit is contained in:
@@ -9,7 +9,9 @@
|
||||
#include "../include/display.h"
|
||||
|
||||
#include <SDL2/SDL_events.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_keycode.h>
|
||||
#include <SDL2/SDL_rect.h>
|
||||
#include <SDL2/SDL_render.h>
|
||||
#include <SDL2/SDL_scancode.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:
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user