I am creating a game of Pong in Pygame with Python (obviously) and am new to Pygame so would like some help working the physics of when the ball touches the paddle, it will reve
For the collision use the code below but change the variables
If paddle1.colliderect(paddle2) or paddle2.colliderect(paddle1): That is the ball direction in the x-axis ballDirectionX*=-1
The code that you have is probably a little excessive. Let's go with something a bit more simple. Within your draw
functions (on both Ball
& Paddle
), go ahead and make the start of your lines look like this:
self.rect = pygame.draw.rect...
Then you can use the colliderect function:
if ball.rect.colliderect(paddle1):
# Reverse, reverse!