0
import pygame
dx = 3
dy = 4
x = 100
y = 100
radius = 20
pygame.init()
clock = pygame.time.Clock()
display = pygame.display.set_mode((500, 300), pygame.SRCALPHA, 32)
while True:
    clock.tick(30)
    for event in pygame.event.get():
            mouseX = event.pos(0)
            mouseY = event.pos(1)
        if event.type == pygame.MOUSEBUTTONDOWN:
        if distance((mouseX, mouseY), (x,y)) <= radius:
            dx = dx+sign(dx)
            dy = dy+sign(dy)
            score = score + 1
        else:
            exit()
    t = font.render ("Score: "+str(score), 1, (255,255,255))
    display.blit (t, (20,20))

    display.fill((100, 100, 100))
    x = x + dx
    y = y + dy
    pygame.draw.circle (display, (200,200,200), (x,y), radius)
    if (x< radius or x>500- radius):
        dx = -dx
    if (y< radius) or (y>300- radius):
        dy = -dy


    pygame.display.update()```




it keeps showing up this error:``` File "d:\Code\Jet Boat.py", line 18 if event.type == pygame.MOUSEBUTTONDOWN: ^ IndentationError: unindent does not match any outer indentation level What am I doing wrong here? Can someone explain? where am i supposed to intend? And what does intend mean? or am i supposed to remove the if from if event.type == pygame.MOUSEBUTTONDOWN: ?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • "indent" != "intend". Whether or not you should remove `if event.type == pygame.MOUSEBUTTONDOWN:` is something we cannot tell, depends on what you are trying to achieve but if you leave it in there the next 4 or 6 lines need to be indented one more level. – luk2302 May 04 '22 at 06:53

2 Answers2

1

The IndentationError refers to the spacing between your codes.

It looks like the issue is here:

if event.type == pygame.MOUSEBUTTONDOWN:
    # this line onwards should be indented further
    if distance((mouseX, mouseY), (x,y)) <= radius: 
        dx = dx+sign(dx)
        dy = dy+sign(dy)
        score = score + 1
    else:
        exit()
greco
  • 304
  • 4
  • 11
1

Time to fix your indentation pal. mouseX = event.pos(0) and mouseY = event.pos(1) are indented one tab too much and

if distance((mouseX, mouseY), (x,y)) <= radius:
    dx = dx+sign(dx)
    dy = dy+sign(dy)
    score = score + 1
else:
    exit()

is one tab short.

AceKiron
  • 56
  • 11