268 lines
8.5 KiB
Python
268 lines
8.5 KiB
Python
|
|
import pygame, random, sys, time
|
|
from pygame.locals import *
|
|
|
|
|
|
#set up some variables
|
|
WINDOWWIDTH = 1024
|
|
WINDOWHEIGHT = 600
|
|
FPS = 60
|
|
TEXTCOLOR = (140, 0, 0)
|
|
BLACK = (0,0,0)
|
|
BLUE = (0, 0, 255)
|
|
RED = (255, 0, 0)
|
|
|
|
# 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))
|
|
backgroundStart = pygame.Surface((WINDOWWIDTH,WINDOWHEIGHT))
|
|
#Title
|
|
titleImage = pygame.image.load('title.png').convert_alpha()
|
|
rescaledTitle = pygame.transform.scale(titleImage, (WINDOWWIDTH, WINDOWHEIGHT))
|
|
Title = pygame.Surface ((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))
|
|
backgroundTor = pygame.Surface ((WINDOWWIDTH,WINDOWHEIGHT))
|
|
#Hall
|
|
hallImage = pygame.image.load('Background1-Hall.png')
|
|
rescaledHall = pygame.transform.scale(hallImage, (WINDOWWIDTH, WINDOWHEIGHT))
|
|
backgroundHall = pygame.Surface((WINDOWWIDTH,WINDOWHEIGHT))
|
|
#Hall2
|
|
hallImage2 = pygame.image.load('Background1-Hall2.png')
|
|
rescaledHall2 = pygame.transform.scale(hallImage, (WINDOWWIDTH ,WINDOWHEIGHT))
|
|
backgroundHall2 = pygame.Surface((WINDOWWIDTH,WINDOWHEIGHT))
|
|
|
|
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)
|
|
|
|
def Area1():
|
|
# update the display
|
|
moveLeft = moveRight =()
|
|
moveUp = moveDown = ()
|
|
startRoom = ()
|
|
Lit = ()
|
|
Hall=()
|
|
Hall2 = ()
|
|
tortureRoom= ()
|
|
# Draw the player's rectangle, rails
|
|
playerRect.centerx - 1, playerRect.centery - 20, (playerRect.centerx - 1, 0), 1
|
|
pygame.display.update(playerRect)
|
|
|
|
pygame.display.flip()
|
|
|
|
# Draw the game world on the window.
|
|
|
|
# Hall2
|
|
if playerRect.bottom > 300 and playerRect.right < 320:
|
|
tortureRoom = False
|
|
Hall2 = True
|
|
Hall = False
|
|
startRoom = False
|
|
pygame.display.update(playerRect)
|
|
|
|
# Hall
|
|
if playerRect.bottom < 405 and playerRect.centery > 300:
|
|
Hall = True
|
|
startRoom = False
|
|
tortureRoom = False
|
|
Hall2 = False
|
|
pygame.display.update(playerRect)
|
|
|
|
# tortureRoom
|
|
if playerRect.bottom < 295 and playerRect.right > 319:
|
|
tortureRoom = True
|
|
Hall = False
|
|
startRoom = False
|
|
Hall2 = False
|
|
pygame.display.update(playerRect)
|
|
|
|
#startRoom
|
|
if playerRect.bottom > 405:
|
|
startRoom = True
|
|
Hall = False
|
|
tortureRoom = False
|
|
Hall2 = False
|
|
pygame.display.update(playerRect)
|
|
|
|
while startRoom==True:
|
|
Hall = False
|
|
Hall2 = False
|
|
tortureRoom = False
|
|
break
|
|
|
|
while Hall==True:
|
|
startRoom = False
|
|
Hall2 = False
|
|
tortureRoom = False
|
|
break
|
|
|
|
while Hall2==True:
|
|
Hall = False
|
|
startRoom = False
|
|
tortureRoom = False
|
|
break
|
|
|
|
while tortureRoom==True:
|
|
Hall = False
|
|
Hall2 = False
|
|
startRoom = False
|
|
break
|
|
|
|
if startRoom==True:
|
|
Hall= False
|
|
tortureRoom=False
|
|
Hall2=False
|
|
backgroundStart.blit(rescaledBackground, (0, 0))
|
|
backgroundStart.blit(scissorsImage, (500,410))
|
|
windowSurface.blit(backgroundStart, (0,0))
|
|
|
|
if Lit == True:
|
|
windowSurface.blit(rescaledstartRoomLit,(0,0))
|
|
windowSurface.blit(scissorsImage, (500,410))
|
|
|
|
if tortureRoom == True:
|
|
Hall=False
|
|
Hall2=False
|
|
startRoom=False
|
|
backgroundTor.blit(rescaledTortureRoom, (0,0))
|
|
windowSurface.blit(backgroundTor, (0,0))
|
|
|
|
if Hall == True:
|
|
startRoom = False
|
|
tortureRoom = False
|
|
Hall2 = False
|
|
backgroundHall.blit(rescaledHall, (0,0))
|
|
windowSurface.blit(backgroundHall, (0,0))
|
|
|
|
if Hall2 == True:
|
|
startRoom=False
|
|
tortureRoom=False
|
|
Hall=False
|
|
backgroundHall2.blit(hallImage2, (0,0))
|
|
windowSurface.blit(backgroundHall2, (0,0))
|
|
|
|
# show the "Start" screen
|
|
Title.blit(rescaledTitle, (0, 0))
|
|
windowSurface.blit(Title,(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))
|
|
|
|
|
|
Area1()
|
|
|
|
|