Game
Game
import sys
# Initialize Pygame
pygame.init()
# Constants
WIDTH, HEIGHT = 800, 600
PADDLE_WIDTH, PADDLE_HEIGHT = 15, 100
BALL_RADIUS = 10
PADDLE_SPEED = 10
FPS = 60
# Game objects
player1_paddle = pygame.Rect(50, HEIGHT // 2 - PADDLE_HEIGHT // 2, PADDLE_WIDTH,
PADDLE_HEIGHT)
player2_paddle = pygame.Rect(WIDTH - 50 - PADDLE_WIDTH, HEIGHT // 2 - PADDLE_HEIGHT
// 2, PADDLE_WIDTH, PADDLE_HEIGHT)
ball = pygame.Rect(WIDTH // 2 - BALL_RADIUS, HEIGHT // 2 - BALL_RADIUS, BALL_RADIUS
* 2, BALL_RADIUS * 2)
# Scores
score_player1 = 0
score_player2 = 0
# Fullscreen flag
fullscreen = False
ball.x += ball_velocity_x
ball.y += ball_velocity_y
# Draw paddles
pygame.draw.rect(screen, WHITE, player1_paddle)
pygame.draw.rect(screen, WHITE, player2_paddle)
# Draw ball
pygame.draw.ellipse(screen, WHITE, ball)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
# Handle movement
move_paddles()
move_ball()
# Draw everything
draw()