import pygame
import sys
SCREEN = pygame.Rect(0, 0, 400, 400)
FPS = 30
WHITE = (255, 255, 255)
def main():
pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode(SCREEN.size)
ball = pygame.image.load('ball.png')
ball_width = ball.get_size()[0]
ball_height = ball.get_size()[1]
ball_x = 100
ball_y = 200
ball_dx = 5
ball_dy = 5
while True:
screen.fill(WHITE)
screen.blit(ball, (ball_x, ball_y))
if (ball_x < SCREEN.left) or (SCREEN.right - ball_width < ball_x):
ball_dx *= -1
if (ball_y < SCREEN.top) or (SCREEN.bottom - ball_height < ball_y):
ball_dy *= -1
ball_x += ball_dx
ball_y += ball_dy
pygame.display.update()
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if __name__ == '__main__':
main()