I'm starting in this pygame and I get this error in main ()
missing 1 required positional argument: 'self'
import pygame
import random
r1=pygame.Rect(0,0,0,0)
pygame.init()
class Recs(object):
def __init__(self,numeroinicia):
self.lista=[]
for x in range(numeroinicia):
#creo un rect random
leftrandom=random.randrange(2,560)
toprandom=random.randrange(-580,-10)
width=random.randrange(10,30)
height=random.randrange(15,30)
self.lista.append(pygame.Rect(leftrandom,toprandom,width,height))
def reagrear(self):
for x in range(len(self.lista)):
if self.lista[x].top>482:
leftrandom=random.randrange(2,560)
toprandom=random.randrange(-580,-10)
width=random.randrange(10,30)
height=random.randrange(15,30)
self.lista[x]=(pygame.Rect(leftrandom,toprandom,width,height))
def agregarotro(self):
pass
def mover(self):
for rectangulo in self.lista:
rectangulo.move_ip(0,2)
def pintar(self,superficie):
for rectangulo in self.lista:
pygame.draw.rect(superficie,(200,0,0),rectangulo)
#color de los cuadros
class Player(pygame.sprite.Sprite):
def __init__(self,imagen):
self.imagen=imagen
self.rect=self.imagen.get_rect()
self.rect.top,self.rect.left=(100,200)
def mover(self,vx,vy):
self.rect.move_ip(vx,vy)
if self.rect.left<0:
vx=-vx
self.rect.move_ip(vx,vy)
def update(self,superficie):
superficie.blit(self.imagen,self.rect)
def colision(player,recs):
for rec in recs.lista:
if player.rect.colliderect(rec):
return True
return False
def main(self):
import pygame
pygame.init()
pantalla=pygame.display.set_mode((600,480))
salir=False
reloj1= pygame.time.Clock()
imagen1=pygame.image.load("imagen2.png").convert_alpha()
imagenexplosion=pygame.image.load("explosion.png").convert_alpha()
imagenfondo=pygame.image.load("fondo.png").convert_alpha()
#pygame.mixer.music.load("music.mp3")
sonido1=pygame.mixer.Sound("sonido.wav")
recs1=Recs(25)
player1=Player(imagen1)
#variables aux
player1=Player(imagen1)
vx,vy=0,0
velocidad=10
leftsigueapretada,rightsigueapretada,upsigueapretada,downsigueapretada=False,False,False,False
colisiono=False
#pygame.mixer.music.play(2
while salir!=True:#LOOP PRINCIPAL
for event in pygame.event.get():
if event.type == pygame.QUIT:
salir=True
reloj1.tick(20)
if colision(player1,recs1):
colisiono=True
player1.imagen=imagenexplosion
pygame.mixer.music.stop()
#pongo la explocion
if colisiono==False:
recs1.mover()
player1.mover(vx, vy)
def __init__(self, lista):
self.lista =lista
def darlista(self):
return self.lista
def mover(self):
for Recs in self.lista:
Recs.move_ip(50,50)
#tamaño de los cuadros
if event.type==pygame.MOUSEBUTTONDOWN:
for recs in self.lista:
if r1.colliderect(recs):
sonido1.play()
recs.width=0
recs.height=0
(r1.left,r1.top)=pygame.mouse.get_pos()
#posision del roton en el cuadro
r1.left-=r1.width/2
r1.top-=r1.height/2
pantalla.fill((0,0,0))
pantalla.blit(imagenfondo,(0,0))
for recs in self.lista:
pantalla.blit(imagen1,(300,300))
pygame.draw.rect(pantalla,(0,200,0),recs)
pygame.draw.rect(pantalla,(10,10,10),r1)
pantalla.blit(info,(5,5))
pygame.quit()
main()