def forward_and_reflex(): for tur in FOUR_TURTLES: if abs(tur.xcor()) >= ww() / 2 - tur.radius: tur.setheading((180 - tur.heading()) % 360) if abs(tur.ycor()) >= wh() / 2 - tur.radius: tur.setheading((360 - tur.heading()) % 360) tur.forward(2)
def move(self): for other_tur in NinjaTurtle.all_ninjas: if (self is not other_tur and self.distance(other_tur) < 2 * self.radius): self.setheading(rint(0, 360)) if abs(self.xcor()) >= ww() / 2 - self.radius: self.setheading((180 - self.heading()) % 360) if abs(self.ycor()) >= wh() / 2 - self.radius: self.setheading((360 - self.heading()) % 360) self.forward(2)
def random_point(r): x = rint(-ww() // 2 + r, ww() // 2 - r) y = rint(-wh() // 2 + r, wh() / 2 - r) return (x, y)