0

I have been trying to create a simple multiplayer game in Python using pygame, everyting was working smoothly until I linked the menu to the gameplay screen. No if I press play the game freezes and I have to force the program to stop, any ideas?

This is the function that is called one the play button is clicked:

def play():
    while True:
        SCREEN.blit(TempMap, (0, 0))
        player = Player(1280/2, 720/2)
        player.draw(SCREEN)
        PLAY_MOUSE_POS = pygame.mouse.get_pos()

        #SCREEN.fill("black")
         #Player Initialization
        
        

        
       

        PLAY_BACK = Button(image=None, pos=(100, 50), 
                            text_input="EXIT", font=get_font(30), base_color="White", hovering_color="Green")

        PLAY_BACK.changeColor(PLAY_MOUSE_POS)
        PLAY_BACK.update(SCREEN)
        #Player Initialization
        #player = Player(1280/2, 720/2)
        

 
        while True:
           for event in pygame.event.get():
               if event.type == pygame.QUIT:
                   pygame.quit()
                   sys.exit()
               if event.type == pygame.MOUSEBUTTONDOWN:
                    if PLAY_BACK.checkForInput(PLAY_MOUSE_POS):
                         main_menu()
               if event.type == pygame.KEYDOWN:
                      if event.key == pygame.K_LEFT:
                               player.left_pressed = True
                      if event.key == pygame.K_RIGHT:
                                player.right_pressed = True
                      if event.key == pygame.K_UP:
                                 player.up_pressed = True
                      if event.key == pygame.K_DOWN:
                                 player.down_pressed = True
               if event.type == pygame.KEYUP:
                      if event.key == pygame.K_LEFT:
                              player.left_pressed = False
                      if event.key == pygame.K_RIGHT:
                               player.right_pressed = False
                      if event.key == pygame.K_UP:
                               player.up_pressed = False
                      if event.key == pygame.K_DOWN:
                               player.down_pressed = False
   
        #pygame.display.update()
        #player.draw(SCREEN)
        #update
        player.update()
        pygame.display.flip()
        clock.tick(120)
Rabbid76
  • 202,892
  • 27
  • 131
  • 174

0 Answers0