import pygamepygame.init()win = pygame.display.set_mode((750, 500))pygame.display.set_caption('Title')run = Truewhile run: for event in pygame.event.get(): if event.type == pygame.QUIT: run = False pygame.quit()import pygamepygame.init()win = pygame.display.set_mode((750, 500))pygame.display.set_caption('Pong')white = (255, 255, 255)black = (0, 0, 0)class Paddle(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface([10, 75]) self.image.fill(white) self.rect = self.image.get_rect() self.points = 0 class Ball(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface([10, 10]) self.image.fill(white) self.rect = self.image.get_rect() paddle1 = Paddle()paddle2 = Paddle()ball = Ball()paddle1.rect.x = 25paddle1.rect.y = 250paddle2.rect.x = 715paddle2.rect.y = 250ball.rect.x = 375ball.rect.y = 250all_sprites = pygame.sprite.Group()all_sprites.add(paddle1, paddle2, ball)def redraw(): win.fill(black) all_sprites.draw(win) pygame.display.update()run = Truewhile run: pygame.time.delay(100) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False redraw()pygame.quit()import pygamepygame.init()win = pygame.display.set_mode((750, 500))pygame.display.set_caption('Pong')white = (255, 255, 255)black = (0, 0, 0)class Paddle(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface([10, 75]) self.image.fill(white) self.rect = self.image.get_rect() self.points = 0class Ball(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface([10, 10]) self.image.fill(white) self.rect = self.image.get_rect() self.dirx = 1 self.diry = 1paddle1 = Paddle()paddle2 = Paddle()ball = Ball()paddle1.rect.x = 25paddle1.rect.y = 250paddle2.rect.x = 715paddle2.rect.y = 250ball.rect.x = 375ball.rect.y = 250all_sprites = pygame.sprite.Group()all_sprites.add(paddle1, paddle2, ball)def redraw(): win.fill(black) all_sprites.draw(win) pygame.display.update()run = Truewhile run: pygame.time.delay(100) for event in pygame.event.get(): if event.type == pygame.QUIT: run = False key = pygame.key.get_pressed() if key[pygame.K_w]: paddle1.rect.y += -10 if key[pygame.K_s]: paddle1.rect.y += 10 if key[pygame.K_UP]: paddle2.rect.y += -10 if key[pygame.K_DOWN]: paddle2.rect.y += 10 ball.rect.x += 10 * ball.dirx ball.rect.y += 10 * ball.diry if ball.rect.x < 10: ball.dirx = 1 if ball.rect.x > 740: ball.dirx = -1 if ball.rect.y < 10 : ball.diry = 1 if ball.rect.y > 490 : ball.diry = -1 redraw()pygame.quit()# Imports and initsimport pygamepygame.init()# Window setupwin = pygame.display.set_mode((750, 500))pygame.display.set_caption('Pong')# Colorswhite = (255, 255, 255)black = (0, 0, 0)# Sprite Classesclass Paddle1(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface([10, 75]) self.image.fill(white) self.rect = self.image.get_rect() self.points = 0class Paddle2(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface([10, 75]) self.image.fill(white) self.rect = self.image.get_rect() self.points = 0class Ball(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface([10, 10]) self.image.fill(white) self.rect = self.image.get_rect() self.speed = 10 self.dx = 1 self.dy = 1# Sprite Creationpaddle1 = Paddle1()paddle1.rect.x = 25paddle1.rect.y = 225paddle2 = Paddle2()paddle2.rect.x = 715paddle2.rect.y = 225paddle_speed = 10pong = Ball()pong.rect.x = 375pong.rect.y = 250# Group of Spritesall_sprites = pygame.sprite.Group()all_sprites.add(paddle1, paddle2, pong)# Screen update functiondef redraw(): # Draws black screen win.fill(black) # Title font font = pygame.font.SysFont('Comic Sans MS', 30) text = font.render('PONG', False, white) textRect = text.get_rect() textRect.center = (750 // 2, 25) win.blit(text, textRect) # Player 1 Score p1_score = font.render(str(paddle1.points), False, white) p1Rect = p1_score.get_rect() p1Rect.center = (50, 50) win.blit(p1_score, p1Rect) # Player 2 Score p2_score = font.render(str(paddle2.points), False, white) p2Rect = p2_score.get_rect() p2Rect.center = (700, 50) win.blit(p2_score, p2Rect) # Updates all Sprites all_sprites.draw(win) # Draws updates pygame.display.update()run = True# Main Loopwhile run: pygame.time.delay(100) # Quit Event for event in pygame.event.get(): if event.type == pygame.QUIT: run = False # Paddle Movement key = pygame.key.get_pressed() if key[pygame.K_w]: paddle1.rect.y += -paddle_speed if key[pygame.K_s]: paddle1.rect.y += paddle_speed if key[pygame.K_UP]: paddle2.rect.y += -paddle_speed if key[pygame.K_DOWN]: paddle2.rect.y += paddle_speed # Moves pong ball pong.rect.x += pong.speed * pong.dx pong.rect.y += pong.speed * pong.dy # Wall and Paddle Bounces if pong.rect.y > 490: pong.dy = -1 if pong.rect.y < 1: pong.dy = 1 if pong.rect.x > 740: pong.rect.x, pong.rect.y = 375, 250 pong.dx = -1 paddle1.points += 1 if pong.rect.x < 1: pong.rect.x, pong.rect.y = 375, 250 pong.dx = 1 paddle2.points += 1 if paddle1.rect.colliderect(pong.rect): pong.dx = 1 if paddle2.rect.colliderect(pong.rect): pong.dx = -1 # Runs redraw function above redraw()pygame.quit()