This is a video of the bug ill explain and post code below
">
when you just press down the player moves down with the animation
if you press a another direction key with down it will take it direction sprite and move down
heres the code
if(in_game_state == 1 && app_state == 5) {
keystate = SDL_GetKeyState(NULL);
if(keystate[SDLK_DOWN]) {
if(btnPressed == 1) {
if(player_pos == 2) {
player_pos = 1;
}else if(player_pos == 1) {
player_pos = 3;
}else if(player_pos == 3){
player_pos = 2;
}
}else{
player_pos = 2;
}
move_y -= 1;
btnPressed = 1;
}else if(keystate[SDLK_UP]) {
player_pos = 11;
move_y += 1;
btnPressed = 1;
}else if(keystate[SDLK_RIGHT]) {
player_pos = 8;
move_x -= 1;
btnPressed = 1;
}else if(keystate[SDLK_LEFT]) {
player_pos = 5;
move_x += 1;
btnPressed = 1;
}else{
btnPressed = 0;
}
}
Defining variables
in_game_state - is just that it that the player is on the map and is allowed to move
app_state - is just so we know we are on the map part of the game
btnPressed - is just if the button pressed or not
move_x - is the players position on the screen
move_y - is the players position on the screen
player_pos = is the position of the sprite being used ( this is how im doing the animation )