Способ вычисления направления normale
неверен: это должно быть направление к центру кривой, а не точка (0, 0)
, которая не имеет особого значения в этом контексте.
Итак,Вы можете изменить свой код на:
while nbrebonds >= 0: #rebonds means bounce
forward(1)
if (xcor() < -150 and distance(-150, 50) > 100) or (xcor() > 150 and distance(150,50) > 100):
trajectoire = heading()
if xcor() < -150:
normale = towards(-150, 50) #direction de la normale : vers le centre de la courbe
else:
normale = towards(150, 50)
trajectoire = 2*normale-180-trajectoire
print(trajectoire) # trajectoire du rebond
setheading(trajectoire)
forward(1)
nbrebonds -= 1 # plutôt que += -1
print(nbrebonds)
if ycor() < -50 or ycor() > 150:
trajectoire = heading()
trajectoire = 360-trajectoire
setheading(trajectoire)
nbrebonds -= 1
print(nbrebonds)