Added a collide function to be able to click the targets
def collide(self, x, y):
'''creates the collisions with the mouse and the circle'''
dis = math.sqrt((x - self.x)**2 + (y - self.y)**2)
return dis <= self.size
Added ANOTHER draw function that updates the screen every frame so that the program doesn’t slow down
def draw(win, targets):
'''wipes the screen, draws the objects, and updates the display'''
win.fill(BG_COLOR)
for target in targets:
target.draw(win)
pygame.display.update()
additional code for collide in main
if event.type == TARGET_EVENT:
x = random.randint(TARGET_PADDING, WIDTH - TARGET_PADDING)
y = random.randint(TARGET_PADDING, HEIGHT - TARGET_PADDING)
target = Target(x, y)
targets.append(target)
if event.type == pygame.MOUSEBUTTONDOWN:
click = True
clicks += 1
for target in targets:
target.update()
if target.size <= 0:
targets.remove(target)
misses += 1
if click and target.collide(*mouse_pos):
targets.remove(target)
target_pressed += 1
if misses >= LIVES:
pass # end game