optimisation de move
This commit is contained in:
30
function.c
30
function.c
@@ -97,41 +97,34 @@ void move(unsigned short int **tab,vect *playerPos, vect direction)
|
||||
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;
|
||||
@@ -143,13 +136,13 @@ void move(unsigned short int **tab,vect *playerPos, vect direction)
|
||||
|
||||
if(returnValue!=0)
|
||||
{
|
||||
|
||||
if(playerState==PLAYER_ON_TARGET){tab[playerPos->x][playerPos->y] = TARGET;}
|
||||
else{ tab[playerPos->x][playerPos->y] = EMPTY;}
|
||||
playerPos->x = playerPos->x+direction.x;
|
||||
playerPos->y = playerPos->y+direction.y;
|
||||
|
||||
}
|
||||
direction.x = 0;
|
||||
direction.y = 0;
|
||||
|
||||
}
|
||||
|
||||
void getStartPlayerPos(unsigned short int **tab2d, short int size, vect *playerPos )
|
||||
@@ -192,22 +185,19 @@ void inGameLoop(unsigned short int **tab2d,vect *playerPos )
|
||||
case 'd':
|
||||
direction.y=1;
|
||||
direction.x=0;
|
||||
move(tab2d,playerPos, direction);
|
||||
|
||||
break;
|
||||
case 'q':
|
||||
direction.y=-1;
|
||||
direction.x=0;
|
||||
move(tab2d,playerPos, direction);
|
||||
break;
|
||||
case 'z':
|
||||
direction.x=-1;
|
||||
direction.y=0;
|
||||
move(tab2d,playerPos, direction);
|
||||
break;
|
||||
case 's':
|
||||
direction.x=1;
|
||||
direction.y=0;
|
||||
move(tab2d,playerPos, direction);
|
||||
break;
|
||||
default:
|
||||
direction.x=0;
|
||||
@@ -215,6 +205,8 @@ void inGameLoop(unsigned short int **tab2d,vect *playerPos )
|
||||
|
||||
}
|
||||
|
||||
system("clear");
|
||||
move(tab2d,playerPos, direction);
|
||||
|
||||
printf("\n");
|
||||
screenDisplay(tab2d, 32);
|
||||
|
||||
Reference in New Issue
Block a user