From 1715eaa5423fa25f32055ccb19f527a2edda52e0 Mon Sep 17 00:00:00 2001 From: belkhiritaha <belkhiri.taha53@gmail.com> Date: Wed, 22 Jun 2022 20:21:15 +0200 Subject: [PATCH] ajout animation idle + flip selon la direction --- travail_de_groupe/chef_oeuvre/src/player.c | 8 ++++---- travail_de_groupe/chef_oeuvre/src/render.c | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/travail_de_groupe/chef_oeuvre/src/player.c b/travail_de_groupe/chef_oeuvre/src/player.c index 622717b..865f3a1 100644 --- a/travail_de_groupe/chef_oeuvre/src/player.c +++ b/travail_de_groupe/chef_oeuvre/src/player.c @@ -126,22 +126,22 @@ void manageMovement(){ player.isMoving = 1; player.direction = PLAYER_UP; } - if(keys[PLAYER_DOWN]){ + else if(keys[PLAYER_DOWN]){ moveDownPlayer(); player.isMoving = 1; player.direction = PLAYER_DOWN; } - if(keys[PLAYER_LEFT]){ + else if(keys[PLAYER_LEFT]){ moveLeftPlayer(); player.isMoving = 1; player.direction = PLAYER_LEFT; } - if(keys[PLAYER_RIGHT]){ + else if(keys[PLAYER_RIGHT]){ moveRightPlayer(); player.isMoving = 1; player.direction = PLAYER_RIGHT; } - player.isMoving = 0; + else player.isMoving = 0; } int selectStateHover(){ diff --git a/travail_de_groupe/chef_oeuvre/src/render.c b/travail_de_groupe/chef_oeuvre/src/render.c index eafdaab..2c4c73a 100644 --- a/travail_de_groupe/chef_oeuvre/src/render.c +++ b/travail_de_groupe/chef_oeuvre/src/render.c @@ -153,9 +153,13 @@ void drawPlayer(){ rect.x = player.x + (screenDimension.w - (MAPSIZE * CELLSIZE)) / 2; rect.y = player.y ; 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); - 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(){ -- GitLab