import pygame

pygame.init()

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

pygame.display.set_caption("Window")

moveX=0
moveY=0

black = (0,0,0)

white = (255, 255, 255)

clock = pygame.time.Clock()

class Sprite():
    def __init__(self,x,y):

        self.x=x

        self.y=y

        self.width=50

        self.height=50

    def render(self):

        pygame.draw.rect(window, white, (self.x, self.y, self.width, self.height))

player = Sprite(100,150)

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 = -15

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

                moveX = 15

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

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

                moveY = 15

        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)

        player.x += moveX

        player.y += moveY

        player.render()

        clock.tick (500)

        pygame.display.flip()

pygame.quit()
