Home > Blockchain >  Pygame can't create if statment for restart screen?
Pygame can't create if statment for restart screen?

Time:01-22

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:

        if snail_rect.colliderect(player_rect):
            game_active = False

        else:
            screen.fill('Yellow')

CodePudding user response:

You need to do

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

You missed the event.key part.

  • Related