python turlte中to列表之间的交互

python turlte中to列表之间的交互,python,turtle-graphics,Python,Turtle Graphics,我有一个循环检测列表中海龟之间的碰撞(移动球)。我想创建第二个列表(固定球),并具有相同的碰撞检测。例如,如果红色和绿色球相互作用,则将绿色球变成红色。我所看到的是,一些固定的球会改变,而大多数不会-不知道为什么 while True: #moving balls wn.update() for ball in balls: ball.sety(ball.ycor() + ball.dy) ball.setx(ball.xcor() + ball.

我有一个循环检测列表中海龟之间的碰撞(移动球)。我想创建第二个列表(固定球),并具有相同的碰撞检测。例如,如果红色和绿色球相互作用,则将绿色球变成红色。我所看到的是,一些固定的球会改变,而大多数不会-不知道为什么

while True:
#moving balls
    wn.update()
    for ball in balls:
        ball.sety(ball.ycor() + ball.dy)
        ball.setx(ball.xcor() + ball.dx)
        for other_ball in balls:
            if (other_ball is ball):
                # We are not interested in balls colliding with themselves.
                # Skip the current iteration of the inner for-loop, and move on to the next ball
                continue

            if is_collided_with(other_ball, ball) and (ball.color()!=other_ball.color()):
                ball.color("red")     
            if is_collided_with(ball, nidas):
                ball.color("red")

#BARRIER ON
        if not_safe_top(ball):
                ball.dy *=-1
                ball.dx *=-1
        if not_safe_bottom(ball):
                ball.dy *=-1
                ball.dx *=-1
        if ball.ycor() <-400:
                ball.dy *=-1
        if ball.ycor() >+400:
                ball.dy *=-1
        if ball.xcor() >+400:
                ball.dx *=-1
        if ball.xcor() <-400:
                ball.dx *=-1

#stationary balls
    wn.update()
    for ball_s in balls_stat:
        for other_ball_s in balls_stat:
            if (other_ball_s is ball):
                # We are not interested in balls colliding with themselves.
                # Skip the current iteration of the inner for-loop, and move on to the next ball
                continue
            if is_collided_with(ball_s, ball) and (ball.color()!=ball_s.color()):
                ball_s.color("red")      
为True时:
#移动球
wn.update()
对于球中球:
ball.sety(ball.ycor()+ball.dy)
ball.setx(ball.xcor()+ball.dx)
对于其他球中球:
如果(其他球是球):
#我们对球与其碰撞不感兴趣。
#跳过内部for循环的当前迭代,继续下一个球
持续
如果与(其他球,球)和(ball.color()!=其他球.color())碰撞:
球。颜色(“红色”)
如果与(球、奈达)碰撞:
球。颜色(“红色”)
#障碍物
如果不安全,顶部(球):
ball.dy*=-1
ball.dx*=-1
如果底部(球)不安全:
ball.dy*=-1
ball.dx*=-1
如果ball.ycor()+400:
ball.dy*=-1
如果ball.xcor()>+400:
ball.dx*=-1

如果底部嵌套for循环中的ball.xcor()迭代“ball_s”和“other_ball_s”,但在某些地方使用“ball”。复制粘贴后,代码未正确调整。在底部的嵌套for循环中,您迭代“ball_s”和“other_ball_s”,但在某些地方使用“ball”。复制粘贴后,代码未正确改编。