From f5a6d69357398c5f0c6121a523e2e6f9acb51fca Mon Sep 17 00:00:00 2001 From: Tim Curry Date: Wed, 21 Feb 2024 15:59:25 -0500 Subject: [PATCH] created PongBall class --- pong.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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