I am beginner and have a problem with my code. Here you can see a short excerpt of my code.
It\'s a simple snake game I created but I was trying to add a pause. I got it
I editet my code to this one:
def checkquit(e): running = True pause = False for ev in e: if ev.type == pygame.QUIT: exit(0) running = False pause = False
if ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE:
quit(0)
running = False
pause = False
if ev.type == pygame.KEYDOWN and ev.key == pygame.K_p:
pause = True
running = False
while pause:
pause = True
red = (255,0,0)
screen = pygame.display.set_mode((800,800))
screen.fill((0,0,0))
myfont=pygame.font.SysFont("monospace",50)
myfonttwo=pygame.font.SysFont("monospace",10)
myfonttwo=pygame.font.SysFont("monospace",10)
text1=myfont.render("Pause!",100,red)
text2=myfont.render("Please resume your game!",100,red)
text3=myfont.render("Game starts in 10 seconds!",100,red)
screen.blit(text2,(50,200))
screen.blit(text1,(300,100))
screen.blit(text3,(0,300))
pygame.display.update()
pygame.time.delay(4500)
if ev.type == pygame.KEYDOWN and ev.key == pygame.K_p:
pause = False
And it works very good! Thanks for your advices!