Categories
Development Python

python pygame pause function

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 but when I start the pause I am not able to close it. Possibly there is a basic mistake in my code so I couldn’t advance. I hope you can help me.
Thank you in advance!

def checkquit(e):
    running = True
    pause = False
    for ev in e:
        if ev.type == pygame.QUIT:
            exit(0)
            running = True

        if ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE:
            quit(0)
            running = True

        if ev.type == pygame.KEYDOWN and ev.key == pygame.K_p:
            pause = True




    while pause:
        #running = False
        pause = True   
        red = (255,0,0)
        screen = pygame.display.set_mode((800,500))
        screen.fill((0,0,0))
        myfont=pygame.font.SysFont("monospace",50)
        myfonttwo=pygame.font.SysFont("monospace",10)
        text1=myfont.render("Pause!",100,red)
        text2=myfont.render("Please restart the game",100,red)
        screen.blit(text2,(10,200))
        screen.blit(text1,(230,100))
        pygame.display.update()

        for ev in e:
            if ev.type == pygame.QUIT:
                pause = False
            if ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE:
                pause = False      
            if ev.type == pygame.KEYDOWN and ev.key == pygame.K_p:
                pause = True

Leave a Reply

Your email address will not be published. Required fields are marked *