From 1d2190e55d22b0bd61589c89a9254d7ea1a4b2b0 Mon Sep 17 00:00:00 2001 From: Aubin DORIVAL Date: Fri, 13 Dec 2024 11:06:44 +0100 Subject: [PATCH] fix deplacement out of range --- display.c | 2 +- function.c | 14 ++++++++++++-- function.h | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/display.c b/display.c index fbdaca3..8f5f21a 100644 --- a/display.c +++ b/display.c @@ -3,7 +3,7 @@ void screenDisplay( unsigned short int **tab,int size) { - puts("0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 "); + //puts("0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 "); char element[7] ={' ','#','S','.','*','@','+'} ; for(int i=0;ix + direction.x][playerPos->y + direction.y]; - short int valueOfNPlusOneCase - = tab[playerPos->x + direction.x * 2][playerPos->y + direction.y * 2]; + + vect add = plusVect(*playerPos, direction); + add = plusVect(add,direction); + short int valueOfNPlusOneCase; + + if(add.x < 0 || add.y < 0) + { + valueOfNPlusOneCase = WALL; + }else + { + valueOfNPlusOneCase = tab[add.x][add.y]; + } short int returnValue = canIGoDirection (valueOfNCase, valueOfNPlusOneCase); short int playerState = tab[playerPos->x][playerPos->y]; diff --git a/function.h b/function.h index 38513b0..08b6297 100644 --- a/function.h +++ b/function.h @@ -24,6 +24,8 @@ void inGameLoop (unsigned short int **tab2d, int N, vect *playerPos, vect *targe bool isWin(unsigned short int **tab2d, vect *targets, int nbr_targets); bool islose(unsigned short int ** tab2d,const int N); bool blockBox(unsigned short int **tab2d, vect box_coor); +vect plusVect (vect one, vect two); + #endif // FONCTION_H