def title_screen(screen, screen_rect):
    in_title_screen = True

    # Load
    background_image = load_image(background_file)
    main_title_image = load_image('ccc_pumptrack_attack_title.png')

    # Main Theme
    load_music(main_theme)
    pygame.mixer.music.play(-1)

    while in_title_screen:
        for event in pygame.event.get():
            if event.type == pygame.QUIT or event.type == pygame.KEYDOWN:
                return

        # Draw Background
        background_rect = background_image.get_rect()
        background_rect.left, background_rect.top = [0, 0]
        screen.fill(colors.white)
        screen.blit(background_image, background_rect)

        main_title_image_rect = main_title_image.get_rect()
        main_title_image_rect.center = (screen_rect.size[0] / 2 + 20,
                                        screen_rect.size[1] / 2 - 80)
        screen.blit(main_title_image, main_title_image_rect)

        press_any_key = text_format("Press any key to continue", MENU_FONT, 18,
                                    colors.white)
        press_any_key_rect = press_any_key.get_rect()
        press_any_key_rect.center = (screen_rect.size[0] / 2, 500)
        screen.blit(press_any_key, press_any_key_rect)

        pygame.display.update()
        clock.tick(30)
Пример #2
0
def leaderboard_menu(screen, menu_logos):
    in_leaderboard_menu = True

    # Load
    background_image = load_image(background_file)
    menu_line = load_image(menu_line_file)
    leaderboard_list = load_leaderboard()

    while in_leaderboard_menu:
        for event in pygame.event.get():
            if event.type == pygame.QUIT or \
                    (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
                return

        # Draw Background
        background_rect = background_image.get_rect()
        background_rect.left, background_rect.top = [0, 0]
        screen.fill([255, 255, 255])
        screen.blit(background_image, background_rect)

        # Draw Logos
        menu_logos.draw(screen)

        title = text_format(TITLE_TEXT, MENU_FONT, 50, colors.white)
        screen.blit(title, (150, 220))

        position_header_text = text_format("POSITION", MENU_FONT, 16,
                                           colors.white)
        screen.blit(position_header_text, (150, 300))
        time_header_text = text_format("TIME (seconds)", MENU_FONT, 16,
                                       colors.white)
        screen.blit(time_header_text, (300, 300))
        name_header_text = text_format("NAME", MENU_FONT, 16, colors.white)
        screen.blit(name_header_text, (500, 300))

        screen.blit(menu_line, (150, 320))

        for place in range(10):
            y_position = 330 + place * 16
            place_text = text_format(
                str(place + 1) + ".", MENU_FONT, 16, colors.white)
            time_text = text_format(leaderboard_list[place][0], MENU_FONT, 16,
                                    colors.white)
            name_text = text_format(leaderboard_list[place][1], MENU_FONT, 16,
                                    colors.white)
            screen.blit(place_text, (150, y_position))
            screen.blit(time_text, (300, y_position))
            screen.blit(name_text, (500, y_position))

        screen.blit(menu_line, (150, 500))

        press_escape_text = text_format(
            "Press 'Escape' key to return to the Main Menu", MENU_FONT, 16,
            colors.white)
        screen.blit(press_escape_text, (150, 520))

        pygame.display.update()
        clock.tick(30)
Пример #3
0
def splash_intro(screen):
    intro = True

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

        screen.fill(black)

        splash_fps = fileUtils.load_image("fps_logo.png")
        splash_fps_rect = splash_fps.get_rect()
        splash_fps_rect.center = (DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2)

        splash_ccc = fileUtils.load_image("ccc_logo.png")
        splash_ccc = pygame.transform.smoothscale(splash_ccc, (300, 300))
        splash_ccc_rect = splash_ccc.get_rect()
        splash_ccc_rect.center = (DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2)

        splash_pygame = fileUtils.load_image("pygame-badge-SMA.png")
        splash_pygame_rect = splash_pygame.get_rect()
        splash_pygame_rect.center = (DISPLAY_WIDTH / 2, DISPLAY_HEIGHT / 2)

        fade_in(screen, splash_fps, splash_fps_rect)
        pygame.time.wait(1000)
        fade_out(screen, splash_fps, splash_fps_rect)

        fade_in(screen, splash_ccc, splash_ccc_rect)
        pygame.time.wait(1000)
        fade_out(screen, splash_ccc, splash_ccc_rect)

        fade_in(screen, splash_pygame, splash_pygame_rect)
        pygame.time.wait(1000)
        fade_out(screen, splash_pygame, splash_pygame_rect)

        intro = False
Пример #4
0
def settings_menu(menu_logos):
    menu = True
    selected = 0

    # Load
    background_image = load_image(background_file)
    menu_line = load_image(menu_line_file)

    while menu:
        for event in pygame.event.get():
            if event.type == pygame.QUIT or \
                    (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
                return
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    if selected <= 0:
                        selected = len(menu_options) - 1
                    else:
                        selected -= 1
                elif event.key == pygame.K_DOWN:
                    if selected == len(menu_options) - 1:
                        selected = 0
                    else:
                        selected += 1
                if event.key == pygame.K_RETURN:
                    if selected == 0:
                        change_sound_volume()
                    if selected == 1:
                        change_music_volume()
                    if selected == 2:
                        toggle_full_screen()
                    if selected == 3:
                        menu = False

        # Draw Background
        background_rect = background_image.get_rect()
        background_rect.left, background_rect.top = [0, 0]
        screen = pygame.display.get_surface()
        screen.fill([255, 255, 255])
        screen.blit(background_image, background_rect)

        # Draw Logos
        menu_logos.draw(screen)

        # Main Menu UI
        # screen.fill(colors.light_blue)
        title = text_format(TITLE_TEXT, MENU_FONT, 50, colors.white)
        sfx_volume = MENU_SFX_VOLUME + str(int(pygame.mixer.Channel(0).get_volume() * 10))
        music_volume = MENU_MUSIC_VOLUME + str(int(pygame.mixer.music.get_volume()*10))
        full_screen_mode = MENU_FULL_SCREEN_MODE + is_full_screen()
        if selected == 0:
            text_start = text_format(sfx_volume, MENU_FONT, 25, colors.white)
        else:
            text_start = text_format(sfx_volume, MENU_FONT, 25, colors.light_gray)
        if selected == 1:
            text_settings = text_format(music_volume, MENU_FONT, 25, colors.white)
        else:
            text_settings = text_format(music_volume, MENU_FONT, 25, colors.light_gray)
        if selected == 2:
            text_credits = text_format(full_screen_mode, MENU_FONT, 25, colors.white)
        else:
            text_credits = text_format(full_screen_mode, MENU_FONT, 25, colors.light_gray)
        if selected == 3:
            text_quit = text_format(MENU_RETURN, MENU_FONT, 25, colors.white)
        else:
            text_quit = text_format(MENU_RETURN, MENU_FONT, 25, colors.light_gray)

        text_option_description = text_format(menu_options_descriptions[selected], MENU_FONT, 16, colors.white)

        # Main Menu Text
        screen.blit(title, (150, 220))
        screen.blit(menu_line, (150, 320))
        screen.blit(text_start, (150, 340))
        screen.blit(text_settings, (150, 370))
        screen.blit(text_credits, (150, 400))
        screen.blit(text_quit, (150, 460))
        screen.blit(menu_line, (150, 500))
        screen.blit(text_option_description, (150, 520))
        pygame.display.update()
        clock.tick(30)
Пример #5
0
 def __init__(self):
     self.menu_line = load_image(menu_line_file)
Пример #6
0
def main_menu(screen, screen_rect):
    menu = True
    selected = 0
    menu_logos = MenuLogos()

    # Load
    background_image = load_image(background_file)
    menu_line = load_image(menu_line_file)
    menu_logos.load()

    while menu:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    if selected <= 0:
                        selected = len(menu_options) - 1
                    else:
                        selected -= 1
                elif event.key == pygame.K_DOWN:
                    if selected == len(menu_options) - 1:
                        selected = 0
                    else:
                        selected += 1
                if event.key == pygame.K_RETURN:
                    if selected == 0:
                        game_play(screen, screen_rect)
                    if selected == 1:
                        settings_menu(menu_logos)
                    if selected == 2:
                        leaderboard_menu(screen, menu_logos)
                    if selected == 3:
                        credits_menu(screen, menu_logos)
                    if selected == 4:
                        pygame.quit()
                        quit()

        # Draw Background
        background_rect = background_image.get_rect()
        background_rect.left, background_rect.top = [0, 0]
        screen.fill([255, 255, 255])
        screen.blit(background_image, background_rect)

        # Draw Logos
        menu_logos.draw(screen)

        # Main Menu UI
        title = text_format(TITLE_TEXT, MENU_FONT, 50, colors.white)
        if selected == 0:
            text_start = text_format(MENU_START, MENU_FONT, 25, colors.white)
        else:
            text_start = text_format(MENU_START, MENU_FONT, 25,
                                     colors.light_gray)
        if selected == 1:
            text_settings = text_format(MENU_SETTINGS, MENU_FONT, 25,
                                        colors.white)
        else:
            text_settings = text_format(MENU_SETTINGS, MENU_FONT, 25,
                                        colors.light_gray)
        if selected == 2:
            text_leaderboard = text_format(MENU_LEADERBOARD, MENU_FONT, 25,
                                           colors.white)
        else:
            text_leaderboard = text_format(MENU_LEADERBOARD, MENU_FONT, 25,
                                           colors.light_gray)
        if selected == 3:
            text_credits = text_format(MENU_CREDITS, MENU_FONT, 25,
                                       colors.white)
        else:
            text_credits = text_format(MENU_CREDITS, MENU_FONT, 25,
                                       colors.light_gray)
        if selected == 4:
            text_quit = text_format(MENU_QUIT, MENU_FONT, 25, colors.white)
        else:
            text_quit = text_format(MENU_QUIT, MENU_FONT, 25,
                                    colors.light_gray)

        text_option_description = text_format(
            menu_options_descriptions[selected], MENU_FONT, 16, colors.white)

        # Main Menu Text
        screen.blit(title, (150, 220))
        screen.blit(menu_line, (150, 320))
        screen.blit(text_start, (150, 340))
        screen.blit(text_settings, (150, 370))
        screen.blit(text_leaderboard, (150, 400))
        screen.blit(text_credits, (150, 430))
        screen.blit(text_quit, (150, 460))
        screen.blit(menu_line, (150, 500))
        screen.blit(text_option_description, (150, 520))
        pygame.display.update()
        clock.tick(30)
 def __init__(self):
     self.menu_line = load_image(menu_line_file)
     self.leaderboard_list = load_leaderboard()
Пример #8
0
def game_play(screen, screen_rect):
    playing = True
    game_state = GameState.STARTING
    number_of_laps = 2

    # Load images, assign to sprite classes
    img = fileUtils.load_image('rider1-placeholder.png')
    Player.images = [img, pygame.transform.flip(img, 1, 0)]

    # decorate the game window
    # icon = pygame.transform.scale(Rider.images[0], (32, 32))
    # pygame.display.set_icon(icon)
    # pygame.display.set_caption('Pygame Aliens')
    # pygame.mouse.set_visible(0)

    # create the background, tile the bgd image
    background = fileUtils.load_image('pumptrack.png')
    background_rect = background.get_rect()
    screen.blit(background, background_rect)
    pygame.display.flip()

    background_in_alpha = pygame.Surface(
        (screen_rect.size[0], screen_rect.size[1]))
    background_in_alpha.set_alpha(128)
    background_in_alpha.fill(colors.black)

    # load the sound effects
    # shoot_sound = load_sound('car_door.wav')
    """if pygame.mixer:
        music = os.path.join(main_dir, 'data', 'house_lo.wav')
        pygame.mixer.music.load(music)
        pygame.mixer.music.play(-1)"""
    # fileUtils.load_music("Lame_Drivers_-_01_-_Frozen_Egg.mp3")
    # pygame.mixer.music.play(-1)

    # Initialize Game Groups
    aliens = pygame.sprite.Group()
    all = pygame.sprite.RenderUpdates()
    lastalien = pygame.sprite.GroupSingle()

    # assign default groups to each sprite class
    Player.containers = all
    Rider.containers = aliens, all, lastalien
    TimeCounter.containers = all

    # Create Some Starting Values
    clock = pygame.time.Clock()

    # initialize our starting sprites
    player = Player(screen_rect, way_points_pump_track, True)
    time_counter = TimeCounter()
    time_countdown = CountDown()
    game_over = GameOverScreen()
    pause_menu = PauseScreen()
    if pygame.font:
        all.add(time_counter)

    button_down = False

    while playing:

        # get input
        for event in pygame.event.get():
            game_over_state = game_over.update_input(event)
            if game_over_state == GameOverState.RESTART:
                game_state = GameState.RESTART
            elif game_over_state == GameOverState.QUIT:
                return

            quit_game = pause_menu.update_input(event)
            if quit_game:
                return

            if event.type == pygame.QUIT \
                    or (event.type == pygame.KEYDOWN
                        and event.key == pygame.K_ESCAPE
                        and game_state == GameState.PLAYING):
                game_state = GameState.PAUSED

            if event.type == pygame.KEYDOWN \
                    and event.key == pygame.K_SPACE \
                    and button_down is False \
                    and game_state == GameState.PLAYING:
                button_down = True

        all.clear(screen, background)
        all.update()
        # player.update_state(game_state)
        time_counter.set_state(game_state)
        time_countdown.set_state(game_state)
        game_over.set_state(game_state)
        time_countdown.update()

        if time_countdown.countdown <= 0 and game_state == GameState.STARTING:
            game_state = GameState.PLAYING
            screen.blit(background, background_rect)
            pygame.display.flip()

        if game_state == GameState.PLAYING:
            player.pump()
            if button_down is True:
                player.add_pump()
                button_down = False
            if player.lap >= number_of_laps:
                game_state = GameState.GAME_OVER
                game_over.set_final_time(time_counter.time_in_millis)

        if game_state == GameState.STARTING:
            time_countdown.draw(screen, screen_rect, background,
                                background_in_alpha)
            pygame.display.update()

        if game_state == GameState.PAUSED:
            pause_menu.draw(screen, screen_rect, background,
                            background_in_alpha)
            pygame.display.update()

        if game_state == GameState.GAME_OVER:
            game_over.draw(screen, screen_rect, background,
                           background_in_alpha)
            pygame.display.update()

        if game_state == GameState.RESTART:
            clock = pygame.time.Clock()
            player = Player(screen_rect, way_points_pump_track, True)
            time_counter = TimeCounter()
            time_countdown = CountDown()
            game_state = GameState.STARTING

        dirty = all.draw(screen)
        pygame.display.update(dirty)

        clock.tick(30)
def credits_menu(screen, menu_logos):
    in_credits_menu = True
    selected = 0

    # Load
    background_image = load_image(background_file)
    menu_line = load_image(menu_line_file)

    while in_credits_menu:
        for event in pygame.event.get():
            if event.type == pygame.QUIT or \
                    (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
                return
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    if selected <= 0:
                        selected = len(menu_options) - 1
                    else:
                        selected -= 1
                elif event.key == pygame.K_DOWN:
                    if selected == len(menu_options) - 1:
                        selected = 0
                    else:
                        selected += 1
                if event.key == pygame.K_RETURN:
                    if selected == 0:
                        go_to_web(CCC_URL)
                    if selected == 1:
                        go_to_web(CCC_FACEBOOK_URL)
                    if selected == 2:
                        return

        # Draw Background
        background_rect = background_image.get_rect()
        background_rect.left, background_rect.top = [0, 0]
        screen.fill([255, 255, 255])
        screen.blit(background_image, background_rect)

        # Draw Logos
        menu_logos.draw(screen)

        title = text_format(TITLE_TEXT, MENU_FONT, 50, colors.white)
        screen.blit(title, (150, 220))

        developed_by = text_format(
            "DEVELOPED BY FERRAN PONS (PROGRAMMING AND GRAPHICS)", MENU_FONT,
            16, colors.white)
        screen.blit(developed_by, (150, 300))

        screen.blit(menu_line, (150, 320))

        if selected == 0:
            text_ccc_about = text_format(MENU_ABOUT_CCC, MENU_FONT, 25,
                                         colors.white)
        else:
            text_ccc_about = text_format(MENU_ABOUT_CCC, MENU_FONT, 25,
                                         colors.light_gray)
        if selected == 1:
            text_ccc_facebook = text_format(MENU_GO_TO_WEB, MENU_FONT, 25,
                                            colors.white)
        else:
            text_ccc_facebook = text_format(MENU_GO_TO_WEB, MENU_FONT, 25,
                                            colors.light_gray)
        if selected == 2:
            text_quit = text_format(MENU_RETURN, MENU_FONT, 25, colors.white)
        else:
            text_quit = text_format(MENU_RETURN, MENU_FONT, 25,
                                    colors.light_gray)

        text_option_description = text_format(
            menu_options_descriptions[selected], MENU_FONT, 16, colors.white)

        screen.blit(text_ccc_about, (150, 340))
        screen.blit(text_ccc_facebook, (150, 370))
        screen.blit(text_quit, (150, 460))
        screen.blit(menu_line, (150, 500))
        screen.blit(text_option_description, (150, 520))

        music_title_text = text_format("MUSIC", MENU_FONT, 18, colors.white)
        screen.blit(music_title_text, (800, 300))
        screw_wave = text_format("Screw Wave by Windom Earle", MENU_FONT, 16,
                                 colors.white)
        screen.blit(screw_wave, (800, 330))
        screw_wave_license = \
            text_format("licensed under a Attribution-NonCommercial-ShareAlike 3.0 International License.",
                        MENU_FONT, 10, colors.white)
        screen.blit(screw_wave_license, (800, 350))

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