If the snake goes up it normally won't react if you press down. But if it goes up and then I hit right(or left) and then quickly hit down the program isn't able to render it but apparently it recognizes the change of direction so the snake goes down. Same goes for every other direction.
What can I do to fix this?
Here is my code help me please. Thanks in advance!
void CSnake::Event(SDL_Event &event){
if (SDL_KEYDOWN)
switch (event.key.keysym.sym){
case SDLK_UP:
if (dir!=DOWN){
yVel = -20;
xVel = 0;
dir = UP;
}
break;
case SDLK_DOWN:
if (dir!=UP){
yVel = 20;
xVel = 0;
dir = DOWN;
}
break;
case SDLK_LEFT:
if (dir!=RIGHT){
xVel = -20;
yVel = 0;
dir=LEFT;
}
break;
case SDLK_RIGHT:
if (dir!=LEFT){
xVel = 20;
yVel = 0;
dir=RIGHT;
}
break;
}
}
void CSnake::movement(){
if (t_MoveTime <= (SDL_GetTicks()-t_SnakeStarted)){
SDL_Rect front;
iSnake = snake.begin();
front.x = (*iSnake).x + xVel;
front.y = (*iSnake).y + yVel;
snake.push_front(front);
snake.pop_back();
t_SnakeStarted = SDL_GetTicks();
}
}