So I'm making a 2 player tron game in turtle, and my code seemed to be working fine (except the border that's why I commented it out). The only thing is that when I tried to play the game by myself to test it out, whenever I moved the "other" tron bike, the one that I just had clicked to make move stops moving. How can I fix this?
Here is my code:
def tron():
#Drawing the starting turtles
blueplayer = turtle.Turtle()
redplayer = turtle.Turtle()
screen = turtle.Screen()
screen.setup(width, height)
screen.bgpic('TronBg.png')
screen.bgcolor('black')
screen.addshape('BlueBike.gif')
screen.addshape('RedBike.gif')
blueplayer.shape('BlueBike.gif')
redplayer.shape('RedBike.gif')
redplayer.pencolor("red")
redplayer.pensize(3)
blueplayer.pencolor("blue")
blueplayer.pensize(3)
redplayer.pu()
blueplayer.pu()
redplayer.goto(width/2, height/8)
blueplayer.goto(-1*(width)/2, height/8)
redplayer.pd()
blueplayer.pd()
#Border
#box = Turtle()
#box.ht()
#box.color('purple')
#box.speed('fastest')
#box.pensize(10)
# box.pu()
# box.goto(-1*height, -1*width)
# box.pd()
# for i in range(4):
# box.forward(height)
# box.left(90)
# box.forward(width)
# box.left(90)
#Player movements
def RedUp():
while True:
blueplayer.setheading(90)
blueplayer.forward(3)
def BlueUp():
while True:
redplayer.setheading(90)
redplayer.forward(3)
def RedDown():
while True:
blueplayer.setheading(270)
blueplayer.forward(3)
def BlueDown():
while True:
redplayer.setheading(270)
redplayer.forward(3)
def RedLeft():
while True:
blueplayer.setheading(180)
blueplayer.forward(3)
def BlueLeft():
while True:
redplayer.setheading(180)
redplayer.forward(3)
def RedRight():
while True:
blueplayer.setheading(0)
blueplayer.forward(3)
def BlueRight():
while True:
redplayer.setheading(0)
redplayer.forward(3)
for x in range(10):
turtle.color('white')
style = ('Arial', 25, 'italic')
turtle.write(10-x, font=style, align='center')
time.sleep(1)
turtle.undo()
screen.listen()
screen.onkey(RedUp, "w")
screen.onkey(RedDown, "s")
screen.onkey(RedLeft, "a")
screen.onkey(RedRight, "d")
screen.onkey(BlueUp, "Up")
screen.onkey(BlueDown, "Down")
screen.onkey(BlueLeft, "Left")
screen.onkey(BlueRight, "Right")
screen.mainloop()
tron()