Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #--------------- one player pong ---------------------
- import pygame
- #------------------- screen code ---------------------
- pygame.init()
- screen = pygame.display.set_mode((800, 600)) # this makes the screen
- pygame.display.set_caption('PiPong made by Leon Brisley')
- #------------------- varibles -------------------------
- done = False
- x = 400
- y = 300
- x_direction = 0.8
- y_direction = 0.8
- player_x = 400
- player_y = 560
- print('start')
- #-------------------- Main loop ---------------------
- while not done:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- done = True
- # x_direction = x_direction + 0.5
- x = x + x_direction
- if x >= 782 or x<= 0:
- x_direction = x_direction * -1 # x bouncing code
- y = y - y_direction
- if y >= 582 or y<= 0:
- y_direction = y_direction * -1 # y bouncing code
- if x == player_x and y == 578:
- x_direction = x_direction * -1
- y_direction = y_direction * -1
- if player_x >= 675:
- player_x = 675 # stops the paddle going off the edge
- if player_x <= 0:
- player_x = 0
- #------------------------- Players and Keys -------------------
- screen.fill((0, 0, 0))
- # pygame.draw.rect(screen, (r, g, b), pygame.Rect(x, y, width, height))
- pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(x, y, 18, 18)) # make the ball
- pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(player_x, player_y, 130, 16)) # makes the paddle
- pygame.display.flip()
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_LEFT:
- player_x = player_x + -2
- elif event.key == pygame.K_r:
- lives = 3
- x = 400
- y = 300
- x_direction = 0.8
- y_direction = 0.8
- player_x = 400
- player_y = 568
- print('reset')
- print()
- print()
- print()
- elif event.key == pygame.K_RIGHT:
- player_x = player_x + 2
Add Comment
Please, Sign In to add comment