Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
created PongBall class
  • Loading branch information
Tim Curry committed Feb 21, 2024
1 parent 0d97843 commit f5a6d69
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pong.py
Expand Up @@ -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
Expand Down Expand Up @@ -73,8 +83,8 @@ pygame.display.set_caption("My Pong Game!")

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
Expand Down

0 comments on commit f5a6d69

Please sign in to comment.