import pygame

pygame.init()

window = pygame.display.set_mode((800,600))

pygame.display.set_caption("Window")

x,y=0,0

moveX=0
moveY=0

black = (0,0,0)

white = (255, 255, 255)

clock = pygame.time.Clock()

gameLoop=True
while gameLoop:
    for event in pygame.event.get():
        if (event.type==pygame.QUIT):
            gameLoop=False

        if (event.type==pygame.KEYDOWN):

            if event.key == pygame.K_LEFT or event.key == ord ('a') :

                moveX = -5

            if event.key == pygame.K_RIGHT or event.key == ord ('d'):

                moveX = 5

            if event.key == pygame.K_UP or event.key == ord ('w'):

                moveY = -5
                
            if event.key == pygame.K_DOWN or event.key == ord ('s'):

                moveY = 5

        if (event.type==pygame.KEYUP):

            if event.key == pygame.K_LEFT or event.key == ord ('a') :

                moveX = 0

            if event.key == pygame.K_RIGHT or event.key == ord ('d'):

                moveX = 0

            if event.key == pygame.K_UP or event.key == ord ('w'):

                moveY = 0
                
            if event.key == pygame.K_DOWN or event.key == ord ('s'):

                moveY = 0


        window.fill(black)

        x+=moveX
        y+=moveY

        pygame.draw.rect(window, white, (x, y, 50, 50))

        clock.tick (500)

        pygame.display.flip()

pygame.quit()
