I have the turtle named "t", which is controlled by the user, and a turtle that moves randomly named "to". I need the turtle named "to" to run away from turtle "t" when peepee
(which btw is just the level) equals to 1 to 4. Turtle "to" is still catchable, but when peepee
equals 5, the turtle "to" moves randomly, making it almost impossible to catch
from time import sleep
import turtle
import random
print("this is a turtle game, u r the police turtle (blue), and u need to beat up the criminal turtle (black)")
s = turtle.Screen()
s.bgcolor('white')
s.setup(500,380)
d=turtle.Turtle()
d.penup()
d.goto(-150,-150)
d.pensize(5)
d.pendown()
d.hideturtle()
for x in range(4):
d.forward(300)
d.left(90)
t = turtle.Turtle()
t.shape('turtle')
t.color('blue')
t.penup()
to = turtle.Turtle()
to.shape('turtle')
to.color('black')
to.penup()
for peepee in range(1, 6):
xcor=[]
ycor=[]
xrandomlist=[]
yrandomlist=[]
jack=random.randint(-130,130)
to.speed(peepee)
t.goto(40,-40)
to.goto(40,40)
t.setheading(180)
to.setheading(180)
def left():
t.left(90)
def right():
t.left(-90)
def goup():
t.forward(15)
xcor.append(t.xcor())
ycor.append(t.ycor())
def godown():
t.forward(-15)
xcor.append(t.xcor())
ycor.append(t.ycor())
jacker=random.randint(-130,130)
def drunkt():
if to.xcor()<140:
if to.xcor()> -140:
if to.ycor()<140:
if to.ycor()>-140:
turn=random.choice([90,-90])
to.left(turn)
go=random.choice([-20, 20])
def jiji():
if peepee==5:
if to.distance(t)<60:
to.goto(jack, jacker)
to.forward(go)
xrandomlist.append(to.xcor())
yrandomlist.append(to.ycor())
jiji()
if to.xcor()>130 or to.xcor()< -130 or to.ycor()>130 or to.ycor()<-130:
def yoyo():
to.goto(jacker, jacker)
xrandomlist.append(to.xcor())
yrandomlist.append(to.ycor())
yoyo()
s.onkeypress(left, "Left")
s.onkeypress(right, "Right")
s.onkeypress(goup, "Up")
s.onkeypress(godown, "Down")
s.listen()
if peepee==5:
print("ur now on the final level")
to.speed(7)
to.color("yellow")
else:
print(f"u r playing level {peepee}.")
sleep(1)
while True:
if peepee==5:
don=random.choice([1,2])
if don==1:
to.goto(jack, jacker)
drunkt()
if t.xcor()>130 or t.xcor()<-130:
print("game over")
s.bye()
sleep(9999)
if t.ycor()>130 or t.ycor()<-130:
print("game over")
s.bye()
sleep(9999)
if t.distance(to)<30:
print("noice")
print(' ')
for x in range(len(xcor)):
t.speed(1)
t.goto(xcor[-1],ycor[-1])
xcor.pop(-1)
ycor.pop(-1)
for x in range(len(xrandomlist)):
to.speed(1)
to.goto(xrandomlist[-1],yrandomlist[-1])
xrandomlist.pop(-1)
yrandomlist.pop(-1)
sleep(2)
break
turtle.done()
s.bye()
I tried putting some stuff in drunkt()
. It doesn't matter where the turtle "to" goes, I just need that turtle to move away from "t", but not impossible to catch. But on level 5, I need the turtle "to" to be nearly impossible to catch.