# Leo Salazar
# 6/4/2024
# Introduction to pyGame with a bouncing ball (like dvd logo)

import pygame
import random

# Initial set up
pygame.init()
screen = pygame.display.set_mode((1280, 720))
clock = pygame.time.Clock()
running = True
x = screen.get_width()/2
y = screen.get_height()/2
dx = 1
dy = 1
r = 10

# picking a random color to start with
red = random.randint(0, 255)
blue = random.randint(0, 255)
green = random.randint(0, 255)
color = pygame.Color(red, blue, green)

# randomly picks a new color
def changeColor():
    color.update(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))

while running:
    # check if red x is pressed to quit
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # makes the background black
    screen.fill("black")

    # draws the circle
    pygame.draw.circle(screen, color, (x, y), r)

    # constantly moves the circle
    x += dx*5
    y += dy*5

    # keeps the circle within the walls of the game window
    # changes the direction depending on what wall is hit
    if x + r > screen.get_width():
        r += 5
        x = screen.get_width() - r
        dx *= -1
        changeColor()
    if x - r < 0:
        r += 5
        x = r
        dx *= -1
        changeColor()
    if y - r < 0:
        r += 5
        y = r
        dy *= -1
        changeColor()
    if y + r > screen.get_height():
        r += 5
        y = screen.get_height() - r
        dy *= -1
        changeColor()

    # displays changes to the screen
    pygame.display.flip()

    clock.tick(60)  # limits FPS to 60

pygame.quit()