Skip to content
Snippets Groups Projects
Commit 1715eaa5 authored by belkhiritaha's avatar belkhiritaha
Browse files

ajout animation idle + flip selon la direction

parent 730a31d9
No related branches found
No related tags found
No related merge requests found
...@@ -126,22 +126,22 @@ void manageMovement(){ ...@@ -126,22 +126,22 @@ void manageMovement(){
player.isMoving = 1; player.isMoving = 1;
player.direction = PLAYER_UP; player.direction = PLAYER_UP;
} }
if(keys[PLAYER_DOWN]){ else if(keys[PLAYER_DOWN]){
moveDownPlayer(); moveDownPlayer();
player.isMoving = 1; player.isMoving = 1;
player.direction = PLAYER_DOWN; player.direction = PLAYER_DOWN;
} }
if(keys[PLAYER_LEFT]){ else if(keys[PLAYER_LEFT]){
moveLeftPlayer(); moveLeftPlayer();
player.isMoving = 1; player.isMoving = 1;
player.direction = PLAYER_LEFT; player.direction = PLAYER_LEFT;
} }
if(keys[PLAYER_RIGHT]){ else if(keys[PLAYER_RIGHT]){
moveRightPlayer(); moveRightPlayer();
player.isMoving = 1; player.isMoving = 1;
player.direction = PLAYER_RIGHT; player.direction = PLAYER_RIGHT;
} }
player.isMoving = 0; else player.isMoving = 0;
} }
int selectStateHover(){ int selectStateHover(){
......
...@@ -153,9 +153,13 @@ void drawPlayer(){ ...@@ -153,9 +153,13 @@ void drawPlayer(){
rect.x = player.x + (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2; rect.x = player.x + (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2;
rect.y = player.y ; rect.y = player.y ;
SDL_Rect destRect = {32 * (SDL_GetTicks()/200%6), 0, 32, 32}; SDL_Rect destRect = {32 * (SDL_GetTicks()/200%6), 0, 32, 32};
SDL_Texture * drawTexture = (player.isMoving) ? (playerTexture):(playerIdleTexture);
int flip = (player.direction == PLAYER_LEFT) ? (SDL_FLIP_HORIZONTAL) : (SDL_FLIP_NONE); int flip = (player.direction == PLAYER_LEFT) ? (SDL_FLIP_HORIZONTAL) : (SDL_FLIP_NONE);
SDL_RenderCopyEx(renderer, playerTexture, &destRect, &rect, 0, NULL, flip); if (player.isMoving){
SDL_RenderCopyEx(renderer, playerTexture, &destRect, &rect, 0, NULL, flip);
}
else {
SDL_RenderCopyEx(renderer, playerIdleTexture, &destRect, &rect, 0, NULL, flip);
}
} }
void drawBackgroundSides(){ void drawBackgroundSides(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment