From e84ae7fe3a6f0bf3646a41d0a02fe57f969c1cbe Mon Sep 17 00:00:00 2001 From: cyjullien1 Date: Thu, 12 Dec 2024 13:08:18 +0100 Subject: [PATCH] ajout du deplacement du joueur --- function.c | 123 +++++++++++++++++++++++++++++++++-------------------- function.h | 7 +++ 2 files changed, 84 insertions(+), 46 deletions(-) diff --git a/function.c b/function.c index bdad64f..9ff395f 100644 --- a/function.c +++ b/function.c @@ -38,58 +38,89 @@ unsigned short int **creatArea2D(const unsigned int N) 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; } + 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 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; - -} \ No newline at end of file diff --git a/function.h b/function.h index 525b2a3..66a5e8d 100644 --- a/function.h +++ b/function.h @@ -10,8 +10,15 @@ #define BOX_ON_TARGET 4 #define PLAYER 5 #define PLAYER_ON_TARGET 6 +typedef struct Vecteur +{ + short int x; + short int y; +} vect; + unsigned short int **creatArea2D(const unsigned int N); #endif // FONCTION_H +