diff --git a/pong.py b/pong.py index a58051a..f9a609a 100644 --- a/pong.py +++ b/pong.py @@ -6,6 +6,16 @@ import pygame, sys, random +class PongBall(pygame.Rect): + def __init__(self, left, top, height, width): + super().__init__(left, top, height, width) + + def set_center(self, x, y): + self.center = (x, y) + + + + def reset_ball(): global ball_speed_x, ball_speed_y ball.x = screen_width/2 - 10 @@ -73,8 +83,8 @@ def animate_cpu(): clock = pygame.time.Clock() -ball = pygame.Rect(0,0,30,30) -ball.center = (screen_width/2, screen_height/2) +ball = PongBall(0, 0, 30, 30) +ball.set_center(screen_width/2, screen_height/2) cpu = pygame.Rect(0,0,20,100) cpu.centery = screen_height/2