Advertisement
Guest User

Untitled

a guest
Jan 24th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import turtle
  2. import time
  3. #screen
  4. delay=0.1
  5. wn=turtle.Screen()
  6. wn.title("Snake game by @Misheel")
  7. wn.bgcolor("white")
  8. wn.setup(width=600,height=600)
  9. wn.tracer(0)
  10. #snakehead
  11.  
  12. head=turtle.Turtle()
  13. head.speed(0)
  14. head.shape("square")
  15. head.color("black")
  16. head.penup()
  17. head.goto(0,0)
  18. head.direction="up"
  19. def go_up():
  20. head.direction="up"
  21. def go_down():
  22. head.direction="down"
  23. def go_left():
  24. head.direction="left"
  25. def go_right():
  26. head.direction="right"
  27. def move():
  28. if head.direction == "up":
  29. y=head.ycor()
  30. head.sety(y+20)
  31.  
  32. def move():
  33. if head.direction == "down":
  34. y=head.ycor()
  35. head.sety(y-20)
  36. def move():
  37. if head.direction == "left":
  38. x=head.ycor()
  39. head.setx(x-20)
  40. def move():
  41. if head.direction == "right":
  42. x=head.ycor()
  43. head.setx(x+20)
  44. wn.listen()
  45. wn.onkeypress(go_up,"w")
  46. wn.onkeypress(go_down,"s")
  47. wn.onkeypress(go_left,"a")
  48. wn.onkeypress(go_right,"d")
  49.  
  50.  
  51. while True:
  52. wn.update()
  53. move()
  54. time.sleep(delay)
  55.  
  56. wn.mailoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement