I’m trying to code a simple game of pong as a way to learn pygame as i’m not that experienced in coding. I’ve only recently started to use classes and i guess i don’t quite understand how to use init properly As whenever i run the code:
JavaScript
x
25
25
1
class ball:
2
3
def __init__(self):
4
self.y = y
5
6
def draw_shape(self):
7
8
pygame.draw.circle(screen, WHITE,(30 , self.y),15)
9
pygame.display.flip()
10
11
12
while running:
13
clock.tick(fps)
14
15
for event in pygame.event.get():
16
if event.type == pygame.QUIT:
17
running = False
18
if event.type == KEYDOWN and (event.key == K_UP):
19
player.y = player.y + vel
20
screen.fill(BLACK)
21
visual.border_draw()
22
visual.mid_lines()
23
visual.score()
24
ball.draw_shape()
25
I got the following error message:
JavaScript
1
2
1
TypeError: draw_shape() missing 1 required positional argument: 'self'
2
Advertisement
Answer
try:
JavaScript
1
2
1
ball().draw_shape()
2
or just
JavaScript
1
3
1
player = ball()
2
player.draw_shape()
3