I have created a pong game in Pygame.
I have done the basic collision between the ball and the bat/racket.
The collision is not perfect because sometimes if the ball hit the top/bottom edge of the bat/racket, the ball goes inside the racket/bat.
The collision is between two rect.
The code for collision is:
if self.player.rect.colliderect(self.ball.rect):
self._ball_hit()
if self.player_1.rect.colliderect(self.ball.rect):
self._ball_hit()
Basically the "self._ball_hit()"
Changes the ball direction
I have tried giving a specific position i.e. topright to the bat/racket but I get this error:
if self.player.rect.toprigth.colliderect(self.ball.rect.left):
AttributeError: 'tuple' object has no attribute 'colliderect'
Is there another way to approach the collision?
If there is more information you want to ask please comment.