Python turtle collision detection


  • Can you help me make a collision detection for Python turtle where it will say game over when the yellow circle hits the green pipe

    import turtle
    import random
    import datetime
    
    # this will set the current time to now
    current_time = datetime.datetime.now()
    score_time = datetime.datetime.now()
    
    panel = turtle.Screen()
    panel.bgcolor("light blue")
    panel.title("𝙵𝚕𝚊𝚙𝚙𝚢 𝙲𝚒𝚛𝚌𝚕𝚎")
    panel.setup(width=1080, height=720)
    panel.tracer(0)
    
    human = turtle.Turtle()
    human.color("yellow")
    human.shape("circle")
    human.penup()
    human.goto(0, 0)
    human.shapesize(5, 5)
    speed = 0
    score = 0
    
    display = turtle.Turtle()
    display.write(str(score), align='center', font=("Fixedsys", 40))
    display.penup()
    display.goto(0, 200)
    pipes = []
    
    def create_pipes():
    
       x = 550
       y = random.randint(300, 500)
       pipe_up = turtle.Turtle()
       pipe_up.shape("square")
       pipe_up.color("green")
       pipe_up.shapesize(20, 3)
       pipe_up.penup()
       pipe_up.goto(x, y)
       #pipe_up.setheading(human.heading() - 180)
       pipes.append(pipe_up)
       y = random.randint(-330, -200)
       pipe_down = turtle.Turtle()
       pipe_down.shape("square")
       pipe_down.color("green")
       pipe_down.shapesize(20, 3)
       pipe_down.penup()
       pipe_down.goto(x, y)
       #pipe_down.setheading(human.heading() - 180)
       pipes.append(pipe_down)
    
    
    def fly():
     global speed
     speed = -1
    
    
    panel.listen()
    panel.onkeypress(fly, "space")
    
    
    # forever
    while True:
    
       # if passed 2 seconds
       if (datetime.datetime.now() - current_time).total_seconds() > 2:
           # do something
           create_pipes()
           # update current_time to now
           current_time = datetime.datetime.now()
    
           if pipes[0].xcor() < 0:
               score+=1
           display.clear()
           display.write(str(score), align='center', font=("Fixedsys", 40))
           display.penup()
    
    
       for i in pipes:
           i.setx(i.xcor() - 1)
    
       panel.update()
       speed += 0.0035
       human.setheading(-90)
       human.forward(speed)
    
    
       if human.xcor() > 500:
           human.setx(500)
       if human.xcor() < -500:
           human.setx(-500)
    
       if human.ycor() > 330:
           human.sety(330)
       if human.ycor() < -330:
           human.sety(-330)