Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- import time
- #screen
- delay=0.1
- wn=turtle.Screen()
- wn.title("Snake game by @Misheel")
- wn.bgcolor("white")
- wn.setup(width=600,height=600)
- wn.tracer(0)
- #snakehead
- head=turtle.Turtle()
- head.speed(0)
- head.shape("square")
- head.color("black")
- head.penup()
- head.goto(0,0)
- head.direction="up"
- def go_up():
- head.direction="up"
- def go_down():
- head.direction="down"
- def go_left():
- head.direction="left"
- def go_right():
- head.direction="right"
- def move():
- if head.direction == "up":
- y=head.ycor()
- head.sety(y+20)
- def move():
- if head.direction == "down":
- y=head.ycor()
- head.sety(y-20)
- def move():
- if head.direction == "left":
- x=head.ycor()
- head.setx(x-20)
- def move():
- if head.direction == "right":
- x=head.ycor()
- head.setx(x+20)
- wn.listen()
- wn.onkeypress(go_up,"w")
- wn.onkeypress(go_down,"s")
- wn.onkeypress(go_left,"a")
- wn.onkeypress(go_right,"d")
- while True:
- wn.update()
- move()
- time.sleep(delay)
- wn.mailoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement