CODING/Python/Escape.py DATA/Escape 6-4-13.py
2026-01-19 17:54:17 -05:00

309 lines
9.2 KiB
Python

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)
Area1 = False
Area2 = False
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
self.reset = False
#images
self.i0 = pygame.image.load('TexturePack/Player/Player.png')
self.i1 = pygame.image.load('TexturePack/Player/Player1.png')
self.i2 = pygame.image.load('TexturePack/Player/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))
if self.reset == True:
self.x = 500
self.y = 570
self.reset = False
pygame.display.flip()
def area1():
# Draw the game world on the window.
# set up start of game
startRoom = False
Lit = False
Hall=False
HallWay = False
tortureRoom= False
windowSurface.fill(BLACK)
if Player.y < 368 and Player.y > 270:
Hall = True
startRoom = False
tortureRoom = False
HallWay = False
if Player.y < 270 and Player.x > 319:
tortureRoom = True
Hall = False
startRoom = False
HallWay = False
if Player.y > 368:
startRoom = True
Hall = False
tortureRoom = False
HallWay = False
if Player.x < 319 and Player.y < 300:
tortureRoom = False
HallWay = True
Hall = False
startRoom = False
if startRoom==True:
Hall= False
tortureRoom=False
windowSurface.blit(rescaledBackground, (0, 0))
windowSurface.blit(scissorsImage, (500,410))
if HallWay == True:
windowSurface.blit(hallImage2, (0,0))
if Lit == True:
windowSurface.blit(rescaledstartRoomLit,(0,0))
windowSurface.blit(scissorsImage, (505,414))
if tortureRoom == True:
windowSurface.blit(rescaledTortureRoom, (0,0))
if Hall == True:
windowSurface.blit(rescaledHall, (0,0))
Player.render()
def area2():
Hall2 = False
Hall3 = False
Bathroom = False
SaveRoom1 = False
Player.reset = True
windowSurface.fill(BLACK)
if Player.x > 650:
Bathroom = True
if Player.x < 435:
SaveRooom1 = True
if Player.y < (WINDOWHEIGHT -10) and Player.x > 435 and Player.x < 650:
Hall3 = True
if Bathroom == True:
windowSurface.blit(rescaledBathroom, (0,0))
if SaveRoom1 == True:
windowSurface.blit(SaveRoom1Image, (0,0))
if Hall3 == True:
windowSurface.blit(rescaledHall3, (0,0))
Player.render()
# set up pygame, the window, and the mouse cursor
pygame.init()
mainClock = pygame.time.Clock()
windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), pygame.FULLSCREEN)
backgroundSurface = pygame.Surface
pygame.display.set_caption('ESCAPE')
pygame.mouse.set_visible(True)
# set up fonts
font = pygame.font.SysFont(None, 48)
#Images
#area1
#scissors
scissorsImage = pygame.image.load('TexturePack/area1/scissors.png')
scissorsRect = scissorsImage.get_rect()
#startroom
backgroundImage = pygame.image.load('TexturePack/area1/background1.png')
rescaledBackground = pygame.transform.scale(backgroundImage, (WINDOWWIDTH, WINDOWHEIGHT))
#Title
titleImage = pygame.image.load('TexturePack/area1/title.png').convert_alpha()
rescaledTitle = pygame.transform.scale(titleImage, (WINDOWWIDTH, WINDOWHEIGHT))
#start room lit
startRoomLitImage = pygame.image.load('TexturePack/area1/Background1lit.png')
rescaledstartRoomLit = pygame.transform.scale(startRoomLitImage, (WINDOWWIDTH, WINDOWHEIGHT))
#toture room
tortureRoomImage=pygame.image.load('TexturePack/area1/Background1-tortureRoom.png')
tortureRoomRect = tortureRoomImage.get_rect
rescaledTortureRoom = pygame.transform.scale(tortureRoomImage, (WINDOWWIDTH, WINDOWHEIGHT))
#Hall
hallImage = pygame.image.load('TexturePack/area1/Background1-Hall.png')
rescaledHall = pygame.transform.scale(hallImage, (WINDOWWIDTH, WINDOWHEIGHT))
#HallWay
hallImage2 = pygame.image.load('TexturePack/area1/Background1-Hall2.png')
rescaledHallWay = pygame.transform.scale(hallImage, (WINDOWWIDTH ,WINDOWHEIGHT))
#images, area2
#bathroom
BathroomImage = pygame.image.load('TexturePack/area2/Bathroom.png')
rescaledBathroom = pygame.transform.scale(BathroomImage, (WINDOWWIDTH, WINDOWHEIGHT))
#Hall2
Hall2Image = pygame.image.load('TexturePack/area2/Hall2.png')
rescaledHall2 = pygame.transform.scale(Hall2Image, (WINDOWWIDTH, WINDOWHEIGHT))
#Hall3
Hall3Image = pygame.image.load('TexturePack/area2/Hall3.png')
rescaledHall3 = pygame.transform.scale(Hall3Image, (WINDOWWIDTH, WINDOWHEIGHT))
#SaveRoom1
SaveRoom1Image = pygame.image.load('TexturePack/area2/SaveRoom1.png')
rescaledSaveRoom1 = pygame.transform.scale(SaveRoom1Image, (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()
Area1 = True
Area2 = False
Player = Sprite(500,570)
PlayerA1y = Player.y
while True:
moveLeft = moveRight =False
moveUp = moveDown = 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-30:
Player.x += 5
if moveUp and Player.y > 0:
Player.y += -5
if moveDown and Player.y < WINDOWHEIGHT-30:
Player.y += 5
# update the display
mainClock.tick(60)
if Player.y <30:
Area1 = False
Area2 = True
pygame.time.delay(10)
if Area1 == True:
area1()
if Area2 == True:
area2()