0
\$\begingroup\$

Video as you can see there I am trying to make my end screen restart my game but whats happening is that its not restarting my game its just loading the same thing when I die >> how could I make it so it restarts my game when I click start game on my end screen?

my end screen def

---------------------------------------------------

def button(msg,x,y,w,h,ic,ac,action=None):
    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()

    if x+w > mouse[0] > x and y+h > mouse[1] > y:
        pygame.draw.rect(window, ac,(x,y,w,h))
        if click[0] == 1 and action != None:
            action()         
    else:
        pygame.draw.rect(window, ic,(x,y,w,h))
    smallText = pygame.font.SysFont("comicsansms",20)
    textSurf, textRect = text_objects(msg, smallText)
    textRect.center = ( (x+(w/2)), (y+(h/2)) )
    window.blit(textSurf, textRect)

#------------------------------------------------------


def text_objects(text, font):
    textSurface = font.render(text, True, black)
    return textSurface, textSurface.get_rect()

def endScreen():
    red = (200,0,0)
    green = (0,200,0)
    bright_red = (255,0,0)
    bright_green = (0,255,0)

    intro = True
    while intro:
        for event in pygame.event.get():
            #print(event)
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        window.fill((255,255,255))
        largeText = pygame.font.Font('BLOODY.ttf',100)
        TextSurf, TextRect = text_objects("You Have Died Fool", largeText)
        TextRect.center = ((800/2), (800/2))
        window.blit(TextSurf, TextRect)
        button("Start Game",150,450,100,50,green,bright_green,game_loop)

# make the square brighter if collideded with the buttons
        mouse = pygame.mouse.get_pos()
        if 150+120 > mouse[0] > 150 and 450+50 > mouse[1] > 450:
            pygame.draw.rect(window, bright_green,(150,450,120,50))
        else:
            pygame.draw.rect(window, green,(150,450,120,50))
        if 550+110 > mouse[0] > 550 and 450+50 > mouse[1] > 450:
            pygame.draw.rect(window, bright_red,(550,450,110,50))
        else:
            pygame.draw.rect(window, red,(550,450,110,50))
# ---------------------------------------------------------------------

        smallText = pygame.font.Font("freesansbold.ttf",20)
        textSurf, textRect = text_objects("Start Game", smallText)
        textRect.center = ( (150+(120/2)), (450+(50/2)) )
        window.blit(textSurf, textRect)


        smallText = pygame.font.Font("freesansbold.ttf",20)
        textSurf, textRect = text_objects("Quit Game", smallText)
        textRect.center = ( (150+(910/2)), (450+(50/2)) )
        window.blit(textSurf, textRect)


        pygame.display.update()
        clock.tick(15)



#----------------------------------------------------------


and on my main loop I said if my playerman health is > -1 it should load the end screen


            if playerman.health < -5:
                endScreen()

```
\$\endgroup\$
6
  • \$\begingroup\$ even if I put it on my endScreen the game will not reload my enemies and everything I want it to reload my whole game when I click play again \$\endgroup\$ Jun 11, 2020 at 1:40
  • \$\begingroup\$ Have you considered setting the variables to the values you want when you click play? \$\endgroup\$
    – DMGregory
    Jun 11, 2020 at 1:41
  • \$\begingroup\$ no I dont know how to its my first time trying to make an end screen sorry if I am annoying you \$\endgroup\$ Jun 11, 2020 at 2:16
  • \$\begingroup\$ Then you might want to show us your code where those variables are first initialized. \$\endgroup\$
    – DMGregory
    Jun 11, 2020 at 2:18
  • 1
    \$\begingroup\$ Please edit your question to include the relevant code, not an external paste link. \$\endgroup\$
    – DMGregory
    Jun 11, 2020 at 2:34

1 Answer 1

0
\$\begingroup\$

You can have a boolean variable like playing that you set to True when you enter the game. Then, when you load the endscreen you set it to False. Then, when you press the try again button, set it back to True to enter the loop again.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .