#Trisha Ruiz
#6/15/2023
#mouse inputs

#init
import pygame, sys, random
from pygame.locals import *
pygame.init()

#constants
width = 1000
height = 700

#bgm
bgm = ["zelda.wav", "pokemon.wav"]

# assign sound files
blip_sound = pygame.mixer.Sound("blip.wav")
boing_sound = pygame.mixer.Sound("boing.wav")
bubbles_sound = pygame.mixer.Sound("bubbles.wav")


#init buttons | color, x, y, width, height | attributes
button_list = []

button_list.append(["red", 250, 350, 100, 50])
button_list.append(["orange", 450, 350, 100, 50])
button_list.append(["yellow", 650, 350, 100, 50])

click_x = 0
click_y = 0

#window
DISPLAYSURF = pygame.display.set_mode((width, height))
pygame.display.set_caption("mouse inputs")

clock = pygame.time.Clock()
clicked = False

#texts
myfont = pygame.font.SysFont("monospace", 30)
label1 = myfont.render("Press the buttons for sound!", 1, "green")
label2 = myfont.render("Press the scroll button for bgm!", 1, "cyan")
label3 = myfont.render("Press scroll again!", 1, "violet")


#check if clicked
def checkClick(click_x, click_y, button):

    #button is rectangle, so (x, y) is top left corner

    #if click is on button horizontally
    if click_x >= button[1] and click_x <= button[1] + button[3] and click_y >= button[2] and click_y <= button[2] + button[4]:
        return True
    else:
        return False
#game loop
while True:
    clock.tick(60)

    DISPLAYSURF.fill("black")

    DISPLAYSURF.blit(label1, (250, 100))
    DISPLAYSURF.blit(label2, (250-20, 200))
    DISPLAYSURF.blit(label3, (250+100, 500))
    
    #event handler
    for event in pygame.event.get():

        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type == MOUSEBUTTONDOWN:
            if pygame.mouse.get_pressed()[1]:#when scroll button is clicked
                
                #play random bgm
                bgm_file = random.randint(0,1)
                pygame.mixer.music.load(bgm[bgm_file]) #loads the music
                pygame.mixer.music.play(-1) #play music infinitely

            elif pygame.mouse.get_pressed()[0]:#when right is clicked

                #get x and y of click to check for button click
                click_x = event.pos[0]
                click_y = event.pos[1]

                #check if button is clicked
                if checkClick(click_x, click_y, button_list[0]):
                    print("button 1 was clicked")
                    pygame.mixer.Sound.play(blip_sound)
                elif checkClick(click_x, click_y, button_list[1]):
                    pygame.mixer.Sound.play(boing_sound)
                elif checkClick(click_x, click_y, button_list[2]):
                    print("button 3 was clicked")
                    pygame.mixer.Sound.play(bubbles_sound)

                
    
                
    #BUTTONS

    #draw buttons | color, x, y, width, height | attributes
    for button in button_list :
        pygame.draw.rect(DISPLAYSURF, button[0], (button[1], button[2], button[3], button[4]))


    pygame.display.update()
