import pygame
from pygame.locals import *
window = pygame.display.set_mode((600,400))
#

moveX,moveY=0,0
clock=pygame.time.Clock()

class player(pygame.sprite.Sprite):
    def __init__(self,x,y):
        pygame.sprite.Sprite.__init__(self)
        self.x=x
        self.y=y
        self.image = pygame.image.load('Player.png')
        self.rect = pygame.Rect(self.x,self.y,30,30)
player_object = player(100,100)
sprites = pygame.sprite.Group()
sprites.add(player_object)


#
loop = True
while loop == True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            loop = 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

    

    player_object.x=moveX
    player_object.y=moveY
    clock.tick(50)
    pygame.display.update()
    sprites.draw(window)
    sprites.update()

pygame.quit()
