Why does my code keep crashing when trying to setup my collide system?

So I'm making a small game with painter for a school final and I got to where my collision part and for some reason, it just crashes. Also, I'm using visual studio code. I was also wondering if there was a way to condense most of this code. I feel as though I am doing it the longest way possible. Any help would be appreciated, thanks!

import turtle as trtl

#tutle config
wn = trtl.Screen()
field = trtl.Turtle()
line = trtl.Turtle()

#feild setup
area = 0
line.speed(0)
yard = 0


#make field border
field.shape("square")
field.color("green")
field.shapesize(100)

#line setup
line.hideturtle()
line.color("white")
line.pensize(10)
line.penup()
line.goto(-700,-310)
line.pendown()
while(yard != 10):
    line.left(90)
    line.forward(620)
    line.penup()
    line.right(90)
    line.forward(70)
    line.pendown()
    line.right(90)
    line.forward(620)
    line.left(90)
    line.penup()
    line.forward(70)
    line.pendown()
    yard += 1
line.left(90)
line.forward(620)


#make sideline   
line.penup()
line.goto(-800,-310)
line.pendown()
line.right(90)
line.forward(1600)
line.left(90)
line.forward(620)
line.left(90)
line.forward(1600)
line.left(90)
line.forward(620)

#make endzone
line.fillcolor("black")
line.begin_fill()
line.left(90)
line.forward(90)
line.left(90)
line.forward(620)
line.left(90)
line.forward(90)
line.left(90)
line.forward(620)
line.end_fill()
line.penup()
line.goto(710,-310)
line.pendown()
line.begin_fill()
line.left(90)
line.forward(90)
line.left(90)
line.forward(620)
line.left(90)
line.forward(90)
line.left(90)
line.forward(620)
line.end_fill()

#game setup

#turtle config
player = trtl.Turtle()

#player setup
player.penup()
player.shape("circle")
player.color("gold")
player.goto(710,0)

#make player controls
def move_left():
    player.setheading(180)
    player.forward(2)
    wn.delay(1)
def move_right():
    player.setheading(0)
    player.forward(2)
    wn.delay(1)
def move_up():
    player.setheading(90)
    player.forward(2)
    wn.delay(1)
def move_down():
    player.setheading(270)    
    player.forward(2)
    wn.delay(1)







#setup enemy

enemy_1 = trtl.Turtle()
enemy_2 = trtl.Turtle()
enemy_3 = trtl.Turtle()
enemy_4 = trtl.Turtle()
enemy_5 = trtl.Turtle()
enemy_6 = trtl.Turtle()



enemy_1.penup()
enemy_1.shape("circle")
enemy_1.color("red")
enemy_1.goto(0,0)

enemy_2.penup()
enemy_2.shape("circle")
enemy_2.color("red")
enemy_2.goto(210,0)

enemy_6.penup()
enemy_6.shape("circle")
enemy_6.color("red")
enemy_6.goto(420,0)

enemy_3.penup()
enemy_3.shape("circle")
enemy_3.color("red")
enemy_3.goto(-210,0)

enemy_4.penup()
enemy_4.shape("circle")
enemy_4.color("red")
enemy_4.goto(-420,0)

enemy_5.penup()
enemy_5.shape("circle")
enemy_5.color("red")
enemy_5.goto(-630,0)


#stop
def stop():
    wn.bye()

#collide
def is_collided_with1(a, b):
    return abs(a.xcor() - b.xcor()) < 10 and abs(a.ycor() - b.ycor()) < 10
def is_collided_with2(a, b):
    return abs(a.xcor() - b.xcor()) < 10 and abs(a.ycor() - b.ycor()) < 10
def is_collided_with3(a, b):
    return abs(a.xcor() - b.xcor()) < 10 and abs(a.ycor() - b.ycor()) < 10
def is_collided_with4(a, b):
    return abs(a.xcor() - b.xcor()) < 10 and abs(a.ycor() - b.ycor()) < 10
def is_collided_with5(a, b):
    return abs(a.xcor() - b.xcor()) < 10 and abs(a.ycor() - b.ycor()) < 10
def is_collided_with6(a, b):
    return abs(a.xcor() - b.xcor()) < 10 and abs(a.ycor() - b.ycor()) < 10



#follow
def follow_1():
    enemy_1.setheading(enemy_1.towards(player))
    enemy_1.forward(2)
    if is_collided_with1(enemy_1, player):
        stop()
    else:
        wn.ontimer(follow_1, 10)

def follow_2():
    enemy_2.setheading(enemy_2.towards(player))
    enemy_2.forward(2)
    wn.ontimer(follow_2, 10)
    if is_collided_with2(enemy_2, player):
        stop()
    else:
        wn.ontimer(follow_2, 10)

def follow_3():
    enemy_3.setheading(enemy_3.towards(player))
    enemy_3.forward(2)
    wn.ontimer(follow_3, 10)
    if is_collided_with3(enemy_3, player):
        stop()
    else:
        wn.ontimer(follow_3, 10)

def follow_4():
    enemy_4.setheading(enemy_4.towards(player))
    enemy_4.forward(2)
    wn.ontimer(follow_4, 10)
    if is_collided_with4(enemy_4, player):
        stop()
    else:
        wn.ontimer(follow_4, 10)

def follow_5():
    enemy_5.setheading(enemy_5.towards(player))
    enemy_5.forward(2)
    wn.ontimer(follow_5, 10)
    if is_collided_with5(enemy_5, player):
        stop()
    else:
        wn.ontimer(follow_5, 10)

def follow_6():
    enemy_6.setheading(enemy_6.towards(player))
    enemy_6.forward(2)
    wn.ontimer(follow_6, 10)
    if is_collided_with6(enemy_6, player):
        stop()
    else:
        wn.ontimer(follow_6, 10)








#setup out of bounds







 

#mainloop

wn.onkeypress(move_left,"Left")
wn.onkeypress(move_down,"Down")
wn.onkeypress(move_right,"Right")
wn.onkeypress(move_up,"Up")

wn.listen()

follow_1()
follow_2()
follow_3()
follow_4()
follow_5()
follow_6()



wn.mainloop()


Read more here: https://stackoverflow.com/questions/65727062/why-does-my-code-keep-crashing-when-trying-to-setup-my-collide-system

Content Attribution

This content was originally published by CrazyG36 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: