import pygame, random, sys, time from pygame.locals import * #set up some variables WINDOWWIDTH = 1000 WINDOWHEIGHT = 550 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) class Sprite: def __init__(self,x,y): #demensions self.x=x self.y=y self.width=30 self.height=30 #images self.i0 = pygame.image.load('Player.png') self.i1 = pygame.image.load('Player1.png') self.i2 = pygame.image.load('Player2.png') #image Rotation self.i0L=pygame.transform.rotate(self.i0,90) self.i0R=pygame.transform.rotate(self.i0,270) self.i0U=pygame.transform.rotate(self.i0, 0) self.i0D=pygame.transform.rotate(self.i0, 180) #frame update self.timeTarget=10 self.timeNum=0 self.currentImage=0 self.face = 0 def render(self): if (self.currentImage==0): if moveLeft == True: self.face=1 if moveRight == True: self.face=2 if moveUp == True: self.face=0 if moveDown == True: self.face=3 if self.face == 1: windowSurface.blit(self.i0L, (self.x, self.y)) if self.face == 2: windowSurface.blit(self.i0R, (self.x, self.y)) if self.face == 0: windowSurface.blit(self.i0U, (self.x, self.y)) if self.face == 3: windowSurface.blit(self.i0D, (self.x, self.y)) pygame.display.flip() # set up pygame, the window, and the mouse cursor pygame.init() mainClock = pygame.time.Clock() windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT)) backgroundSurface = pygame.Surface pygame.display.set_caption('ESCAPE') pygame.mouse.set_visible(True) # set up fonts font = pygame.font.SysFont(None, 48) #Images #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() Player = Sprite(500, 500) while True: # set up start of game 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 Player.x > 0: Player.x += -5 if moveRight and Player.x < WINDOWWIDTH: Player.x += 5 if moveUp and Player.y > 0: Player.y += -5 if moveDown and Player.y < WINDOWHEIGHT-22: Player.y += 5 # Draw the game world on the window. windowSurface.fill(BLACK) if Player.y > 300 and Player.x < 350: tortureRoom = False Hall2 = True Hall = False startRoom = False if Player.y < 368 and Player.y > 280: Hall = True startRoom = False tortureRoom = False Hall2 = False if Player.y < 280 and Player.x > 319: tortureRoom = True Hall = False startRoom = False Hall2 = False if Player.y > 368: 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)) # update the display mainClock.tick(60) Player.render() pygame.display.flip()