ajout du deplacement du joueur
This commit is contained in:
121
function.c
121
function.c
@@ -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;
|
||||||
return 2;
|
case 1:
|
||||||
}
|
//move player
|
||||||
return 1;
|
tab[playePos.x][playerPos.y] = EMPTY;
|
||||||
}
|
tab[playerPos.x+direction.x][playePos.y+direction.y] = PLAYER;
|
||||||
return 0;
|
break;
|
||||||
|
case 2:
|
||||||
}
|
//move player and the box
|
||||||
|
tab[playePos.x][playerPos.y] = EMPTY;
|
||||||
int CanIGoDown(unsigned short int **tab,int size,int posX,int posY)
|
tab[playerPos.x+direction.x][playePos.y+direction.y] = PLAYER;
|
||||||
{
|
tab[playerPos.x+direction.x*2][playePos.y+direction.y*2] = BOX;
|
||||||
if(tab[posX][posY-1]!=1)
|
break;
|
||||||
{
|
case 3:
|
||||||
if(tab[posX][posY-1]==2)
|
//move player and the box is well-placed
|
||||||
{
|
tab[playePos.x][playerPos.y] = EMPTY;
|
||||||
return 2;
|
tab[playerPos.x+direction.x][playePos.y+direction.y] = PLAYER;
|
||||||
}
|
tab[playerPos.x+direction.x*2][playePos.y+direction.y*2] = BOX_ON_TARGET;
|
||||||
return 1;
|
break;
|
||||||
}
|
case 4:
|
||||||
return 0;
|
//move player on a target
|
||||||
|
tab[playePos.x][playerPos.y] = EMPTY;
|
||||||
}
|
tab[playerPos.x+direction.x][playePos.y+direction.y] = PLAYER_ON_TARGET;
|
||||||
|
break;
|
||||||
int CanIGoLeft(unsigned short int **tab,int size,int posX,int posY)
|
case 5:
|
||||||
{
|
//move player on a target
|
||||||
if(tab[posX-1][posY]!=1)
|
tab[playePos.x][playerPos.y] = EMPTY;
|
||||||
{
|
tab[playerPos.x+direction.x][playePos.y+direction.y] = PLAYER_ON_TARGET;
|
||||||
if(tab[posX-1][posY]==2)
|
break;
|
||||||
{
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
return 1;
|
//////pas fini + refaire la 5
|
||||||
}
|
player.x = playerPos.x+direction.x;
|
||||||
return 0;
|
player.y = playePos.y+direction.y;
|
||||||
|
}
|
||||||
}
|
|
||||||
|
int CanIGoDirection(short int valueOfNCase, short int valueOfNPlusOneCase)
|
||||||
int CanIGoRight(unsigned short int **tab,int size,int posX,int posY)
|
{
|
||||||
{
|
if(valueOfNCase!=WALL)
|
||||||
if(tab[posX+1][posY]!=1)
|
{
|
||||||
{
|
if(valueOfNCase==BOX && valueOfNPlusOneCase==EMPTY || valueOfNCase==BOX && valueOfNPlusOneCase==TARGET)
|
||||||
if(tab[posX+1][posY]==2)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user