Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. import turtle
  2. wn = turtle.Screen()
  3. wn.title ("Adrian's crappy Pong game")
  4. wn.bgcolor("black")
  5. wn.setup(width=800 , height=600)
  6. wn.tracer(0)
  7.  
  8. #Scoring
  9. pen = turtle.Turtle()
  10. pen.speed(0)
  11. pen.color("white")
  12. pen.penup()
  13. pen.hideturtle()
  14. pen.goto(-50, 260)
  15. pen.write("Nigga A:0 Nigga B:0", align="center", font=("Courier", 24 ,"normal"))
  16. score_a = 0
  17. score_b = 0
  18.  
  19. #Long Stick A
  20. longstick_a = turtle.Turtle()
  21. longstick_a.speed(0)
  22. longstick_a.shape("square")
  23. longstick_a.color("red")
  24. longstick_a.shapesize(stretch_wid=5 , stretch_len=1)
  25. longstick_a.penup()
  26. longstick_a.goto(-350, 0)
  27.  
  28. #Long Stick B
  29. longstick_b = turtle.Turtle()
  30. longstick_b.speed(0)
  31. longstick_b.shape("square")
  32. longstick_b.color("red")
  33. longstick_b.shapesize(stretch_wid=5 , stretch_len=1)
  34. longstick_b.penup()
  35. longstick_b.goto(+350, 0)
  36.  
  37.  
  38. #Ball
  39. Ball = turtle.Turtle()
  40. Ball.speed(0)
  41. Ball.shape("circle")
  42. Ball.color("white")
  43. Ball.penup()
  44. Ball.goto(0, 0)
  45. Ball.dx = 0.2
  46. Ball.dy = 0.3
  47.  
  48. #Functions
  49.  
  50. def longstick_b_up():
  51. y = longstick_b.ycor()
  52. y += 20
  53. longstick_b.sety(y)
  54.  
  55.  
  56. def longstick_b_down():
  57. y = longstick_b.ycor()
  58. y -= 20
  59. longstick_b.sety(y)
  60.  
  61.  
  62.  
  63. def longstick_a_up():
  64. y = longstick_a.ycor()
  65. y += 20
  66. longstick_a.sety(y)
  67.  
  68.  
  69. def longstick_a_down():
  70. y = longstick_a.ycor()
  71. y -= 20
  72. longstick_a.sety(y)
  73.  
  74. #Keyboard binding
  75. wn.listen()
  76. wn.onkeypress(longstick_a_up, "w" )
  77. wn.onkeypress(longstick_a_down, "s")
  78. wn.onkeypress(longstick_b_up, "Up" )
  79. wn.onkeypress(longstick_b_down, "Down")
  80.  
  81.  
  82. #Main game loop dont forget it moron
  83. while True:
  84. wn.update()
  85.  
  86. #Move Ball
  87. Ball.setx(Ball.xcor() + Ball.dx)
  88. Ball.sety(Ball.ycor() + Ball.dy)
  89.  
  90. #Trumps Wall
  91. if Ball.ycor() < -290:
  92. Ball.sety(-290)
  93. Ball.dy *= -1
  94. if Ball.ycor() > 290:
  95. Ball.sety(290)
  96. Ball.dy *= -1
  97.  
  98. if Ball.xcor() > 390:
  99. Ball.goto(0, 0)
  100. Ball.dx *= -1
  101. score_a += 1
  102. pen.clear()
  103. pen.write("Nigga A: {} Nigga B: {}". format(score_a, score_b), align="center", font=("Courier", 24 ,"normal"))
  104.  
  105. if Ball.xcor() < -390:
  106. Ball.goto(0, 0)
  107. Ball.dx *= -1
  108. score_b += 1
  109. pen.clear()
  110. pen.write("Nigga A: {} Nigga B: {}". format(score_a, score_b), align="center", font=("Courier", 24 ,"normal"))
  111.  
  112.  
  113. #Collisions
  114. if Ball.xcor() > 340 and (Ball.ycor() < longstick_b.ycor() + 40 and Ball.ycor() > longstick_b.ycor() - 50):
  115. Ball.dx *= -1
  116. Ball.setx(340)
  117.  
  118. if Ball.xcor() < -340 and (Ball.ycor() < longstick_a.ycor() + 40 and Ball.ycor() > longstick_a.ycor() - 50):
  119. Ball.dx *= -1
  120. Ball.setx(-340)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement