ajout du deplacement du joueur

This commit is contained in:
cyjullien1
2024-12-12 13:08:18 +01:00
parent f3024f1cbb
commit e84ae7fe3a
2 changed files with 84 additions and 46 deletions

View File

@@ -38,58 +38,89 @@ unsigned short int **creatArea2D(const unsigned int N)
return tab2d; return tab2d;
} }
int CanIGoUp(unsigned short int **tab,int size,int posX,int posY) void move(unsigned short int **tab,int size,vect playerPos, vect direction)
{ {
if(tab[posX][posY+1]!=1) 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)
{ {
if(tab[posX][posY+1]==2) 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)
{
if(valueOfNCase!=WALL)
{
if(valueOfNCase==BOX && valueOfNPlusOneCase==EMPTY || valueOfNCase==BOX && valueOfNPlusOneCase==TARGET)
{ {
if(valueOfNPlusOneCase==TARGET)
{
// Box on target
return 3;
}
//move the box
return 2; return 2;
} }
if(valueOfNCase==BOX_ON_TARGET && valueOfNPlusOneCase==EMPTY || valueOfNCase==BOX_ON_TARGET && valueOfNPlusOneCase==TARGET)
{
if(valueOfNPlusOneCase==TARGET)
{
// Box on target and player on target too
return 6;
}
//move the box but player on a target
return 5;
}
if(valueOfNCase==TARGET)
{
//move player on target
return 4;
}
// move player
return 1; return 1;
} }
return 0; return 0;
} }
int CanIGoDown(unsigned short int **tab,int size,int posX,int posY)
{
if(tab[posX][posY-1]!=1)
{
if(tab[posX][posY-1]==2)
{
return 2;
}
return 1;
}
return 0;
}
int CanIGoLeft(unsigned short int **tab,int size,int posX,int posY)
{
if(tab[posX-1][posY]!=1)
{
if(tab[posX-1][posY]==2)
{
return 2;
}
return 1;
}
return 0;
}
int CanIGoRight(unsigned short int **tab,int size,int posX,int posY)
{
if(tab[posX+1][posY]!=1)
{
if(tab[posX+1][posY]==2)
{
return 2;
}
return 1;
}
return 0;
}

View File

@@ -10,8 +10,15 @@
#define BOX_ON_TARGET 4 #define BOX_ON_TARGET 4
#define PLAYER 5 #define PLAYER 5
#define PLAYER_ON_TARGET 6 #define PLAYER_ON_TARGET 6
typedef struct Vecteur
{
short int x;
short int y;
} vect;
unsigned short int **creatArea2D(const unsigned int N); unsigned short int **creatArea2D(const unsigned int N);
#endif // FONCTION_H #endif // FONCTION_H