# Kat Prendergast
# 6/15/22
# Movement in pygame - ball continuously moves in the direction you tell it to

import pygame,sys
from pygame.locals import *

def main():
    pygame.init()
    DISPLAYSURF = pygame.display.set_mode((1000,600))
    pygame.display.set_caption("Continuous Movement")

    BLACK = pygame.Color(0,0,0)
    PURPLE = pygame.Color(255,0,255)

    clock = pygame.time.Clock()

    x = 300
    y = 300
    dx = 0
    dy = 0

    while True:

        for event in pygame.event.get():

            if event.type == QUIT:
                pygame.quit()
                sys.exit()

            # Change speed/direction based on which arrow key you press
            if event.type == KEYDOWN:
                if event.key == K_DOWN:
                    dy = 5
                    dx = 0
                elif event.key == K_UP:
                    dy = -5
                    dx = 0
                elif event.key == K_RIGHT:
                    dx = 5
                    dy = 0
                else: #event.key == K_LEFT:
                    dx = -5
                    dy = 0

        # Move the ball
        x += dx
        y += dy

        DISPLAYSURF.fill(BLACK)
        pygame.draw.circle(DISPLAYSURF, PURPLE, (x,y), 20, 0)
        pygame.display.update()

        clock.tick(60)

main()
