예제 #1
0
def opening_screen(ai_settings, game_stats, screen):
    """Display the menu in the beginning"""

    # Set up screen attributes
    menu = Intro(ai_settings, game_stats, screen)
    play_button = Button(ai_settings, screen, 'Play Game', y_factor=0.70)
    hs_button = Button(ai_settings, screen, 'High Scores', y_factor=0.80)
    intro = True

    # Manages the key presses of the game
    while intro:
        for events in pygame.event.get():
            if events.type == pygame.QUIT:
                return False
            elif events.type == pygame.MOUSEBUTTONDOWN:
                click_x, click_y = pygame.mouse.get_pos()
                game_stats.game_active = play_button.check_button(click_x, click_y)
                intro = not game_stats.game_active
                if hs_button.check_button(click_x, click_y):
                    ret_hs = high_score_screen(ai_settings, screen)
                    if not ret_hs:
                        return False

        screen.fill(ai_settings.bg_color)
        # Allow the menu to display on the top layer
        menu.show_menu()
        # Draw the button on the main screen
        hs_button.draw_button()
        play_button.draw_button()

        # Display past
        pygame.display.flip()

    return True
예제 #2
0
def startup_screen(ai_settings, game_stats, screen):
    """Display the startup menu on the screen, return False if the user wishes to quit,
    True if they are ready to play"""
    menu = Intro(ai_settings, game_stats, screen)
    play_button = Button(ai_settings, screen, 'Play Game', y_factor=0.70)
    hs_button = Button(ai_settings, screen, 'High Scores', y_factor=0.80)
    intro = True

    while intro:
        play_button.alter_text_color(*pygame.mouse.get_pos())
        hs_button.alter_text_color(*pygame.mouse.get_pos())
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False
            elif event.type == pygame.MOUSEBUTTONDOWN:
                click_x, click_y = pygame.mouse.get_pos()
                game_stats.game_active = play_button.check_button(
                    click_x, click_y)
                intro = not game_stats.game_active
                if hs_button.check_button(click_x, click_y):
                    ret_hs = high_score_screen(ai_settings, game_stats, screen)
                    if not ret_hs:
                        return False
        screen.fill(ai_settings.bg_color)
        menu.show_menu()
        hs_button.draw_button()
        play_button.draw_button()
        pygame.display.flip()

    return True
예제 #3
0
def startup_screen(config, game_stats, screen):
    """Display an introductory startup screen for the game, return False if the user wishes to quit,
    True if the user is ready to play"""
    title_screen = Intro(config, game_stats, screen)
    title_screen.prep_image()
    button = Button(config, screen, 'Play')
    intro = True

    while intro:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False
            elif event.type == pygame.MOUSEBUTTONDOWN:
                click_x, click_y = pygame.mouse.get_pos()
                game_stats.game_active = button.check_button(click_x, click_y)
                intro = not game_stats.game_active
        screen.fill(config.bg_color)
        title_screen.show_menu()
        button.draw_button()
        pygame.display.flip()

    return True