plus de warning dans les deplacement
This commit is contained in:
116
function.c
116
function.c
@@ -38,58 +38,11 @@ unsigned short int **creatArea2D(const unsigned int N)
|
||||
return tab2d;
|
||||
}
|
||||
|
||||
void move(unsigned short int **tab,int size,vect playerPos, vect direction)
|
||||
{
|
||||
short int valueOfNCase=tab[playerPos.x+direction.x][playePos.y+direction.y];
|
||||
short int valueOfNPlusOneCase=tab[playerPos.x+direction.x*2][playePos.y+direction.y*2];
|
||||
|
||||
short int returnValue CanIGoDirection(valueOfNCase,valueOfNPlusOneCase);
|
||||
short int playerState =tab[playerPos.x][playePos.y];
|
||||
|
||||
switch case(returnValue)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
//move player
|
||||
tab[playePos.x][playerPos.y] = EMPTY;
|
||||
tab[playerPos.x+direction.x][playePos.y+direction.y] = PLAYER;
|
||||
break;
|
||||
case 2:
|
||||
//move player and the box
|
||||
tab[playePos.x][playerPos.y] = EMPTY;
|
||||
tab[playerPos.x+direction.x][playePos.y+direction.y] = PLAYER;
|
||||
tab[playerPos.x+direction.x*2][playePos.y+direction.y*2] = BOX;
|
||||
break;
|
||||
case 3:
|
||||
//move player and the box is well-placed
|
||||
tab[playePos.x][playerPos.y] = EMPTY;
|
||||
tab[playerPos.x+direction.x][playePos.y+direction.y] = PLAYER;
|
||||
tab[playerPos.x+direction.x*2][playePos.y+direction.y*2] = BOX_ON_TARGET;
|
||||
break;
|
||||
case 4:
|
||||
//move player on a target
|
||||
tab[playePos.x][playerPos.y] = EMPTY;
|
||||
tab[playerPos.x+direction.x][playePos.y+direction.y] = PLAYER_ON_TARGET;
|
||||
break;
|
||||
case 5:
|
||||
//move player on a target
|
||||
tab[playePos.x][playerPos.y] = EMPTY;
|
||||
tab[playerPos.x+direction.x][playePos.y+direction.y] = PLAYER_ON_TARGET;
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
//////pas fini + refaire la 5
|
||||
player.x = playerPos.x+direction.x;
|
||||
player.y = playePos.y+direction.y;
|
||||
}
|
||||
|
||||
int CanIGoDirection(short int valueOfNCase, short int valueOfNPlusOneCase)
|
||||
short int canIGoDirection(short int valueOfNCase, short int valueOfNPlusOneCase)
|
||||
{
|
||||
if(valueOfNCase!=WALL)
|
||||
{
|
||||
if(valueOfNCase==BOX && valueOfNPlusOneCase==EMPTY || valueOfNCase==BOX && valueOfNPlusOneCase==TARGET)
|
||||
if((valueOfNCase==BOX && valueOfNPlusOneCase==EMPTY) ||( valueOfNCase==BOX && valueOfNPlusOneCase==TARGET))
|
||||
{
|
||||
|
||||
if(valueOfNPlusOneCase==TARGET)
|
||||
@@ -100,7 +53,7 @@ int CanIGoDirection(short int valueOfNCase, short int valueOfNPlusOneCase)
|
||||
//move the box
|
||||
return 2;
|
||||
}
|
||||
if(valueOfNCase==BOX_ON_TARGET && valueOfNPlusOneCase==EMPTY || valueOfNCase==BOX_ON_TARGET && valueOfNPlusOneCase==TARGET)
|
||||
if((valueOfNCase==BOX_ON_TARGET && valueOfNPlusOneCase==EMPTY )|| (valueOfNCase==BOX_ON_TARGET && valueOfNPlusOneCase==TARGET))
|
||||
{
|
||||
|
||||
if(valueOfNPlusOneCase==TARGET)
|
||||
@@ -124,3 +77,66 @@ int CanIGoDirection(short int valueOfNCase, short int valueOfNPlusOneCase)
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void 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];
|
||||
|
||||
short int returnValue = canIGoDirection(valueOfNCase,valueOfNPlusOneCase);
|
||||
short int playerState =tab[playerPos.x][playerPos.y];
|
||||
|
||||
switch(returnValue)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
//move player
|
||||
if(playerState==PLAYER_ON_TARGET){tab[playerPos.x][playerPos.y] = TARGET;}
|
||||
else{ tab[playerPos.x][playerPos.y] = EMPTY;}
|
||||
tab[playerPos.x+direction.x][playerPos.y+direction.y] = PLAYER;
|
||||
break;
|
||||
case 2:
|
||||
//move player and the box
|
||||
if(playerState==PLAYER_ON_TARGET){tab[playerPos.x][playerPos.y] = TARGET;}
|
||||
else{ tab[playerPos.x][playerPos.y] = EMPTY;}
|
||||
tab[playerPos.x+direction.x][playerPos.y+direction.y] = PLAYER;
|
||||
tab[playerPos.x+direction.x*2][playerPos.y+direction.y*2] = BOX;
|
||||
break;
|
||||
case 3:
|
||||
//move player and the box is well-placed
|
||||
if(playerState==PLAYER_ON_TARGET){tab[playerPos.x][playerPos.y] = TARGET;}
|
||||
else{ tab[playerPos.x][playerPos.y] = EMPTY;}
|
||||
tab[playerPos.x+direction.x][playerPos.y+direction.y] = PLAYER;
|
||||
tab[playerPos.x+direction.x*2][playerPos.y+direction.y*2] = BOX_ON_TARGET;
|
||||
break;
|
||||
case 4:
|
||||
//move player on a target
|
||||
if(playerState==PLAYER_ON_TARGET){tab[playerPos.x][playerPos.y] = TARGET;}
|
||||
else{ tab[playerPos.x][playerPos.y] = EMPTY;}
|
||||
tab[playerPos.x+direction.x][playerPos.y+direction.y] = PLAYER_ON_TARGET;
|
||||
break;
|
||||
case 5:
|
||||
//move box and player on a target
|
||||
if(playerState==PLAYER_ON_TARGET){tab[playerPos.x][playerPos.y] = TARGET;}
|
||||
else{ tab[playerPos.x][playerPos.y] = EMPTY;}
|
||||
tab[playerPos.x+direction.x*2][playerPos.y+direction.y*2] = BOX;
|
||||
tab[playerPos.x+direction.x][playerPos.y+direction.y] = PLAYER_ON_TARGET;
|
||||
break;
|
||||
case 6:
|
||||
//move player on a target and box on a target
|
||||
if(playerState==PLAYER_ON_TARGET){tab[playerPos.x][playerPos.y] = TARGET;}
|
||||
else{ tab[playerPos.x][playerPos.y] = EMPTY;}
|
||||
tab[playerPos.x+direction.x*2][playerPos.y+direction.y*2] = BOX_ON_TARGET;
|
||||
tab[playerPos.x+direction.x][playerPos.y+direction.y] = PLAYER_ON_TARGET;
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(returnValue!=0)
|
||||
{
|
||||
playerPos.x = playerPos.x+direction.x;
|
||||
playerPos.y = playerPos.y+direction.y;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user