I'm trying to create a way in pygame for the player to skip the tutorial phase simply by pressing "escape". However, I can't seem to get it to work when using the following:
for event in pygame.event.get():
if event.type == pygame.K_ESCAPE:
brek2 = True
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
run2 = False
brek = True
if brek or brek2:
break
pygame.time.delay(1000)
if brek:
break
Here's the full loop of the tutorial phase if you need it:
while run2:
# intro sequence
pygame.event.pump()
fade(screen_width, screen_height, BLACK)
fade(screen_width, screen_height, WHITE)
techi = pygame.transform.scale(pygame.image.load("Techi-Joe.gif"), (75, 75))
bg = pygame.Surface((screen_width, screen_height))
bg.fill(WHITE)
win.blit(pygame.transform.scale(bg, (screen_width, screen_height)), (0, 0))
win.blit(techi, (100, 600))
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
run2 = False
pygame.time.delay(1000)
brek2 = False
presss = 1
brek = False
techi_bubble = pygame.transform.scale(pygame.image.load("techi_speech_bubble.png"), (700, 350))
techi_font = pygame.font.Font('Consolas.ttf', 25)
for a in range(len(techi_says)):
win.blit(pygame.transform.scale(bg, (screen_width, screen_height)), (0, 0))
win.blit(techi_bubble, (175, 300))
win.blit(techi, (100, 600))
writeLikeCode(techi_says[a], 235, 350, techi_font, 20)
for event in pygame.event.get():
if event.type == pygame.K_ESCAPE:
brek2 = True
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
run2 = False
brek = True
if brek or brek2:
break
pygame.time.delay(1000)
if brek:
break
Here's some addition code referenced as function writeLikeCode:
techi_says = ["Hello, User!", "My name is Techi-Joe.", "I'm a programmer,", "and this is my first game:",
"Dunk the Chief!", "in Dunk the Chief,", "your main objective", "is to dunk any US president", "you choose",
"in a cold tub of water!", "yay!"]
# writeLikeCode function
def writeLikeCode(string, xpos, ypos, font, fontsize):
for x in range(len(string)):
lstring = split(string)
text = font.render(lstring[x], 1, GREEN)
win.blit(text, (xpos + (x * fontsize), ypos))
pygame.time.delay(50)
pygame.display.update()
and here's the split function:
def split(string):
return [char for char in string]