Beispiel #1
0
def score_screen():
    pygame.init()
    ai_settings = Settings()
    score_scr = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Space Invaders")

    music = pygame.mixer.Sound("Sounds/space_music.wav")

    play_button = Button(ai_settings, score_scr, "Start", (600, 50))

    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, score_scr, stats)
    a = gm.store_score(stats, score_scr)

    y = 0

    gm.display_scores(a, score_scr, y)

    while True:
        music.play()
        gm.check_button_press(play_button, ai_settings, stats, sb)

        if stats.game_active:
            run_game()
        elif not stats.game_active:
            play_button.draw_button()
        pygame.display.flip()
Beispiel #2
0
def start_screen():
    pygame.init()
    ai_settings = Settings()
    start_scr = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Space Invaders")

    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, start_scr, stats)

    music = pygame.mixer.Sound("Sounds/space_music.wav")

    play_button = Button(ai_settings, start_scr, "Start", (600, 50))
    score_button = Button(ai_settings, start_scr, "Highscore", (600, 750))
    score_button.msg_image_rect.center = 600, 750

    a = gm.display_alien_start_screen(ai_settings, start_scr)
    gm.score1(start_scr)

    while True:
        music.play()
        gm.check_button_press(play_button, ai_settings, stats, sb)
        if stats.game_active:
            run_game()
        elif not stats.game_active:
            play_button.draw_button()
            score_button.draw_button()

        a = gm.score_menu(score_button, ai_settings, stats, sb)
        if a is True:
            score_screen()

        pygame.display.flip()
Beispiel #3
0
def startup_screen(settings, stats, screen, menu_aliens, menu_ufos):
    """Display the startup menu on the screen, return False if the user wishes to quit,
    True if they are ready to play"""
    menu = Intro(settings, stats, screen)
    play_button = Button(settings, screen, 'Play Game', y_factor=0.75)
    hs_button = Button(settings, screen, 'High Scores', y_factor=0.85)
    intro = True

    while intro:
        play_button.alter_text_color(*pg.mouse.get_pos())
        hs_button.alter_text_color(*pg.mouse.get_pos())
        for event in pg.event.get():
            if event.type == pg.QUIT:
                return False
            elif event.type == pg.MOUSEBUTTONDOWN:
                click_x, click_y = pg.mouse.get_pos()
                stats.game_active = play_button.check_button(click_x, click_y)
                intro = not stats.game_active
                if hs_button.check_button(click_x, click_y):
                    ret_hs = high_score_screen(settings, stats, screen)
                    if not ret_hs:
                        return False
        screen.fill(settings.bg_color)
        menu.draw()
        hs_button.draw_button()
        play_button.draw_button()
        menu_aliens.draw()
        menu_ufos.draw()
        pg.display.flip()

    return True
Beispiel #4
0
def high_score_screen(settings, stats, screen):
    """Display all high scores in a separate screen with a back button"""
    hs_screen = HighScoreScreen(settings, screen, stats)
    back_button = Button(settings, screen, 'Back To Menu', y_factor=0.85)

    while True:
        back_button.alter_text_color(*pg.mouse.get_pos())
        for event in pg.event.get():
            if event.type == pg.QUIT:
                return False
            elif event.type == pg.MOUSEBUTTONDOWN:
                if back_button.check_button(*pg.mouse.get_pos()):
                    return True
        screen.fill(settings.bg_color)
        hs_screen.show_scores()
        back_button.draw_button()
        pg.display.flip()