Skip to content
Snippets Groups Projects
Commit 2d5b7a10 authored by belkhiritaha's avatar belkhiritaha
Browse files

animation marche update

parent 044cd4df
No related branches found
No related tags found
No related merge requests found
...@@ -124,18 +124,22 @@ void manageMovement(){ ...@@ -124,18 +124,22 @@ void manageMovement(){
if(keys[PLAYER_UP]){ if(keys[PLAYER_UP]){
moveUpPlayer(); moveUpPlayer();
player.isMoving = 1; player.isMoving = 1;
player.direction = PLAYER_UP;
} }
if(keys[PLAYER_DOWN]){ if(keys[PLAYER_DOWN]){
moveDownPlayer(); moveDownPlayer();
player.isMoving = 1; player.isMoving = 1;
player.direction = PLAYER_DOWN;
} }
if(keys[PLAYER_LEFT]){ if(keys[PLAYER_LEFT]){
moveLeftPlayer(); moveLeftPlayer();
player.isMoving = 1; player.isMoving = 1;
player.direction = PLAYER_LEFT;
} }
if(keys[PLAYER_RIGHT]){ if(keys[PLAYER_RIGHT]){
moveRightPlayer(); moveRightPlayer();
player.isMoving = 1; player.isMoving = 1;
player.direction = PLAYER_RIGHT;
} }
player.isMoving = 0; player.isMoving = 0;
} }
......
...@@ -18,6 +18,7 @@ typedef struct player{ ...@@ -18,6 +18,7 @@ typedef struct player{
int waterMax; int waterMax;
int speed; int speed;
int isMoving; int isMoving;
int direction;
} player_t; } player_t;
extern player_t player; extern player_t player;
......
...@@ -150,7 +150,9 @@ void drawPlayer(){ ...@@ -150,7 +150,9 @@ 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_RenderCopyEx(renderer, playerTexture, &destRect, &rect, 0, NULL, SDL_FLIP_NONE); 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);
} }
void drawBackgroundSides(){ void drawBackgroundSides(){
...@@ -221,7 +223,7 @@ void mainLoop(){ ...@@ -221,7 +223,7 @@ void mainLoop(){
noHoverSurface = IMG_Load("Res/noHover.png"); noHoverSurface = IMG_Load("Res/noHover.png");
noHoverTexture = SDL_CreateTextureFromSurface(renderer, noHoverSurface); noHoverTexture = SDL_CreateTextureFromSurface(renderer, noHoverSurface);
playerSurface = IMG_Load("Res/character_spritesheet.png"); playerSurface = IMG_Load("Res/character_tileset.png");
playerTexture = SDL_CreateTextureFromSurface(renderer, playerSurface); playerTexture = SDL_CreateTextureFromSurface(renderer, playerSurface);
backgroundSurface = IMG_Load("Res/background_mat.png"); backgroundSurface = IMG_Load("Res/background_mat.png");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment