0

Hello so I am having problems with my code because I cannot display my loading screen I have a main menu when I press on start its brings me to the 'Splog choser' and then I have a main menu button to bring me back to the main menu So I would like to add a loading screen because there is a quit button and if you click to fast on main menu you will also quit the game

please help because I am very new to python in general

import pygame
from sys import exit

Ligth_sky_blue = 135, 206, 250

def loading_screen():
    screen.fill('Black')
    Txt_loading = font.render('Loading',True,'White')
    Txt_loading_Rect = Txt_loading.get_rect(center =(960, 540))
    screen.blit(Txt_loading,Txt_loading_Rect)

def main_menu_button():
    global game_start_init, Splog_chose_init
    mmb_surface = pygame.Surface((200, 50))
    mmb_text_surf = font.render('Main MENU',True,'Red')
    mmb_rect = mmb_surface.get_rect(center =(150, 950))
    screen.blit(mmb_surface,mmb_rect)
    screen.blit(mmb_text_surf,mmb_rect)
    if any(buttons):
        if mmb_rect.collidepoint(pygame.mouse.get_pos()):
            print('main_menu_button')
            Splog_chose_init = False
            
            pygame.time.wait(2000)
            game_start_init = True
                
            

def quit_button():
    if game_start_init == True:
        quit_button_screen = pygame.Surface((200, 50))
        quit_button_rect = quit_button_screen.get_rect(center =(150,950))
        quit_button_text_surf = font.render('Quit Game',True,'Red')
        
        screen.blit(quit_button_screen, quit_button_rect)
        screen.blit(quit_button_text_surf,quit_button_rect)
        left, middle, right = pygame.mouse.get_pressed()
        
        if any(buttons):
            if quit_button_rect.collidepoint(pygame.mouse.get_pos()):
                if game_start_init == True:
                    print('exit')
                    pygame.quit()
                    exit()

def start_button():
    global game_start_init, Splog_chose_init
    strb_surface = pygame.Surface((200, 50))
    
    button_text_surf = font.render('Start Game',True,'Red')
    button_start_rect = strb_surface.get_rect(center =(1750, 950))
    screen.blit(strb_surface,button_start_rect)
    screen.blit(button_text_surf,button_start_rect)
    left, middle, right = pygame.mouse.get_pressed()
        
    if any(buttons):
        if button_start_rect.collidepoint(pygame.mouse.get_pos()):
                print('splogchoser')
                
                Splog_chose_init = True
                
                pygame.time.wait(2000)
                game_start_init = False

def Splogs_choser(color):
    global game_start_init,Splog_chose_init
    game_start_init = False
    screen.fill(color)
    Ssc_text_intro = font.render('You may now chose a Splog !!',True,'White')
    Ssc_text_intro_rect = Ssc_text_intro.get_rect(center = (960, 150))
    screen.blit(Ssc_text_intro,Ssc_text_intro_rect)
    main_menu_button()
    
    

def title_screen(color):
    
    screen.fill(color)
    Ttl_text_gn = font.render('Welcome to SPLOGS GAME V6',True,'White')
    Ttl_text_gn_rect = Ttl_text_gn.get_rect(center = (960, 150))
    screen.blit(Ttl_text_gn,Ttl_text_gn_rect)
    quit_button()
    start_button()
    
    

pygame.init()
screen = pygame.display.set_mode((1920, 1080))
pygame.display.set_caption('SPLOGS GAME V6')
font = pygame.font.Font('Fonts/Dungeonfont.ttf', 50)
clock = pygame.time.Clock()


icon = pygame.image.load('Graphs/Icon/SG2.png')
pygame.display.set_icon(icon)
game_start_init = True
Splog_chose_init = False





while True:
    buttons = pygame.mouse.get_pressed()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                pygame.quit()
                exit()
        
    if game_start_init == True:
        
        title_screen(Ligth_sky_blue)
    elif Splog_chose_init == True:
        
        Splogs_choser(Ligth_sky_blue)
    else:
        loading_screen()
    pygame.display.flip()
    clock.tick(60)
pludot
  • 1
  • The problem is `pygame.time.wait(2000)`. See [How to wait some time in pygame?](https://stackoverflow.com/questions/18839039/how-to-wait-some-time-in-pygame) – Rabbid76 Apr 23 '22 at 10:37

0 Answers0