Nose si estara del todo bien echo pero lo q tengo hecho asta ahora nose me ve en pantalla

Algun consejo o alguna forma de hacerlo?
Dentro de la clase bola esta la funcion marcador, pero en la forma de hacerlo creo q habre cometido algun error, alguien sabe decirme cual? Si eso resulta facil me podriais decir como actualizarlo para q la partida acabase cuando alguno marcara 5 goles
Cn el codigo de ahora me dice q marcador no tiene atributo en bola, y nose el porque.
- Código: Seleccionar todo
import pygame, sys
from pygame.sprite import Sprite
from pygame.locals import *
width = 640
height = 300
class Bola(Sprite):
def __init__(self, x, y, radio, color=(0, 255, 0)):
Sprite.__init__(self)
self.x, self.y = x, y
self.radio = radio
self.crear_imagen(radio, color)
self.rect = self.image.get_rect(self.image)
self.mover(0, 0)
def crear_imagen(self, radio, color):
ancho = alto = radio * 2
self.image = pygame.Surface((ancho, alto)).convert()
self.image.set_colorkey((0, 0, 0))
pygame.draw.circle(self.image, color, (radio, radio), radio)
def update(self):
self.x += self.dx
self.y += self.dy
self.rect.center = (self.x, self.y)
self.verificar_limites()
self.reinici()
self.marcador('0', '0')
def reinici(self):
if self.x < -100:
self.x = 320
self.dx = -1
self.dy = -0.7
if self.x > width + 100:
self.x = 320
self.dx = 1
self.dy = 0.7
def verificar_limites(self):
if self.rect.top < 0:
self.rect.top = 0
self.y = self.radio
self.dy *= -0.75
elif self.rect.bottom > height:
self.rect.bottom = height
self.y = height - self.radio
self.dy *= -0.75
def mover(self, dx, dy):
self.dx = dx
self.dy = dy
def marcador(self, puntos_p1, puntos_p2):
lletra = pygame.font.SysFont("Papyrus",50)
m1 = lletra.render(puntos_p1,True,(0,255,255))
m2 = lletra.render(puntos_p2,True,(255,255,255))
self.blit(m1, (20, 20))
self.blit(m2, (600, 0))
class Porteria(Sprite):
def __init__(self, x, y, ancho, alto, dy, color=(255, 0, 255)):
Sprite.__init__(self)
self.image = self.crear_imagen(ancho, alto, color)
self.rect = self.image.get_rect(self.image)
self.rect.center = (x, y)
self.dy = dy
def crear_imagen(self, ancho, alto, color):
image = pygame.Surface((ancho, alto)).convert()
image.fill(color)
return image
def update(self):
self.mover_y()
self.verificar_limites()
def verificar_limites(self):
if self.rect.top < 0:
self.rect.top = 0
elif self.rect.bottom > height:
self.rect.bottom = height
def mover_y(self):
teclas = pygame.key.get_pressed()
if teclas[K_w]:
self.rect.y -= self.dy
elif teclas[K_s]:
self.rect.y += self.dy
class Porteria2(Sprite):
def __init__(self, x, y, ancho, alto, dy, color=(255, 0, 255)):
Sprite.__init__(self)
self.image = self.crear_imagen(ancho, alto, color)
self.rect = self.image.get_rect(self.image)
self.rect.center = (x, y)
self.dy = dy
def crear_imagen(self, ancho, alto, color):
image = pygame.Surface((ancho, alto)).convert()
image.fill(color)
return image
def update(self):
self.mover_y()
self.verificar_limites()
def verificar_limites(self):
if self.rect.top < 0:
self.rect.top = 0
elif self.rect.bottom > height:
self.rect.bottom = height
def mover_y(self):
teclas = pygame.key.get_pressed()
if teclas[K_UP]:
self.rect.y -= self.dy
elif teclas[K_DOWN]:
self.rect.y += self.dy
def actualizar_pantalla(screen, bolas, porterias):
screen.fill((0, 0, 0))
bolas.draw(screen)
porterias.draw(screen)
pygame.display.flip()
def colisiona_con(bola, porteria):
if bola.rect.colliderect(porteria.rect):
return True
else:
return False
def informar_colisiones(bola, porteria):
for a in bola:
for b in porteria:
if colisiona_con(a,b):
colisionar_con(a,b)
break
def colisionar_con(bola, porteria):
if colisiona_con(bola, porteria):
bola.dx *= -1.05
bola.dy *= 1.001
def mainP():
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Pinbola")
bolas = pygame.sprite.Group()
porterias = pygame.sprite.Group()
b1 = Bola(x=320, y=100, radio=7)
b1.mover(-1, 0.7)
p1 = Porteria(x=20, y=140, ancho=10, dy=9, alto=60)
p2 = Porteria2 (x=620, y=140, ancho=10, dy=9, alto=60)
bolas.add([b1])
porterias.add([p1, p2])
clock = pygame.time.Clock()
while True:
for e in pygame.event.get():
if e.type == QUIT:
sys.exit(0)
elif e.type == KEYDOWN:
if e.key == K_ESCAPE:
sys.exit(0)
actualizar_pantalla(screen, bolas, porterias)
bolas.update()
porterias.update()
informar_colisiones(bolas, porterias)
if __name__ == '__main__':
mainP()