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

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