#Small example demonstrating alpha/text rendering
import pscreen

#Load our screen using pyglet
pscreen.LoadScreen((400, 400), False, "pyglet")

background = 255
alphaValue = 255

#Game loop
while True:

    #Exit out of this loop if escape is pressed
    if pscreen.KeyIsPressed("escape"):
        break

    #Clear the screen
    pscreen.ClearScreen((background, background, background, 255))

    #Draw a few shapes    
    pscreen.Triangle(10, 10, 390, 10, 200, 390, (255, 0, 0, alphaValue), 0)
    pscreen.Rectangle(10, 10, 390, 250, (0, 255, 0, alphaValue), 0)
    pscreen.Ellipse(200, 235, 150, 100, (255, 255, 0, alphaValue), 0)
    pscreen.Circle(30, 60, 25, (0, 0, 255, alphaValue), 0)
    pscreen.Circle(370, 60, 25, (0, 0, 255, alphaValue), 0) 
    #pscreen.Line(10, 10, 390, 10, 200, 390, (255, 0, 0, alphaValue), 0)

    #Use up and down keys to change transparency of the filled triangle
    if(pscreen.KeyIsPressed("up")):
        #Alpha cannot exceed 255, so clamp it here
        alphaValue = min(alphaValue+1, 255)

    if(pscreen.KeyIsPressed("down")):
        #Also, alpha is a positive value, so clamp it at zero
        alphaValue = max(alphaValue-1, 0)

    if(pscreen.KeyIsPressed("right")):
        #Alpha cannot exceed 255, so clamp it here
        background = min(background+1, 255)

    if(pscreen.KeyIsPressed("left")):
        #Also, alpha is a positive value, so clamp it at zero
        background = max(background-1, 0)

    #Initialize a font
    pscreen.FontSelect("Arial", 16)

    #Display alpha/background
    pscreen.FontWrite(10, 345, "Alpha: " + str(alphaValue), (0, 0, 255, 255))
    pscreen.FontWrite(10, 375, "Background  : " + str(background), (0, 0, 255, 255))

    pscreen.FontSelect("Arial", 8)

    #Print instructions
    pscreen.FontWrite(225, 345, "Up/Down - Change alpha", (0, 0, 255, 255))
    pscreen.FontWrite(215, 375, "Left/Right - Change background color", (0, 0, 255, 255))
    
    pscreen.UpdateScreen()

pscreen.UnloadScreen()
