Guest User

Untitled

a guest
Jun 18th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #--------------- one player pong ---------------------
  2.  
  3.  
  4. import pygame
  5. #------------------- screen code ---------------------
  6. pygame.init()
  7. screen = pygame.display.set_mode((800, 600)) # this makes the screen
  8. pygame.display.set_caption('PiPong made by Leon Brisley')
  9.  
  10.  
  11. #------------------- varibles -------------------------
  12. done = False
  13. x = 400
  14. y = 300
  15. x_direction = 0.8
  16. y_direction = 0.8
  17. player_x = 400
  18. player_y = 560
  19. print('start')
  20.  
  21.  
  22.  
  23. #-------------------- Main loop ---------------------
  24. while not done:
  25.  
  26. for event in pygame.event.get():
  27. if event.type == pygame.QUIT:
  28. done = True
  29.  
  30.  
  31. # x_direction = x_direction + 0.5
  32. x = x + x_direction
  33. if x >= 782 or x<= 0:
  34. x_direction = x_direction * -1 # x bouncing code
  35. y = y - y_direction
  36. if y >= 582 or y<= 0:
  37. y_direction = y_direction * -1 # y bouncing code
  38.  
  39.  
  40. if x == player_x and y == 578:
  41. x_direction = x_direction * -1
  42. y_direction = y_direction * -1
  43.  
  44.  
  45.  
  46. if player_x >= 675:
  47. player_x = 675 # stops the paddle going off the edge
  48. if player_x <= 0:
  49. player_x = 0
  50.  
  51. #------------------------- Players and Keys -------------------
  52.  
  53. screen.fill((0, 0, 0))
  54. # pygame.draw.rect(screen, (r, g, b), pygame.Rect(x, y, width, height))
  55. pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(x, y, 18, 18)) # make the ball
  56. pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(player_x, player_y, 130, 16)) # makes the paddle
  57. pygame.display.flip()
  58. if event.type == pygame.KEYDOWN:
  59. if event.key == pygame.K_LEFT:
  60. player_x = player_x + -2
  61.  
  62. elif event.key == pygame.K_r:
  63. lives = 3
  64. x = 400
  65. y = 300
  66. x_direction = 0.8
  67. y_direction = 0.8
  68. player_x = 400
  69. player_y = 568
  70. print('reset')
  71. print()
  72. print()
  73. print()
  74.  
  75. elif event.key == pygame.K_RIGHT:
  76. player_x = player_x + 2
Add Comment
Please, Sign In to add comment