import turtle as t
import random
score = 0
playing = False
te=t.Turtle()
te.shape("turtle")
te.color("red")
te.speed(0)
te.penup()
te.goto(0,200)
te2=t.Turtle()
te2.shape("turtle")
te2.color("red")
te2.speed(0)
te2.penup()
te2.goto(200,200)
te2.hideturtle()
ts1=t.Turtle()
ts1.shape("circle")
ts1.color("green")
ts1.speed(0)
ts1.penup()
ts1.goto(0,-200)
ts2=t.Turtle()
ts2.shape("circle")
ts2.color("purple")
ts2.speed(0)
ts2.penup()
ts2.goto(0,-100)
ts3 = t.Turtle()
ts3.shape("circle")
ts3.color("green")
ts3.speed(0)
ts3.penup()
ts3.goto(0,50)
ts3.shapesize(0.99)
s1=t.Turtle()
s1.goto(0,150)
s1.penup()
s1.clear()
s1.hideturtle()
s1.color("grey")
def turn_right():
t.setheading(0)
def turn_up():
t.setheading(90)
def turn_left():
t.setheading(180)
def turn_down():
t.setheading(270)
def start():
global playing
if playing == False:
playing = True
t.clear()
s1.clear()
play()
d_right=0
d_left=180
d_up=90
d_down=270
def area():
global d_right, d_left, d_up, d_down
if t.xcor()>250:
t.setheading(d_right)
if t.ycor()>250:
t.setheading(d_down)
if t.xcor()>250:
t.setheading(d_left)
if t.ycor()>250:
t.setheading(d_up)
if te.xcor()>250:
te.setheading(d_right)
if te.ycor()>250:
te.setheading(d_down)
if te.xcor()>250:
te.setheading(d_left)
if te.ycor()>250:
te.setheading(d_up)
def play():
global score
global playing
area()
speed=score+10
if speed > 15:
speed = 15
if score == 20:
speed = 7
if score > 20:
speed = 13
if score > 80:
speed = 11
t.forward(speed)
ang = te.towards(t.pos())
te.setheading(ang)
te.forward(10)
if score == 5:
t.setup(410,410)
if t.distance(te) < 12:
text = "score : "+str(score)
message("Game over", text)
playing = False
print(score)
score = 0
t.goto(0,0)
ts2.goto(0,-100)
ts3.goto(0,50)
ts1.goto(0,-200)
te.goto(0, 200)
te2.goto(200,200)
if t.distance(te2) < 12:
text = "score : "+str(score)
message("Game over", text)
playing = False
print(score)
score = 0
t.goto(0,0)
ts2.goto(0,-100)
ts3.goto(0,50)
ts1.goto(0,-200)
te.goto(0, 200)
te2.goto(200,200)
if t.distance(ts1) < 12:
s1.clear()
score = score + 1
star_x = random.randint(-200, 200)
star_y = random.randint(-200, 200)
ts1.goto(star_x, star_y)
if score > 5:
score = score + 4
if score == 5:
te.goto(0,200)
if score==20:
te.goto(0,200)
if score==80:
te.goto(0,200)
if score > 20:
score = score + 5
s1.write(f"score : {score}", False, "center", ("", 20))
if t.distance(ts2) < 12:
s1.clear()
score = score + 1
star_x1 = random.randint(-200, 200)
star_y1 = random.randint(-200, 200)
t.goto(star_x1, star_y1)
star_x = random.randint(-200, 200)
star_y = random.randint(-200, 200)
ts2.goto(star_x, star_y)
if score > 5:
score = score + 4
if score == 5:
te.goto(0,200)
if score==20:
te.goto(0,200)
if score==80:
te.goto(0,200)
if score > 20:
score = score + 5
s1.write(f"score : {score}", False, "center", ("", 20))
if playing:
t.ontimer(play,100)
if t.distance(ts3) < 12:
s1.clear()
score = score - 1
star_x = random.randint(-200, 200)
star_y = random.randint(-200, 200)
ts3.goto(star_x, star_y)
if score >20:
score=score-4
s1.write(f"score : {score}", False, "center", ("", 20))
if score > 20:
te2.st()
ang2 = te2.towards(t.pos())
te2.setheading(ang2)
te2.forward(11)
def message(m1, m2):
t.clear()
t.goto(0, 100)
t.write(m1, False, "center", ("", 20))
t.goto(0, -100)
t.write(m2, False, "center", ("", 15))
t.home()
t.title("Turtle Run")
t.setup(500,500)
t.bgcolor("blue")
t.shape("turtle")
t.speed(0)
t.up()
t.color("white")
t.onkeypress(turn_right, "Right")
t.onkeypress(turn_up, "Up")
t.onkeypress(turn_left, "Left")
t.onkeypress(turn_down, "Down")
t.onkeypress(start, "space")
t.listen()
message("Turtle Run", "[Space]")
여기다가
1. 1회용 먹이 만들기(먹으면 다시 생성x)
2.그 먹이 랜덤으로 두가지 효과 부여하기
3.작아지면 점수가 변할때까지 속도가 급격히 증가
4.커지면 악당 한마리 잡아먹음
추가해보고 싶은데 4번에서 막힙니다...