#imports the pygame library, and sys library.
import pygame, sys
#import all your key names
from pygame.locals import *

def main():
    #initialize the library and start a clock, just in case we want it.
    pygame.init()

    #initialize the clock that will determine how often we render a frame
    clock = pygame.time.Clock()

    #create our canvas that will be draw on.
    resolution = (640, 480)
    canvas = pygame.display.set_mode(resolution)
    pygame.display.set_caption('RENAME ME SO I KNOW WHAT GAME I AM')

    #Pick our background and other colors with R,G,B values between 0 and 255
    backgroundColor = pygame.Color(255,255,255)
    mouseCircleColor = pygame.Color(100,150,100)
    pressedRectColor = pygame.Color(255,255,255)
    

    #initialize all the default values of variables we want to use
    mouseMovedX = 0
    mouseMovedY = 0
    mousePressedX = 0
    mousePressedY = 0


    #for ever and ever, keep rendering a new frame of our game.
    #this is where code that needs to be run every single frame belongs
    while True:
        #get all of our input events that have happened since the last frame
        for event in pygame.event.get():

            #deal with key presses
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    pygame.quit()
                    return
                    
            #deal with key releases
            elif event.type == KEYUP:
                if event.key in (K_LEFT, K_RIGHT):
                    #Do something because we hit left or right
                    keyPressed = "Yes"
                    
            #deal with mouse movement
            elif event.type == MOUSEMOTION:
                #the mouse has been moved
                mouseMovedX, mouseMovedY = event.pos

            #deal with mousebutton
            elif event.type == MOUSEBUTTONDOWN:
                mousePressedX, mousePressedY = event.pos
                if event.button in (1, 2, 3):
                    #left middle or right mouse click
                    pressedRectColor = pygame.Color(0, 100, 0)
                elif event.button in (4,5):
                    #mouse scrolled up or down
                    pressedRectColor = pygame.Color(200, 0, 0)
        
        
        #Done dealing with events, lets draw updated things on our canvas
        #fill our canvas with a background color, effectively erasing the last frame
        canvas.fill(backgroundColor)
    
        #Draw a rectangle where the mouse was last clicked.
        pygame.draw.rect(canvas, pressedRectColor, (mousePressedX, mousePressedY, 100, 100))

        #Draw a circle where the mouse currently is
        pygame.draw.circle(canvas, mouseCircleColor, (mouseMovedX, mouseMovedY), 25, 0)

        #done drawing all the stuff on our canvas, now lets show it to the user
        pygame.display.update()

        #wait the amount of time which
        clock.tick(30)
    
main()
