
import pygame, random, sys, time
from pygame.locals import *


#set up some variables
WINDOWWIDTH = 1024
WINDOWHEIGHT = 600
FPS = 6000
TEXTCOLOR = (140, 0, 0)
BLACK = (0,0,0)
BLUE = (0, 0, 255)
RED = (255, 0, 0)
def terminate():
    pygame.quit()
    sys.exit()

def waitForPlayerToPressKey():
    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                terminate()
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE: # pressing escape quits
                    terminate()
                if event.key == K_RETURN:
                    return
                if event.key == ord('q'):
                    return


def drawText(text, font, surface, x, y):
    textobj = font.render(text, 1, TEXTCOLOR)
    textrect = textobj.get_rect()
    textrect.topleft = (x, y)
    surface.blit(textobj, textrect)

            
    
# set up pygame, the window, and the mouse cursor
pygame.init()
mainClock = pygame.time.Clock()
windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
pygame.display.set_caption('ESCAPE')
pygame.mouse.set_visible(False)

# set up fonts
font = pygame.font.SysFont(None, 48)


# set up images
    #player
playerImage = pygame.image.load('Player.png').convert_alpha()
playerRect = playerImage.get_rect()
playerRotateL = pygame.transform.rotate(playerImage,90)
playerRotateR = pygame.transform.rotate(playerImage,270)
playerRotateU = pygame.transform.rotate(playerImage,0)
playerRotateD = pygame.transform.rotate(playerImage,180)

    #scissors
scissorsImage = pygame.image.load('scissors.png')
scissorsRect = scissorsImage.get_rect()

    #startroom
backgroundImage = pygame.image.load('background1.png')
rescaledBackground = pygame.transform.scale(backgroundImage, (WINDOWWIDTH, WINDOWHEIGHT))

    #Title
titleImage = pygame.image.load('title.png').convert_alpha()
rescaledTitle = pygame.transform.scale(titleImage, (WINDOWWIDTH, WINDOWHEIGHT))

    #start room lit
startRoomLitImage = pygame.image.load('Background1lit.png')
rescaledstartRoomLit = pygame.transform.scale(startRoomLitImage, (WINDOWWIDTH, WINDOWHEIGHT))

    #toture room
tortureRoomImage=pygame.image.load('Background1-tortureRoom.png')
tortureRoomRect = tortureRoomImage.get_rect
rescaledTortureRoom = pygame.transform.scale(tortureRoomImage, (WINDOWWIDTH, WINDOWHEIGHT))

    #Hall
hallImage = pygame.image.load('Background1-Hall.png')
rescaledHall = pygame.transform.scale(hallImage, (WINDOWWIDTH, WINDOWHEIGHT))

    #Hall2
hallImage2 = pygame.image.load('Background1-Hall2.png')
rescaledHall2 = pygame.transform.scale(hallImage, (WINDOWWIDTH ,WINDOWHEIGHT))

# show the "Start" screen
windowSurface.blit(rescaledTitle, (0, 0)) 
drawText('Press Enter to start', font, windowSurface, (WINDOWWIDTH / 2) - 180, (WINDOWHEIGHT / 3) + 125)
pygame.display.update()
waitForPlayerToPressKey()
while True:
    # set up start of game

    playerRect.topleft = (WINDOWWIDTH / 2, WINDOWHEIGHT - 50)
    moveLeft = moveRight =False
    moveUp = moveDown = False
    startRoom = True
    Lit = False
    Hall=False
    Hall2 = False
    tortureRoom= False

    while True: # the game loop runs while the game part is playing
        for event in pygame.event.get():
            if event.type == QUIT:
                terminate()

            if event.type == KEYDOWN:
                if event.key == K_LEFT or event.key == ord('a'):
                    moveRight = False
                    moveLeft = True
                if event.key == K_RIGHT or event.key == ord('d'):
                    moveLeft = False
                    moveRight = True
                if event.key == K_UP or event.key == ord('w'):
                    moveUp = True
                    moveDown = False
                if event.key == K_DOWN or event.key == ord('s'):
                    moveUp = False
                    moveDown = True
            if event.type == KEYUP:
                if event.key == K_ESCAPE:
                        terminate()

                if event.key == K_LEFT or event.key == ord('a'):
                    moveLeft = False
                if event.key == K_RIGHT or event.key == ord('d'):
                    moveRight = False
                if event.key == K_DOWN or event.key == ord('s'):
                    moveDown = False
                if event.key == K_UP or event.key == ord('w'):
                    moveUp = False
                    # Move the player around.
        if moveLeft and playerRect.left > 0:
            playerRect.move_ip(-10, 0)
        if moveRight and playerRect.right < WINDOWWIDTH:
            playerRect.move_ip(10, 0)
        if moveUp and playerRect.bottom > 0:
            playerRect.move_ip(0,-10)
        if moveDown and playerRect.bottom < WINDOWHEIGHT:
            playerRect.move_ip(0, +10)

        if moveLeft== True:
            windowSurface.blit(playerRotateL,(playerRect.centerx,playerRect.centery))
        if moveRight== True:
            windowSurface.blit(playerRotateR, (playerRect.centerx,playerRect.centery))
        if moveUp== True:
            windowSurface.blit(playerRotateU, (playerRect.centerx,playerRect.centery))
        if moveDown== True:
            windowSurface.blit(playerRotateD, (playerRect.centerx,playerRect.centery))
        if not moveLeft == True and moveRight== False and moveDown == False:
            windowSurface.blit(playerImage, (playerRect.centerx,playerRect.centery))

        # update the display
        mainClock.tick(5000)
        
        

        pygame.display.flip()

        # Draw the game world on the window.

        if playerRect.bottom > 300 and playerRect.right < 320:
            tortureRoom = False
            Hall2 = True
            Hall = False
            startRoom = False

        if playerRect.bottom < 405 and playerRect.centery > 295:
            Hall = True
            startRoom = False
            tortureRoom = False
            Hall2 = False

        if playerRect.bottom < 295 and playerRect.right > 319:
            tortureRoom = True
            Hall = False
            startRoom = False
            Hall2 = False

        if playerRect.bottom > 405:
            startRoom = True
            Hall = False
            tortureRoom = False
            Hall2 = False
            
        if startRoom==True:
            Hall= False
            tortureRoom=False
            windowSurface.blit(rescaledBackground, (0, 0))
            windowSurface.blit(scissorsImage, (500,410))

        if Lit == True:
           windowSurface.blit(rescaledstartRoomLit,(0,0))
           windowSurface.blit(scissorsImage, (500,410))

        if tortureRoom == True:
            windowSurface.blit(rescaledTortureRoom, (0,0))
            
        if Hall == True:
            windowSurface.blit(rescaledHall, (0,0))

        if Hall2 == True:
            windowSurface.blit(hallImage2, (0,0))

        # Draw the player's rectangle, rails
        playerRect.centerx - 1, playerRect.centery - 20, (playerRect.centerx - 1, 0), 1
        pygame.display.update(playerRect)
        pygame.display.flip()




