encore meilleur

This commit is contained in:
2024-12-14 15:26:00 +01:00
parent af546b8440
commit fa7d5ce51a
5 changed files with 456 additions and 450 deletions

View File

@@ -58,7 +58,8 @@ void screenDisplaySDL (unsigned short int **tab, dis *display_user)
img = IMG_Load ("player_on_target.png"); img = IMG_Load ("player_on_target.png");
break; break;
} }
texture = SDL_CreateTextureFromSurface (display_user->renderer, img); texture
= SDL_CreateTextureFromSurface (display_user->renderer, img);
displayImage (display_user->renderer, texture, pos, size); displayImage (display_user->renderer, texture, pos, size);
SDL_FreeSurface (img); SDL_FreeSurface (img);
SDL_DestroyTexture (texture); SDL_DestroyTexture (texture);
@@ -89,9 +90,10 @@ int getMaxSize ()
void initSDL (dis *display_user) void initSDL (dis *display_user)
{ {
SDL_Init (SDL_INIT_VIDEO); SDL_Init (SDL_INIT_VIDEO);
display_user->window = SDL_CreateWindow ( display_user->window
"Sokoman", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, = SDL_CreateWindow ("Sokoman", SDL_WINDOWPOS_CENTERED,
display_user->size_window, display_user->size_window, SDL_WINDOW_SHOWN); SDL_WINDOWPOS_CENTERED, display_user->size_window,
display_user->size_window, SDL_WINDOW_SHOWN);
if (!display_user->window) if (!display_user->window)
{ {
SDL_Quit (); SDL_Quit ();

View File

@@ -67,7 +67,8 @@ short int canIGoDirection (short int valueOfNCase,
return 2; return 2;
} }
if ((valueOfNCase == BOX_ON_TARGET && valueOfNPlusOneCase == EMPTY) if ((valueOfNCase == BOX_ON_TARGET && valueOfNPlusOneCase == EMPTY)
|| (valueOfNCase == BOX_ON_TARGET && valueOfNPlusOneCase == TARGET)) || (valueOfNCase == BOX_ON_TARGET
&& valueOfNPlusOneCase == TARGET))
{ {
if (valueOfNPlusOneCase == TARGET) if (valueOfNPlusOneCase == TARGET)
{ {
@@ -111,7 +112,8 @@ void move (unsigned short int **tab, vect *playerPos, vect direction)
valueOfNPlusOneCase = tab[add.x][add.y]; valueOfNPlusOneCase = tab[add.x][add.y];
} }
short int returnValue = canIGoDirection (valueOfNCase, valueOfNPlusOneCase); short int returnValue
= canIGoDirection (valueOfNCase, valueOfNPlusOneCase);
short int playerState = tab[playerPos->x][playerPos->y]; short int playerState = tab[playerPos->x][playerPos->y];
switch (returnValue) switch (returnValue)
@@ -127,7 +129,8 @@ void move (unsigned short int **tab, vect *playerPos, vect direction)
// move player and the box // move player and the box
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
@@ -145,7 +148,8 @@ void move (unsigned short int **tab, vect *playerPos, vect direction)
case 5: case 5:
// move box and player on a target // move box and player on a target
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] tab[playerPos->x + direction.x][playerPos->y + direction.y]
= PLAYER_ON_TARGET; = PLAYER_ON_TARGET;
break; break;