Guest User

Untitled

a guest
Feb 17th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. # main game loop
  2. def move():
  3. global pong_dx, pong_dy, AIplayerspeed, seconds, score
  4.  
  5. # move pong ball
  6. x, y = pong.position()
  7. x += pong_dx
  8. y += pong_dy
  9. pong.setposition(x, y)
  10.  
  11. if isCollision(pong, player): # collision pong and player
  12. pong_dx *= -1
  13. # Update the score
  14. score += 10
  15. score_pen.undo()
  16. score_pen.write("Score: {}".format(score), align="left", font=FONT)
  17. elif isCollision(pong, AIplayer): # collision pong and AIplayer
  18. pong_dx *= -1
  19. elif y < -299.5 or y > 299.5: # check for bounce and redirect it
  20. pong_dy *= -1
  21. elif x > 300:
  22. pong_dx *= -1
  23. elif x < -300:
  24. print("Game Over")
  25. screen.bye()
  26. return
  27.  
  28. # move AI paddle (might speed up pong movement)
  29. AIplayer.forward(AIplayerspeed)
  30.  
  31. y = AIplayer.ycor()
  32.  
  33. if y < -250 or y > 250:
  34. AIplayerspeed *= -1
  35.  
  36. # display timer
  37. seconds += 0.05
  38. time_pen.undo()
  39. time_pen.write("Time: {}".format(int(seconds)), False, align="Left", font=FONT)
  40. screen.ontimer(move, 50)
  41.  
  42. screen.update()
  43.  
  44. screen.tracer(False)
  45. move()
  46. screen.mainloop()
Add Comment
Please, Sign In to add comment