I do not seem able to improve the following code:
if(state[SDL_SCANCODE_M]){
if(_ball.velocity.x < 0)
_ball.velocity.x -= 20;
else
_ball.velocity.x += 20;
if(_ball.velocity.y < 0)
_ball.velocity.y -= 20;
else
_ball.velocity.y += 20;
}
if(state[SDL_SCANCODE_L]){
if(_ball.velocity.x < 0)
_ball.velocity.x += 20;
else
_ball.velocity.x -= 20;
if(_ball.velocity.y < 0)
_ball.velocity.y += 20;
else
_ball.velocity.y -= 20;
}
They are pretty similar, but the operations are the opposite.
Is there any best practice or technique that allows to improve these kind of situations?