Notice: New to this site, not so new to StackOverflow though, assuming this is pretty much the same.
Anyhow, I am working on a game (code at end) and I want to make a counter for the number of balls left in the bottom left. is there an easy way to do so?
i've tried to just print the variable that i assigned the counter's information to, but that printed to console. Also, i tried to make a pattern of rectangles that looked like the numbers, but that was too slow.
.
.
my current game code (without counter or blocks yet)
import pygame
# Constants
WIDTH = 700
HEIGHT = 500
SCREEN_AREA = pygame.Rect(0, 0, WIDTH, HEIGHT)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
# Initialization
pygame.init()
screen = pygame.display.set_mode([WIDTH, HEIGHT])
pygame.mouse.set_visible(0)
pygame.display.set_caption("Breakout Recreation WIP")
clock = pygame.time.Clock()
# Variables
paddle = pygame.Rect(350, 480, 50, 10)
ball = pygame.Rect(10, 250, 15, 15)
paddle_movement_x = 0
ball_direction = (1, 1)
balls = 3
done = False
while not done and balls > 0:
# Process events
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
paddle_movement_x = -2
elif keys[pygame.K_RIGHT]:
paddle_movement_x = 2
else:
paddle_movement_x = 0
# Move paddle
paddle.move_ip(paddle_movement_x, 0)
paddle.clamp_ip(SCREEN_AREA)
# Move ball
ball.move_ip(*ball_direction)
if ball.right > WIDTH or ball.left < 0:
ball_direction = -ball_direction[0], ball_direction[1]
elif ball.top < 0 or paddle.colliderect(ball):
ball_direction = ball_direction[0], -ball_direction[1]
elif ball.bottom > HEIGHT:
balls = balls - 1
ball_direction = (1, 1)
ball = pygame.Rect(10, 250, 15, 15)
ball.clamp_ip(SCREEN_AREA)
# Redraw screen
screen.fill(BLACK)
pygame.draw.rect(screen, WHITE, paddle)
pygame.draw.rect(screen, WHITE, ball)
pygame.display.flip()
clock.tick(100)
pygame.quit()