Error: __init__() takes 1 positional argument but 3 were given
Publicado por David (1 intervención) el 15/08/2018 03:08:35
Hola, estoy empezando con python y he comenzado un proyecto usando el modulo pygame. Todo funcionaba perfecto(El fondo cargaba y podia crear objetos de tipo nave y moverlos por los por la pantalla), pero cuando creé la clase proyectil me surgio este error:
¿Alguien sabria decirme que he hecho mal y como podria solucionarlo?
Dejo el código entero aqui por si hace falta.
Gracias
1
2
3
4
5
6
7
8
9
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "C:\Users\deivi\Desktop\Python\Pygame\Pygame.pyw", line 118, in <module>
main()
File "C:\Users\deivi\Desktop\Python\Pygame\Pygame.pyw", line 78, in main
demoLaser = PROYECTIL(ancho/2, alto-30)
TypeError: __init__() takes 1 positional argument but 3 were given
[Finished in 1.0s]
¿Alguien sabria decirme que he hecho mal y como podria solucionarlo?
Dejo el código entero aqui por si hace falta.
Gracias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import random, pygame, sys
from pygame.locals import *
RED = (255, 0, 0)
ancho = 271
alto = 119
class NAVE(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.ImageOVNI = pygame.image.load("Nave.png")
self.rect = self.ImageOVNI.get_rect()
self.rect.centerx = ancho/2
self.rect.centery = alto-30
self.ListaDisparos=[]
self.Vida = True
self.Vel = 5
def mov(self):
if self.Vida == True:
if self.rect.left <= 0:
self.rect.left = 0
elif self.rect.right > 800:
self.rect.right = 750
def Disparar(self):
print("piw piw")
def dibujar(self, superficie):
superficie.blit(self.ImageOVNI, self.rect)
class PROYECTIL(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self, posX, posY)
self.ImageLaser = pygame.image.load("ProyectilLaser.png")
self.rect = self.ImageLaser.get_rect()
self.Vel = 10
self.rect.top = posY
self.rect.left = posX
def mov(self):
self.rect.left = self.rect.left + self.Vel
def dibujar(self, superficie):
self.rect.x = self.x
self.rect.y = self.y
superficie.blit(self.ImageLaser, self.rect)
def main():
pygame.init()
pygame.display.set_caption("Bolita Bola")
screen = pygame.display.set_mode((1024,576))
jugador = NAVE()
demoLaser = PROYECTIL(ancho/2, alto-30)
enjuego = True
while True:
jugador.mov()
demoLaser.mov()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if enjuego == True and event.type == pygame.KEYDOWN:
if event.key == K_a:
jugador.rect.left -= jugador.Vel
elif event.key == K_d:
jugador.rect.right += jugador.Vel
elif event.key == K_SPACE:
jugador.Disparar()
FONDO = pygame.image.load("background.png")
screen.blit(FONDO, (0, 0))
demoLaser.dibujar(screen)
jugador.dibujar(screen)
pygame.display.update()
if __name__ == '__main__':
main()
Valora esta pregunta
0