guys. I'm writing 'Atari Breakout' game in pygame. How can I move this paddle with keys?
paddle = pygame.Rect(300, 220, 40, 5)
pygame.draw.rect(screen, WHITE, paddle, 0)
I've tried a few ways from stackoverflow, but nothing works.
Can you help me write function that moves paddle to right and left, when I'm pressing keys on keyboard, please?
That's my code:
import sys
import pygame
pygame.init()
FRAME_SIZE = (600, 400)
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
screen = pygame.display.set_mode(FRAME_SIZE)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
screen.fill(BLACK)
#objects
game_frame = pygame.Rect(100, 50, 400, 200)
pygame.draw.rect(screen, WHITE, game_frame, 5)
paddle = pygame.Rect(300, 220, 40, 5)
pygame.draw.rect(screen, WHITE, paddle, 0)
ball = pygame.Rect(300, 200, 5, 5)
pygame.draw.rect(screen, RED, ball, 0)
pygame.display.flip()