Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pygame can't create if statment for restart screen?

Im trying to create a code for creating restart section. I created a variable and set to True.
And said if that variable true do everything in game if not press space and restart the game.
Now space bar now working and games not restarting. What is wrong? And every time I ask something on this site I get bullied over here so take it easy Im pretty new.

Code:

    if game_active:

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE and player_rect.bottom >= 300:
                player_gravity = -20
    else:
        if event.type == pygame.KEYDOWN and pygame.K_SPACE:
            game_active = True

Code for setting false to game_active when player and enemy collapse:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

        if snail_rect.colliderect(player_rect):
            game_active = False

        else:
            screen.fill('Yellow')

>Solution :

You need to do

if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:

You missed the event.key part.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading