Just create a new Surface
and fill it with the right color:
class raquete(pygame.sprite.Sprite):
def __init__(self, x, y, l_raquete, a_raquete):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface((l_raquete, a_raquete))
# I guess branco means color
self.image.fill(branco)
# no need for the x and y members,
# since we store the position in self.rect already
self.rect = self.image.get_rect(x=x, y=y)
Since you're already using the Sprite
class, what's the point of the imprime
function anyway? Just use a pygame.sprite.Group
to draw your sprites to the screen. That said, the rect
member of a Sprite
is used for positioning, so you can simplify your bola
class to:
class bola(pygame.sprite.Sprite):
def __init__(self, x, y, imagem_bola):
pygame.sprite.Sprite.__init__(self)
# always call convert() on loaded images
# so the surface will have the right pixel format
self.image = pygame.image.load(imagem_bola).convert()
self.rect = self.image.get_rect(x=x, y=y)