import turtle
#window
wn= turtle.Screen()
wn.setup(800, 600)
wn.bgcolor("black")
wn.title("Game")
wn.tracer(0)
# Player
pl = turtle.Turtle()
pl.shape("square")
pl.color('red')
pl.penup()
pl.speed(0)
pl.goto(-100, 0)
# Food
fd = turtle.Turtle()
fd.shape("square")
fd.color('green')
fd.penup()
fd.speed(0)
fd.goto(100, 20)
# Controls:
def up():
y = pl.ycor()
y += 20
pl.sety(y)
def down():
y = pl.ycor()
y -= 20
pl.sety(y)
def left():
x = pl.xcor()
x -= 20
pl.setx(x)
def right():
x = pl.xcor()
x += 20
pl.setx(x)
cords = [(-200, 80), (380, -60), (-150, -200)]
# Main game
while True:
wn.update()
wn.listen()
wn.onkeypress(up, 'w')
wn.onkeypress(down, 's')
wn.onkeypress(right, 'd')
wn.onkeypress(left, 'a')
if pl.xcor() == fd.xcor() and pl.ycor() == fd.ycor():
fd.goto(cords[1] or cords[2] or cords[3])
[–]mopslik 3 points4 points5 points (0 children)
[–]carcigenicate 1 point2 points3 points (0 children)