I'm playing around with the Pong demo game. I've changed it so that the ball bounced back and fourth between the frame of the screen. Between 0 and screen_size.
The area where I'm puzzled is this
if (ballpos.x > screensize.x and direction.x > 0):
direction.x= -direction.x
The above works fine. and it seems that setting -direction.x will cause the ball to move left.
When I tried to add this code it didn't work at first.
if(ball_pos.x < 0 and direction.x<0):
direction.x= direction.x
Now my thinking was that by making direction.x a positive the ball would again change directions, but this didn't happen. I had to end up using -direction.x to get it to change direction.
Why is this? if the direction is already negative why does a negative need to be used to change it back? is there some math going on that I'm not seeing? where a negative * a negative is a positive maybe? This has me a little confused. I hope someone could clear it up for me.