I'm making a recreation of Pong, and I'm trying to add a text that displays the score.
I have tried so many ways to add a text, but they never worked. I just need someone to help me and teach me what I probably did wrong.
This is my code:
# Set up the display surface
DISPLAYSURF = pygame.display.set_mode((500, 400))
# Set up the clock
fpsClock = pygame.time.Clock()
# Set up the colors
BLACK = pygame.Color(0, 0, 0)
WHITE = pygame.Color(255, 255, 255)
BLU = pygame.Color(0,0,255)
RED = pygame.Color(255,0,0)
#!!!ADD TEXT SCORE HERE!!!
while True:
# Handle events
for event in pygame.event.get():
if event.type == pygame.locals.QUIT:
pygame.quit()
sys.exit()
# Check for ball scoring
if ball_x - ball_radius < 0:
paddle2_score += 1
ball_x = 250
ball_y = 200
ball_dx = 3
print("Red: ",paddle2_score)
elif ball_x + ball_radius > 500:
paddle1_score += 1
ball_x = 250
ball_y = 200
ball_dx = -3
print("Blu: ",paddle1_score)
#!!!UPDATE TEXT SCORE HERE!!!
# Keep the paddles on the screen
if paddle1_y < 0:
paddle1_y = 0
elif paddle1_y + paddle1_h > 400:
paddle1_y = 400 - paddle1_h
if paddle2_y < 0:
paddle2_y = 0
elif paddle2_y + paddle2_h > 400:
paddle2_y = 400 - paddle2_h
# Update the display
pygame.display.flip()
# Control the frame rate
fpsClock.tick(30)
This is only part of the code.