Мне нужно, чтобы движущийся шар и нажатие клавиши a/d работали одновременно, но поскольку код выполняется сверху вниз, шар продолжает зацикливаться, и код нажатия клавиши никогда не активируется, поэтому вы не можете перемещать его одновременно с движением мяча.
t = turtle.Turtle()
t.speed(0)
t.pensize(5)
t.color("Black")
def Rectangle():
for i in range(2):
t.forward(590)
t.left(90)
t.forward(380)
t.left(90)
Rectangle()
t.penup()
t.goto(205,100)
t.color("Blue")
t.shape("circle")
A = random.randint(30,60)
B = random.randint(120,150)
C = random.randint(210,240)
D = random.randint(300,330)
Directions = [A, B, C, D]
direct = random.choice(Directions)
def tDirection(direct):
t.right(direct)
tDirection(direct)
speed = 2
angle = 90
while True:
color = ['black', 'blue', 'green', 'yellow', 'orange', "purple", "pink", "turquoise"]
t.forward(speed)
ty = t.ycor()
tx = t.xcor()
#print(ty, tx)
#breaking out bottom
if ty < 9:
Col = random.choice(color)
while Col == t.color()[0]:
Col = random.choice(color)
t.color(Col)
angleCurr = t.heading()
if(270>angleCurr>180):
t.right(angle)
else:
t.left(angle)
t.forward(2)
#breaking out top
if ty > 188:
Col = random.choice(color)
while Col == t.color()[0]:
Col = random.choice(color)
t.color(Col)
angleCurr = t.heading()
if(0
Подробнее здесь: [url]https://stackoverflow.com/questions/67608561/the-problem-is-that-the-ball-loop-keeps-looping-and-you-cant-control-the-charact[/url]
Мне нужно, чтобы движущийся шар и нажатие клавиши a/d работали одновременно, но поскольку код выполняется сверху вниз, шар продолжает зацикливаться, и код нажатия клавиши никогда не активируется, поэтому вы не можете перемещать его одновременно с движением мяча. [code]t = turtle.Turtle() t.speed(0) t.pensize(5) t.color("Black")
def Rectangle(): for i in range(2): t.forward(590) t.left(90) t.forward(380) t.left(90)
A = random.randint(30,60) B = random.randint(120,150) C = random.randint(210,240) D = random.randint(300,330) Directions = [A, B, C, D] direct = random.choice(Directions)
while True: color = ['black', 'blue', 'green', 'yellow', 'orange', "purple", "pink", "turquoise"]
t.forward(speed) ty = t.ycor() tx = t.xcor() #print(ty, tx)
#breaking out bottom if ty < 9: Col = random.choice(color) while Col == t.color()[0]: Col = random.choice(color) t.color(Col) angleCurr = t.heading() if(270>angleCurr>180): t.right(angle) else: t.left(angle) t.forward(2) #breaking out top if ty > 188: Col = random.choice(color) while Col == t.color()[0]: Col = random.choice(color) t.color(Col) angleCurr = t.heading() if(0