BrotatoBoi2point0 / Pong

My recreation of the classic game Pong!
0 stars 0 forks source link

Simplification of Code!! and BUG - top and bottom of paddle bouncing #1

Open Ashutosh2012 opened 7 months ago

Ashutosh2012 commented 7 months ago

Hello @BrotatoBoi2point0 ,

Just for simplification of code can't we just separate all of the classes into separate modules?!


For BUG:-

def ball_movement(self, player, opponent, pong_sound):
    # Moving the ball
    self.ball.x += self.speed_x
    self.ball.y += self.speed_y

    # Collision detection and appropriate movement also sounds
    # Collision detection of sides
    if self.ball.top <= 0 or self.ball.bottom >= self.H:
        pygame.mixer.Sound.play(pong_sound)
        self.speed_y *= -1
    if self.ball.left <= 0 or self.ball.right >= self.W:
        pygame.mixer.Sound.play(pong_sound)
        self.speed_x *= -1

    # Collision detection of rects
    if self.ball.colliderect(player) or self.ball.colliderect(opponent):
        pygame.mixer.Sound.play(pong_sound)
        self.speed_x *= -1

Please change the variables accordingly

THANKS!!!!

BrotatoBoi2point0 commented 5 months ago

Yes, I am planning on making it a little more "modular" so it is a little more readable, At the moment I am focusing on more important projects. Thank you for the advice, I will consider including it whenever I get the time to come back to this side-project.

P.S. I also want to thank you for taking the time to assist with one of my projects :)