Взаимодействия между списками в python turlte - PullRequest
1 голос
/ 28 марта 2020

У меня есть все oop, которые обнаруживают столкновения между черепахами (движущимися шарами) в списке. Я хотел бы создать второй список (стационарных шаров) и иметь такое же обнаружение столкновений. Например, если красный и зеленый шар взаимодействуют, включите зеленый шар в красный цвет. Что я вижу, так это то, что некоторые стационарные шары будут меняться, в то время как большинство не меняются - не знаю почему.

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")      
...