Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- from paddle import Paddle
- # height and width of the screen
- SCREEN_WIDTH = 1024
- SCREEN_HEIGHT = 800
- # pygame settings
- pygame.init()
- # display, clock and background objects
- display = pygame.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT])
- clock = pygame.time.Clock()
- background_image = pygame.image.load('images/background.png')
- # paddle object
- paddle = Paddle()
- # main game loop
- game_on = True
- while game_on:
- for event in pygame.event.get():
- if event.type == pygame.KEYDOWN:
- if event.key == pygame.K_ESCAPE:
- game_on = False
- elif event.type == pygame.QUIT:
- game_on = False
- # paddle controls
- pressed_keys = pygame.key.get_pressed()
- if pressed_keys[pygame.K_a]:
- paddle.move_paddle(-1)
- if pressed_keys[pygame.K_d]:
- paddle.move_paddle(1)
- # display background
- display.blit(background_image, (0, 0))
- # display paddle
- display.blit(paddle.image, paddle.rect)
- pygame.display.flip()
- clock.tick(30)
- pygame.quit()
Add Comment
Please, Sign In to add comment