I'm trying to make a kind of a Brick Breaker and got a problem with the transparency of the rectangle that surrounds the ball. every time it hits something you can see the rectangle. any suggestions?it also forces me to use a white background there is an image of the problem
import pygame
pygame.init()
bg_color = (255,255,255)
width, height = 600, 400
dx, dy = 2, 2
screen = pygame.display.set_mode((width, height))
screen.fill(bg_color)
ball = pygame.image.load("medicine-ball.png").convert()
ball = pygame.transform.scale(ball, (50, 50))
ball_rect = ball.get_rect()
ball_color = False
def rect(x1,y1,x2,y2):
pygame.draw.rect(screen, (0,0,0), (x1,y1,x2,y2))
game_loop = True
while game_loop:
event = pygame.event.poll()
if event.type == pygame.QUIT:
game_loop = False
ball_rect = ball_rect.move(dx,dy)
if ball_rect.left < 0 or ball_rect.right > width:
dx *= -1
if ball_rect.top < 0 or ball_rect.bottom > height:
dy *= -1
mouse_pos = list(pygame.mouse.get_pos())
rect(mouse_pos[0]-40,300-10,80,20)
if ball_rect.bottom == 300 and ball_rect.x > mouse_pos[0]-89 and ball_rect.x < mouse_pos[0]+129:
dy *= -1
screen.blit(ball, ball_rect)
pygame.time.wait(1)
pygame.display.flip()
screen.fill(bg_color)
another thing that is bothering me is that I can't change the speed of the ball, I am pretty sure it is a problem in my mac because it works on my friend's pc(it's about the pygame.time.wait())