coding_giants

lesson 11 project

Mar 17th, 2023 (edited)
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame
  2.  
  3. from paddle import Paddle
  4.  
  5. # height and width of the screen
  6. SCREEN_WIDTH = 1024
  7. SCREEN_HEIGHT = 800
  8. # pygame settings
  9. pygame.init()
  10.  
  11. # display, clock and background objects
  12. display = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT])
  13. clock = pygame.time.Clock()
  14. background_image = pygame.image.load('images/background.png')
  15.  
  16. # paddle object
  17. paddle = Paddle()
  18.  
  19. # main game loop
  20. game_on = True
  21. while game_on:
  22. for event in pygame.event.get():
  23. if event.type == pygame.KEYDOWN:
  24. if event.key == pygame.K_ESCAPE:
  25. game_on = False
  26. elif event.type == pygame.QUIT:
  27. game_on = False
  28.  
  29. # paddle controls
  30. pressed_keys = pygame.key.get_pressed()
  31. if pressed_keys[pygame.K_a]:
  32. paddle.move_paddle(-1)
  33. if pressed_keys[pygame.K_d]:
  34. paddle.move_paddle(1)
  35.  
  36. # display background
  37. display.blit(background_image, (0, 0))
  38.  
  39. # display paddle
  40. display.blit(paddle.image, paddle.rect)
  41.  
  42. pygame.display.flip()
  43. clock.tick(30)
  44.  
  45. pygame.quit()
  46.  
  47.  
Add Comment
Please, Sign In to add comment