Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import turtle
  2. wn = turtle.Screen()
  3. wn.title("Pong By Cam")
  4. wn.bgcolor("black")
  5. wn.setup(width=800, height=600)
  6. wn.tracer(0)
  7. #Paddle A
  8. Hit = turtle.Turtle()
  9. Hit.speed(0)
  10. Hit.shape("square")
  11. Hit.color("white")
  12. Hit.shapesize(stretch_wid=5, stretch_len=1)
  13. Hit.penup()
  14. Hit.goto(-350, 0)
  15. #Paddle B
  16. Hitt = turtle.Turtle()
  17. Hitt.speed(0)
  18. Hitt.shape("square")
  19. Hitt.color("white")
  20. Hitt.shapesize(stretch_wid=5, stretch_len=1)
  21. Hitt.penup()
  22. Hitt.goto(350, 0)
  23. #Ball
  24. Ball = turtle.Turtle()
  25. Ball.speed(0)
  26. Ball.shape("square")
  27. Ball.color("white")
  28. Ball.penup()
  29. Ball.goto(0, 0)
  30. Ball.dx = 2
  31. Ball.dy = 2
  32. #Functions
  33. def Hit_up():
  34. y = Hit.ycor()
  35. y += 20
  36. Hit.sety(y)
  37. def Hit_down():
  38. y = Hit.ycor()
  39. y -= 20
  40. Hit.sety(y)
  41. def Hitt_up():
  42. y = Hitt.ycor()
  43. y += 20
  44. Hitt.sety(y)
  45. def Hitt_down():
  46. y = Hitt.ycor()
  47. y -= 20
  48. Hitt.sety(y)
  49. #Keyboard binding
  50. wn.listen()
  51. wn.onkeypress(Hit_up, "w")
  52. wn.onkeypress(Hit_down, "s")
  53. wn.onkeypress(Hitt_up, "Up")
  54. wn.onkeypress(Hitt_down, "Down")
  55. #Main game loop
  56. while True:
  57. wn.update()
  58. #Move the ball
  59. Ball.setx(Ball.xcor() + Ball.dx)
  60. Ball.sety(Ball.ycor() + Ball.dy)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement