Im making a game where you try to catch falling bread, and every time you catch one it gets harder i.e they fall faster. The problem is that when I run the code this error message shows up: UnboundLocalError: local variable 'speed' referenced before assignment
My code:
from random import randint
import pgzero
import pgzrun
bread = Actor("bread")
bg = Actor("bg")
WIDTH = 1200
HEIGHT = 711
sounds.music.play(-1)
speed = 1
def draw():
screen.clear()
bg.draw()
bread.draw()
def place_bread():
bread.x = randint(10, 1000)
bread.y = 70
def update():
bread.y += speed
def on_mouse_down(pos):
if bread.collidepoint(pos):
print("Good Shot")
place_bread()
speed += 1
else:
print("You Missed")
quit()
pgzrun.go()