forked from 20241144010013/20241144010013
207 lines
3.2 KiB
Python
207 lines
3.2 KiB
Python
import turtle as tl
|
|
import random as rd
|
|
#setup
|
|
tl.setup(600,600,None,None)
|
|
tl.hideturtle()
|
|
tl.colormode(255)
|
|
t = tl.Turtle()
|
|
t.color("Blue")
|
|
t.goto(-100,0)
|
|
t2 = tl.Turtle()
|
|
t2.color("Red")
|
|
t2.goto(100,0)
|
|
tl.tracer(1)
|
|
cheese = tl.Turtle()
|
|
cheese.color("Yellow")
|
|
cheese.shape("square")
|
|
cheese.up()
|
|
cheese.goto(-600,600)
|
|
|
|
#CENÁRIO
|
|
|
|
#moldura
|
|
tl.tracer(0)
|
|
tl.color("black")
|
|
tl.up()
|
|
tl.goto(-300,-300)
|
|
tl.down()
|
|
tl.goto(-300,300)
|
|
tl.goto(300,300)
|
|
tl.goto(300,-300)
|
|
|
|
#queijo
|
|
possible_pos = [(200,250),(-100,-250), (250,-250),(-50,200),(100,-150),(100,0)]
|
|
|
|
#linhas
|
|
tl.bgcolor((205, 133, 63))
|
|
for _ in range(-6, 6):
|
|
tl.color((139, 69, 19))
|
|
tl.up()
|
|
tl.goto(-300, _ * 50)
|
|
tl.down()
|
|
tl.goto(300, _ * 50)
|
|
tl.up()
|
|
|
|
tl.color("light blue")
|
|
tl.goto(-300, 300)
|
|
tl.down()
|
|
tl.begin_fill()
|
|
|
|
#parede
|
|
tl.goto(-300, 250)
|
|
tl.goto(300, 250)
|
|
tl.goto(300,300)
|
|
tl.end_fill()
|
|
|
|
#casa de rato
|
|
tl.up()
|
|
tl.goto(170, 250)
|
|
tl.color("black")
|
|
tl.down()
|
|
tl.begin_fill()
|
|
tl.goto(190,250)
|
|
tl.goto(190,260)
|
|
tl.left(90)
|
|
tl.circle(10, 180)
|
|
tl.end_fill()
|
|
|
|
#FIM-CENÁRIO
|
|
tl.update()
|
|
tl.tracer(1)
|
|
|
|
|
|
#funções
|
|
global tem_queijo
|
|
tem_queijo = False
|
|
|
|
#pass
|
|
|
|
def colide():
|
|
global tem_queijo
|
|
rng = rd.randint(0,5)
|
|
chance_tocheese = rd.randint(0,100)
|
|
if t.distance(t2) < 10 and tem_queijo == False:
|
|
print("Vitoria do Gato")
|
|
tl.bye()
|
|
elif t.pos()[1] > 250 or t.pos()[1] < -300 or t.pos()[0] > 300 or t.pos()[0] <- 300:
|
|
t.goto(0,0)
|
|
|
|
elif t2.pos()[1] > 250 or t2.pos()[1] < -300 or t2.pos()[0] > 300 or t2.pos()[0] < -300:
|
|
t2.goto(0,0)
|
|
|
|
elif t.distance(t2) < 10 and tem_queijo == True:
|
|
print("Vitoria do Rato")
|
|
tl.bye()
|
|
|
|
if chance_tocheese <= 5:
|
|
tl.tracer(0)
|
|
cheese.goto(possible_pos[rng])
|
|
tl.update()
|
|
tl.tracer(1)
|
|
if t.distance(cheese) < 10:
|
|
print("queijo coletado!")
|
|
tem_queijo = True
|
|
cheese.hideturtle()
|
|
|
|
|
|
|
|
def godir():
|
|
tl.tracer(0)
|
|
t.seth(0)
|
|
t.forward(50)
|
|
tl.update()
|
|
tl.tracer(1)
|
|
colide()
|
|
|
|
|
|
#pass
|
|
def goleft():
|
|
tl.tracer(0)
|
|
t.seth(180)
|
|
t.forward(50)
|
|
tl.update()
|
|
tl.tracer(1)
|
|
colide()
|
|
|
|
|
|
#pass
|
|
def goup():
|
|
tl.tracer(0)
|
|
t.seth(90)
|
|
t.forward(50)
|
|
tl.update()
|
|
tl.tracer(1)
|
|
colide()
|
|
|
|
|
|
#pass
|
|
def godown():
|
|
tl.tracer(0)
|
|
t.seth(270)
|
|
t.forward(50)
|
|
tl.update()
|
|
tl.tracer(1)
|
|
colide()
|
|
|
|
|
|
# pass
|
|
|
|
|
|
|
|
#segunda tartaruga
|
|
def godir2():
|
|
tl.tracer(0)
|
|
t2.seth(0)
|
|
t2.forward(50)
|
|
tl.update()
|
|
tl.tracer(1)
|
|
colide()
|
|
|
|
|
|
#pass
|
|
def goleft2():
|
|
tl.tracer(0)
|
|
t2.seth(180)
|
|
t2.forward(50)
|
|
tl.update()
|
|
tl.tracer(1)
|
|
colide()
|
|
|
|
|
|
#pass
|
|
def goup2():
|
|
tl.tracer(0)
|
|
t2.seth(90)
|
|
t2.forward(50)
|
|
tl.update()
|
|
tl.tracer(1)
|
|
colide()
|
|
|
|
|
|
#pass
|
|
def godown2():
|
|
tl.tracer(0)
|
|
t2.seth(270)
|
|
t2.forward(50)
|
|
tl.update()
|
|
tl.tracer(1)
|
|
colide()
|
|
#pass
|
|
|
|
|
|
|
|
|
|
|
|
#execução
|
|
tl.onkeypress(godir,"d")
|
|
tl.onkeypress(goleft,"a")
|
|
tl.onkeypress(goup,"w")
|
|
tl.onkeypress(godown, "s")
|
|
tl.onkeypress(godir2,"Right")
|
|
tl.onkeypress(goleft2,"Left")
|
|
tl.onkeypress(goup2,"Up")
|
|
tl.onkeypress(godown2, "Down")
|
|
tl.listen()
|
|
|
|
#loop
|
|
tl.mainloop() |