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;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
//move player
|
//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;
|
tab[playerPos->x+direction.x][playerPos->y+direction.y] = PLAYER;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
//move player and the box
|
//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][playerPos->y+direction.y] = PLAYER;
|
||||||
tab[playerPos->x+direction.x*2][playerPos->y+direction.y*2] = BOX;
|
tab[playerPos->x+direction.x*2][playerPos->y+direction.y*2] = BOX;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
//move player and the box is well-placed
|
//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][playerPos->y+direction.y] = PLAYER;
|
||||||
tab[playerPos->x+direction.x*2][playerPos->y+direction.y*2] = BOX_ON_TARGET;
|
tab[playerPos->x+direction.x*2][playerPos->y+direction.y*2] = BOX_ON_TARGET;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
//move player on a target
|
//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;
|
tab[playerPos->x+direction.x][playerPos->y+direction.y] = PLAYER_ON_TARGET;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
//move box and player on a target
|
//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*2][playerPos->y+direction.y*2] = BOX;
|
||||||
tab[playerPos->x+direction.x][playerPos->y+direction.y] = PLAYER_ON_TARGET;
|
tab[playerPos->x+direction.x][playerPos->y+direction.y] = PLAYER_ON_TARGET;
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
//move player on a target and box on a target
|
//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*2][playerPos->y+direction.y*2] = BOX_ON_TARGET;
|
||||||
tab[playerPos->x+direction.x][playerPos->y+direction.y] = PLAYER_ON_TARGET;
|
tab[playerPos->x+direction.x][playerPos->y+direction.y] = PLAYER_ON_TARGET;
|
||||||
break;
|
break;
|
||||||
@@ -143,13 +136,13 @@ void move(unsigned short int **tab,vect *playerPos, vect direction)
|
|||||||
|
|
||||||
if(returnValue!=0)
|
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->x = playerPos->x+direction.x;
|
||||||
playerPos->y = playerPos->y+direction.y;
|
playerPos->y = playerPos->y+direction.y;
|
||||||
|
|
||||||
}
|
}
|
||||||
direction.x = 0;
|
|
||||||
direction.y = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void getStartPlayerPos(unsigned short int **tab2d, short int size, vect *playerPos )
|
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':
|
case 'd':
|
||||||
direction.y=1;
|
direction.y=1;
|
||||||
direction.x=0;
|
direction.x=0;
|
||||||
move(tab2d,playerPos, direction);
|
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
direction.y=-1;
|
direction.y=-1;
|
||||||
direction.x=0;
|
direction.x=0;
|
||||||
move(tab2d,playerPos, direction);
|
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
direction.x=-1;
|
direction.x=-1;
|
||||||
direction.y=0;
|
direction.y=0;
|
||||||
move(tab2d,playerPos, direction);
|
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
direction.x=1;
|
direction.x=1;
|
||||||
direction.y=0;
|
direction.y=0;
|
||||||
move(tab2d,playerPos, direction);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
direction.x=0;
|
direction.x=0;
|
||||||
@@ -215,6 +205,8 @@ void inGameLoop(unsigned short int **tab2d,vect *playerPos )
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
system("clear");
|
||||||
|
move(tab2d,playerPos, direction);
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
screenDisplay(tab2d, 32);
|
screenDisplay(tab2d, 32);
|
||||||
|
|||||||
Reference in New Issue
Block a user