fix deplacement out of range

This commit is contained in:
2024-12-13 11:06:44 +01:00
parent 2c2d446f74
commit 1d2190e55d
3 changed files with 15 additions and 3 deletions

View File

@@ -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;i<size;++i)
{

View File

@@ -87,8 +87,18 @@ move (unsigned short int **tab, vect *playerPos, vect direction)
{
short int valueOfNCase
= tab[playerPos->x + 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];

View File

@@ -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