From 5274a135d67ff5a8da9b7a1f467b006e18eae7f7 Mon Sep 17 00:00:00 2001 From: cyjullien1 Date: Thu, 12 Dec 2024 17:29:18 +0100 Subject: [PATCH] optimisation de move --- function.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/function.c b/function.c index 98694ad..3040d55 100644 --- a/function.c +++ b/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);