Esempio n. 1
0
def dead(score):
    COLOR_BLACK = (0, 0, 0)
    COLOR_WHITE = (255, 255, 255)
    MENU_BACKGROUND_COLOR = (123, 160, 91)
    WINDOW_SIZE = (win_w, win_h)

    def Pass():
        pass

    font1 = 'sprites/bebas.ttf'
    font2 = 'sprites/8bit.ttf'

    dead_menu = pygameMenu.TextMenu(surface=win,
                                    bgfun=Pass,
                                    color_selected=COLOR_WHITE,
                                    font=font1,
                                    font_color=COLOR_BLACK,
                                    font_size=30,
                                    menu_alpha=50,
                                    font_title=font2,
                                    font_size_title=25,
                                    menu_color=MENU_BACKGROUND_COLOR,
                                    menu_height=int(WINDOW_SIZE[1] * 0.2),
                                    menu_width=int(WINDOW_SIZE[0] * 0.3),
                                    onclose=pygameMenu.events.DISABLE_CLOSE,
                                    option_shadow=False,
                                    title='Game Over',
                                    window_height=WINDOW_SIZE[1],
                                    window_width=WINDOW_SIZE[0],
                                    mouse_enabled=False,
                                    mouse_visible=False)

    dead_menu.add_line(f'Your score      {score}')
    dead_menu.add_option('Return to menu', dead_menu.disable)
    dead_menu.mainloop(pygame.event.get())
Esempio n. 2
0
    def __init__(self, surface, clock, start_game_function):
        self._surface = surface
        self._clock = clock

        path = harmonize_path(
            os.path.join(os.path.dirname(__file__),
                         "../resources/sprites/cropped_floor.png"))
        self._background_image = pygame.image.load(path).convert()

        self.main_menu = pygameMenu.Menu(
            self._surface,
            bgfun=self.bg_func,
            color_selected=Menu.WHITE,  # ausgewähltes Menüelement
            font="resources/fonts/VCR_OSD_MONO_1.001.ttf",
            # pygameMenu.font.FONT_BEBAS,
            font_color=Menu.WHITE,
            font_size=50,
            menu_alpha=100,
            menu_color=Menu.BG_COLOR,
            menu_color_title=Menu.BG_TITLE_COLOR,
            menu_height=int(WINDOW_SIZE[1] * 0.8),
            menu_width=int(WINDOW_SIZE[0] * 0.9),
            onclose=pygameMenu.events.DISABLE_CLOSE,
            option_shadow=False,
            title='GREEDY ROYALS',
            window_height=WINDOW_SIZE[1],
            window_width=WINDOW_SIZE[0])

        self.highscore_menu = pygameMenu.TextMenu(
            self._surface,
            bgfun=self.bg_func,
            font="resources/fonts/VCR_OSD_MONO_1.001.ttf",
            font_color=Menu.WHITE,
            font_size=50,
            menu_alpha=100,
            menu_color=Menu.BG_COLOR,
            menu_color_title=Menu.BG_TITLE_COLOR,
            menu_width=int(WINDOW_SIZE[0] * 0.8),
            menu_height=int(WINDOW_SIZE[1] * 0.8),
            title="Highscore",
            option_shadow=False,
            window_height=WINDOW_SIZE[1],
            window_width=WINDOW_SIZE[0],
            # TextMenu specific parameters
            draw_text_region_x=TEXT_DRAW_X,
            text_align=pygameMenu.locals.ALIGN_CENTER,
            text_color=Menu.BG_TITLE_COLOR,
            text_fontsize=20,
            text_margin=TEXT_MARGIN,
        )

        # create DB if necessary and fill highscore list
        Highscore.create_db()
        self.fill_highscore_list()

        self.main_menu.add_option('Play', start_game_function)
        # main_menu.add_option('About', about_menu)
        self.main_menu.add_option('Highscore', self.highscore_menu)
        self.main_menu.add_option('Quit', pygameMenu.events.EXIT)
Esempio n. 3
0
def text_menu_func():
    return pygameMenu.TextMenu(screen,
                               window_width=glob.WINDOW_SIZE[0] - 600,
                               window_height=glob.WINDOW_SIZE[1] - 100,
                               font=pygameMenu.font.FONT_FRANCHISE,
                               title='STAR WARS MENU',
                               bgfun=main_background,
                               menu_width=glob.MENU_SIZE[0],
                               menu_height=glob.MENU_SIZE[1])
Esempio n. 4
0
def text_menu_align_func():
    return pygameMenu.TextMenu(screen,
                               window_width=glob.WINDOW_SIZE[0] - 600,
                               window_height=glob.WINDOW_SIZE[1] - 100,
                               font=pygameMenu.font.FONT_FRANCHISE,
                               font_size=30,
                               text_align=pygameMenu.locals.ALIGN_CENTER,
                               title='STAR WARS MENU',
                               bgfun=main_background,
                               menu_width=glob.MENU_SIZE[0],
                               menu_height=glob.MENU_SIZE[1])
Esempio n. 5
0
    def init_suspect_menu(self, screen, initiator, responder, cards):
        screen_width, screen_height = screen.get_size()
        text_menu = pygameMenu.TextMenu(
            screen,
            dopause=False,
            font=pygameMenu.fonts.FONT_FRANCHISE,
            menu_color=(30, 50, 107),  # Background color
            menu_color_title=(120, 45, 30),
            menu_width=600,
            menu_height=300,
            onclose=pygameMenu.locals.
            PYGAME_MENU_CLOSE,  # Pressing ESC button does nothing
            title='Suspection',
            window_height=screen_height,
            window_width=screen_width)
        text_menu.add_line(responder.upper())
        line_1 = "The player " + initiator.upper(
        ) + " has accused " + self.who_accusation.upper() + " of the"
        line_2 = "murder in the " + self.where_accusation.upper(
        ) + " with the " + self.what_accusation.upper()
        text_menu.add_line(line_1)
        text_menu.add_line(line_2)
        text_menu.add_option('Back', pygameMenu.locals.PYGAME_MENU_BACK)

        self.suspect_menu = pygameMenu.Menu(
            screen,
            dopause=False,
            enabled=False,
            font=pygameMenu.fonts.FONT_NEVIS,
            menu_alpha=85,
            menu_color=(0, 0, 0),  # Background color
            menu_color_title=(255, 0, 0),
            menu_height=400,
            menu_width=1200,
            onclose=pygameMenu.locals.PYGAME_MENU_CLOSE,
            # If this menu closes (press ESC) back to main
            title=responder.upper() + ': Suspection',
            title_offsety=5,  # Adds 5px to title vertical position
            window_height=screen_height,
            window_width=screen_width)
        self.suspect_menu.add_option('View Suspection', text_menu)
        self.suspect_menu.add_selector('Give card?',
                                       cards,
                                       onchange=self.update_card_given,
                                       onreturn=self.update_card_given,
                                       default=1)
        self.suspect_menu.add_option('Give', self.give_card)
        self.suspect_menu.add_option('Pass', self.pass_turn)
        self.menu_list.append(self.suspect_menu)
Esempio n. 6
0
 def init_illegal_move_menu(self, screen, message_number):
     screen_width, screen_height = screen.get_size()
     self.illegal_move_menu = pygameMenu.TextMenu(
         screen,
         dopause=False,
         font=pygameMenu.fonts.FONT_FRANCHISE,
         menu_color=(30, 50, 107),  # Background color
         menu_color_title=(120, 45, 30),
         menu_width=600,
         menu_height=200,
         onclose=pygameMenu.locals.
         PYGAME_MENU_CLOSE,  # Pressing ESC button does nothing
         title='Illegal Move',
         window_height=screen_height,
         window_width=screen_width)
     self.illegal_move_menu.add_line(self.error_messages[message_number])
Esempio n. 7
0
    def init_general_message_menu(self, screen, message_number, param=None):
        screen_width, screen_height = screen.get_size()
        self.general_message_menu = pygameMenu.TextMenu(
            screen,
            dopause=False,
            font=pygameMenu.fonts.FONT_FRANCHISE,
            menu_color=(30, 50, 107),  # Background color
            menu_color_title=(120, 45, 30),
            menu_width=600,
            menu_height=200,
            onclose=pygameMenu.locals.PYGAME_MENU_CLOSE,
            # Pressing ESC button does nothing
            title='General Message',
            window_height=screen_height,
            window_width=screen_width)

        message = self.general_messages[message_number]
        if message_number == 0:
            message = "Player " + str(param[0]) + message + str(param[1])
            self.general_message_menu.add_line(message)

            # Update the last message
            self.update_status_info(last_message="Recent: " + message)

        elif message_number == 5:
            message = "Player " + str(param) + " " + message
            self.general_message_menu.add_line(message)

            # Update the last message
            self.update_status_info(last_message="Recent: " + message)

        elif message_number == 6:
            line_1 = "Player " + str(param[0]) + " has accused " + str(
                param[1]) + " of the"
            line_2 = "murder in the " + str(param[2]) + " with the " + str(
                param[3]) + "."
            line_3 = "Waiting for other players to respond"
            full_message = line_1 + " " + line_2
            self.general_message_menu.add_line(line_1)
            self.general_message_menu.add_line(line_2)
            self.general_message_menu.add_line(line_3)

            # Update the last message
            self.update_status_info(last_message="Recent: " + full_message)

        else:
            self.general_message_menu.add_line(message)
Esempio n. 8
0
def run_show_round(app: App, winner: Player):
    menu = pygameMenu.TextMenu(
        app.screen,
        *app.conf.pixel_size.as_ints(),
        font=pygameMenu.fonts.FONT_8BIT,
        title='Good Job',
        dopause=False
    )
    menu.add_line("Player %i scored" % winner.player_id)

    while app.app_state == AppState.STAGE_END:
        events = pg.event.get()
        for event in events:
            if event.type == QUIT:
                exit()
            if event.type == pg.KEYUP and (event.key == pg.K_ESCAPE or event.key == pg.K_RETURN):
                app.new_round()
        menu.mainloop(events)
        pg.display.flip()
Esempio n. 9
0
def create_menu(menu_title, font_size=30):
    return pygameMenu.TextMenu(GAME_ENV.surface,
                               bgfun=main_background,
                               color_selected=COLOR_WHITE,
                               font=MENU_FONT,
                               font_color=COLOR_BLACK,
                               font_size_title=30,
                               font_title=pygameMenu.font.FONT_8BIT,
                               menu_color=MENU_BACKGROUND_COLOR,
                               menu_color_title=COLOR_WHITE,
                               menu_height=int(WINDOW_SIZE[1] * 0.6),
                               menu_width=int(WINDOW_SIZE[0] * 0.6),
                               onclose=pygameMenu.events.DISABLE_CLOSE,
                               option_shadow=False,
                               text_color=COLOR_BLACK,
                               font_size=font_size,
                               title=menu_title,
                               window_height=WINDOW_SIZE[1],
                               window_width=WINDOW_SIZE[0])
Esempio n. 10
0
def create_activity_menu():
    '''
    Create and return a TextMenu for how many hours slept
    '''
    activity_menu = pygameMenu.TextMenu(surface=screen,
                                        bgfun=menu_background,
                                        enabled=False,
                                        font=pygameMenu.fonts.FONT_NEVIS,
                                        menu_alpha=90,
                                        onclose=pygameMenu.locals.PYGAME_MENU_CLOSE,
                                        title='Exercise',
                                        title_offsety=5,
                                        window_height=SCREEN_HEIGHT,
                                        window_width=SCREEN_WIDTH)
    activity_menu.add_selector(title='Active Minutes',
                               values=MINUTES_SELECTORS,
                               onchange=None,
                               onreturn=update_activity)

    return activity_menu
Esempio n. 11
0
def create_sleep_menu():
    '''
    Create and return a TextMenu for how many hours slept
    '''
    sleep_menu = pygameMenu.TextMenu(surface=screen,
                                     bgfun=menu_background,
                                     enabled=False,
                                     font=pygameMenu.fonts.FONT_NEVIS,
                                     menu_alpha=90,
                                     onclose=pygameMenu.locals.PYGAME_MENU_CLOSE,
                                     title='Sleep',
                                     title_offsety=5,
                                     window_height=SCREEN_HEIGHT,
                                     window_width=SCREEN_WIDTH)
    sleep_menu.add_selector(title='Hours Slept',
                            values=NUMBER_SELECTORS,
                            onchange=None,
                            onreturn=update_sleep)

    return sleep_menu
Esempio n. 12
0
def create_food_menu():
    '''
    Create and return a TextMenu for selecting what has been eaten.
    '''
    food_menu = pygameMenu.TextMenu(surface=screen,
                                    bgfun=menu_background,
                                    enabled=False,
                                    font=pygameMenu.fonts.FONT_NEVIS,
                                    menu_alpha=90,
                                    onclose=pygameMenu.locals.PYGAME_MENU_CLOSE,
                                    title='Eat',
                                    title_offsety=5,
                                    window_height=SCREEN_HEIGHT,
                                    window_width=SCREEN_WIDTH)
    for m in FOODS:
        food_menu.add_selector(title=m,
                               values=NUMBER_SELECTORS,
                               onchange=None,
                               onreturn=update_nutrition,
                               food_type=m)

    return food_menu
Esempio n. 13
0
def win_menu():
    win_menu = pygameMenu.TextMenu(surface,
                                   bgfun=no,
                                   back_box=False,
                                   color_selected=DARKRED,
                                   font=pygameMenu.font.FONT_BEBAS,
                                   font_color=COLOR_BLACK,
                                   font_size=24,
                                   menu_alpha=100,
                                   font_size_title=30,
                                   font_title=pygameMenu.font.FONT_BEBAS,
                                   menu_color_title=MENU_BACKGROUND_COLOR,
                                   menu_color=COLOR_WHITE,
                                   menu_height=int(WINDOW_SIZE[1] * 0.5),
                                   menu_width=int(WINDOW_SIZE[0] * 0.5),
                                   onclose=pygameMenu.events.DISABLE_CLOSE,
                                   option_shadow=False,
                                   text_color=COLOR_BLACK,
                                   text_fontsize=20,
                                   text_align=pygameMenu.locals.ALIGN_CENTER,
                                   title='You Won!',
                                   window_height=WINDOW_SIZE[1],
                                   window_width=WINDOW_SIZE[0])

    win_menu.add_line("Congratulations!")
    win_menu.add_line("You beat the game :)")
    win_menu.add_button('Quit', run_menu)

    while True:
        # Tick
        clock.tick(FPS)

        # Main menu
        win_menu.mainloop()

        # Flip surface
        pygame.display.flip()
Esempio n. 14
0
def main():
    """
    Main program.

    :param test: Indicate function is being tested
    :type test: bool
    :return: None
    """

    # -------------------------------------------------------------------------
    # Globals
    # -------------------------------------------------------------------------
    global clock
    global main_menu
    global surface

    # -------------------------------------------------------------------------
    # Init pygame
    # -------------------------------------------------------------------------
    pygame.init()
    os.environ['SDL_VIDEO_CENTERED'] = '1'

    # Create pygame screen and objects
    surface = pygame.display.set_mode(WINDOW_SIZE)
    pygame.display.set_caption('SennAI')
    clock = pygame.time.Clock()

    #Setup menus, using pygamemenu

    # Play menu
    play_menu = pygameMenu.Menu(surface,
                                bgfun=main_background,
                                color_selected=COLOUR_WHITE,
                                font=pygameMenu.font.FONT_BEBAS,
                                font_color=COLOUR_BLACK,
                                font_size=30,
                                menu_alpha=100,
                                menu_color=MENU_BACKGROUND_COLOUR,
                                menu_height=int(WINDOW_SIZE[1] * 0.7),
                                menu_width=int(WINDOW_SIZE[0] * 0.7),
                                onclose=pygameMenu.events.DISABLE_CLOSE,
                                option_shadow=False,
                                title='Play menu',
                                window_height=WINDOW_SIZE[1],
                                window_width=WINDOW_SIZE[0])

    play_submenu = pygameMenu.Menu(surface,
                                   bgfun=main_background,
                                   color_selected=COLOUR_WHITE,
                                   font=pygameMenu.font.FONT_BEBAS,
                                   font_color=COLOUR_BLACK,
                                   font_size=30,
                                   menu_alpha=100,
                                   menu_color=MENU_BACKGROUND_COLOUR,
                                   menu_height=int(WINDOW_SIZE[1] * 0.5),
                                   menu_width=int(WINDOW_SIZE[0] * 0.7),
                                   option_shadow=False,
                                   title='Submenu',
                                   window_height=WINDOW_SIZE[1],
                                   window_width=WINDOW_SIZE[0])

    #upon click you'll return to the main menu
    play_submenu.add_option('Back', pygameMenu.events.BACK)

    #play menu
    play_menu.add_option('Start', play_function, DIFFICULTY,
                         pygame.font.Font(pygameMenu.font.FONT_FRANCHISE, 30))

    #selects either 5000aft or 10000aft
    play_menu.add_selector('Select difficulty', [('1 - Easy', 'EASY'),
                                                 ('2 - Normal', 'NORMAL')],
                           onchange=change_difficulty,
                           selector_id='select_difficulty')
    #play_menu.add_option('Another menu', play_submenu)
    play_menu.add_option('Return to main menu', pygameMenu.events.BACK)

    # Leaderboard menu
    leaderboard_menu = pygameMenu.TextMenu(
        surface,
        bgfun=main_background,
        color_selected=COLOUR_WHITE,
        font=pygameMenu.font.FONT_BEBAS,
        font_color=COLOUR_BLACK,
        font_size_title=30,
        font_title=pygameMenu.font.FONT_8BIT,
        menu_color=MENU_BACKGROUND_COLOUR,
        menu_color_title=COLOUR_WHITE,
        menu_height=int(WINDOW_SIZE[1] * 0.6),
        menu_width=int(WINDOW_SIZE[0] * 0.6),
        onclose=pygameMenu.events.DISABLE_CLOSE,
        option_shadow=False,
        text_color=COLOUR_BLACK,
        text_fontsize=20,
        title='Leaderboard',
        window_height=WINDOW_SIZE[1],
        window_width=WINDOW_SIZE[0])

    #FIX
    #leaderboard prior was only printing the first five times ever recorded, now wil display the top
    #five times
    i = 0
    #sort last digits of a string
    for l in sorted(leaderboard,
                    key=lambda x: int(re.search(r'\d+$', x).group())):
        if i == 5:
            break
        leaderboard_menu.add_line(l)
        i += 1

    leaderboard_menu.add_line(pygameMenu.locals.TEXT_NEWLINE)
    leaderboard_menu.add_option('Return to menu', pygameMenu.events.BACK)

    train_menu = pygameMenu.Menu(surface,
                                 bgfun=main_background,
                                 color_selected=COLOUR_WHITE,
                                 font=pygameMenu.font.FONT_BEBAS,
                                 font_color=COLOUR_BLACK,
                                 font_size=30,
                                 menu_alpha=100,
                                 menu_color=MENU_BACKGROUND_COLOUR,
                                 menu_height=int(WINDOW_SIZE[1] * 0.7),
                                 menu_width=int(WINDOW_SIZE[0] * 0.7),
                                 onclose=pygameMenu.events.DISABLE_CLOSE,
                                 option_shadow=False,
                                 title='training menu',
                                 window_height=WINDOW_SIZE[1],
                                 window_width=WINDOW_SIZE[0])

    #descriptive text needs to be included at top
    train_menu.add_option(
        'Start',  # When pressing return -> play(DIFFICULTY[0], font)
        train_function,
        DIFFICULTY,
        pygame.font.Font(pygameMenu.font.FONT_FRANCHISE, 30))

    #replace with number field
    train_menu.add_selector('Generation to train to', [
        ('0', '0'),
        ('50', '50'),
        ('100', '100'),
        ('1000', '1000'),
        ('2000', '2000'),
        ('3000', '3000'),
        ('4000', '4000'),
        ('5000', '5000'),
        ('6000', '6000'),
        ('7000', '7000'),
        ('8000', '8000'),
        ('9000', '9000'),
        ('10000', '10000'),
        ('11000', '11000'),
        ('12000', '12000'),
        ('13000', '13000'),
        ('14000', '14000'),
        ('15000', '15000'),
        ('16000', '16000'),
        ('17000', '17000'),
        ('18000', '18000'),
        ('19000', '19000'),
        ('20000', '20000'),
    ],
                            onchange=change_gentotrainto,
                            selector_id='select_gentotrainto')

    train_menu.add_option('Return to main menu', pygameMenu.events.BACK)

    options_menu = pygameMenu.Menu(surface,
                                   bgfun=main_background,
                                   color_selected=COLOUR_WHITE,
                                   font=pygameMenu.font.FONT_BEBAS,
                                   font_color=COLOUR_BLACK,
                                   font_size=30,
                                   menu_alpha=100,
                                   menu_color=MENU_BACKGROUND_COLOUR,
                                   menu_height=int(WINDOW_SIZE[1] * 0.7),
                                   menu_width=int(WINDOW_SIZE[0] * 0.7),
                                   onclose=pygameMenu.events.DISABLE_CLOSE,
                                   option_shadow=False,
                                   title='options menu',
                                   window_height=WINDOW_SIZE[1],
                                   window_width=WINDOW_SIZE[0])

    # Main menu
    main_menu = pygameMenu.Menu(surface,
                                bgfun=main_background,
                                color_selected=COLOUR_WHITE,
                                font=pygameMenu.font.FONT_BEBAS,
                                font_color=COLOUR_BLACK,
                                font_size=25,
                                menu_alpha=100,
                                menu_color=MENU_BACKGROUND_COLOUR,
                                menu_height=int(WINDOW_SIZE[1] * 0.6),
                                menu_width=int(WINDOW_SIZE[0] * 0.6),
                                onclose=pygameMenu.events.DISABLE_CLOSE,
                                option_shadow=False,
                                title='SennAI',
                                window_height=WINDOW_SIZE[1],
                                window_width=WINDOW_SIZE[0])

    #options submenus as seen from main menu
    main_menu.add_option('Play', play_menu)
    main_menu.add_option('Train', train_menu)
    main_menu.add_option('Leaderboard', leaderboard_menu)
    main_menu.add_option('Quit', pygameMenu.events.EXIT)

    # Configure main menu
    main_menu.set_fps(FPS)
    #Main loop
    while True:

        # Tick
        clock.tick(FPS)

        # Paint background
        main_background()

        # Application events
        events = pygame.event.get()
        for event in events:
            if event.type == pygame.QUIT:
                exit()

        # Main menu
        main_menu.mainloop(events)

        # Flip surface
        pygame.display.flip()
Esempio n. 15
0
def main():
    global GAME_STATE
    animation_frame = 0
    blit_screen(0)
    simple_menu = pygameMenu.TextMenu(SCREEN,
                                      window_width=SCREEN_WIDTH,
                                      window_height=SCREEN_HEIGHT,
                                      font=pygameMenu.font.FONT_8BIT,
                                      font_color=(255, 255, 255),
                                      enabled=False,
                                      font_size=20,
                                      title='Exit',
                                      bgfun=bg_pass,
                                      menu_alpha=100,
                                      onclose=pygameMenu.events.CLOSE,
                                      option_shadow=False,
                                      menu_color=(0, 0, 0),
                                      menu_width=300,
                                      menu_height=300)
    simple_menu.set_fps(FPS)
    simple_menu.add_option('Close Menu', pygameMenu.events.CLOSE)
    simple_menu.add_option('Exit Game', pygameMenu.events.EXIT)

    while 1:
        if GAME_STATE == 0:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                elif event.type == pygame.KEYUP:
                    if event.key == pygame.K_w:
                        PLAYER.facing_up = True
                        PLAYER.facing_left = False
                        PLAYER.key_up = False
                    if event.key == pygame.K_s:
                        PLAYER.facing_up = False
                        PLAYER.facing_left = False
                        PLAYER.key_down = False
                    if event.key == pygame.K_a:
                        PLAYER.facing_left = True
                        PLAYER.facing_up = False
                        PLAYER.key_left = False
                    if event.key == pygame.K_d:
                        PLAYER.facing_left = False
                        PLAYER.facing_up = False
                        PLAYER.key_right = False
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_w:
                        PLAYER.key_up = True
                    elif event.key == pygame.K_s:
                        PLAYER.key_down = True
                    elif event.key == pygame.K_a:
                        PLAYER.key_left = True
                    elif event.key == pygame.K_d:
                        PLAYER.key_right = True
                    if event.key == pygame.K_q:
                        simple_menu.enable()
                        PLAYER.stop()
                    if event.key == pygame.K_z:
                        for ob in GAME_OBJECTS:
                            if PLAYER.calculate_tile() == ob.grid_pos:
                                ob.flip_switch()
                    if event.key == pygame.K_e:
                        if PLAYER.calculate_tile() in RESOURCES.unbuilt:
                            GAME_STATE = 1
                            PLAYER.stop()
                    if event.key == pygame.K_SPACE:
                        if PLAYER.calculate_tile() == 12:
                            fish = FISHING.catch(True)
                            if fish == 6:
                                RESOURCES.resources[11] += 1
                            else:
                                RESOURCES.resources[
                                    fish + 5] += FISHING.catch_quantity
                        else:
                            for ob in GAME_OBJECTS:
                                if PLAYER.calculate_tile() == ob.grid_pos:
                                    RESOURCES.resources[ob.product] += 1
                    if event.key == pygame.K_1:
                        for ob in GAME_OBJECTS:
                            if PLAYER.calculate_tile() == ob.grid_pos:
                                if RESOURCES.resources[ob.upgrade_type1] >= ob.upgrade_cost1 and \
                                        RESOURCES.resources[ob.upgrade_type2] >= ob.upgrade_cost2:
                                    RESOURCES.resources[
                                        ob.upgrade_type1] -= ob.upgrade_cost1
                                    RESOURCES.resources[
                                        ob.upgrade_type2] -= ob.upgrade_cost2
                                    ob.upgrade(1)
                    if event.key == pygame.K_v:
                        for ob in GAME_OBJECTS:
                            if PLAYER.calculate_tile() == ob.grid_pos:
                                if RESOURCES.resources[ob.fuel1_type] >= 50:
                                    ob.fuel1 += 50
                                    RESOURCES.resources[ob.fuel1_type] -= 50

            PLAYER.move()
            blit_screen(animation_frame)
            simple_menu.mainloop()
            for ob in GAME_OBJECTS:
                ob.produce()
            transfer_product()
            animation_frame += 1
            if animation_frame > ANIMATION_MAX_CT:
                animation_frame = 0
            if GAME_STATE == 1:
                blit_construction_menu()

        elif GAME_STATE == 1:
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_e:
                        GAME_STATE = 0
                    if event.key == pygame.K_SPACE:
                        for fact in constants.factories.values():
                            if PLAYER.calculate_tile() == fact['grid_pos']:
                                build1 = constants.construct_menu['resources'][
                                    0]
                                build2 = constants.construct_menu['resources'][
                                    1]
                                build3 = constants.construct_menu['resources'][
                                    2]
                                build4 = constants.construct_menu['resources'][
                                    3]
                                cost1 = fact['build_cost1']
                                cost2 = fact['build_cost2']
                                cost3 = fact['build_cost3']
                                cost4 = fact['build_cost4']
                                if RESOURCES.resources[build1] >= cost1 and RESOURCES.resources[build2] >= cost2 and \
                                        RESOURCES.resources[build3] >= cost3 and RESOURCES.resources[build4] >= cost4:
                                    RESOURCES.resources[build1] -= cost1
                                    RESOURCES.resources[build2] -= cost2
                                    RESOURCES.resources[build3] -= cost3
                                    RESOURCES.resources[build4] -= cost4
                                    GAME_OBJECTS.append(
                                        game_classes.Factory(fact['name']))
                                    RESOURCES.unbuilt.remove(fact['grid_pos'])
                                    RESOURCES.can_build.remove(
                                        fact['grid_pos'])
                                    for nex in fact['build_next']:
                                        RESOURCES.can_build.append(
                                            constants.factories[nex]
                                            ['grid_pos'])
                                break
                        GAME_STATE = 0
        CLOCK.tick(FPS)
    timer_menu.add_selector(
        'Mode',
        [('AI', True)],
        onchange=None,  # Action when changing element with left/right
        onreturn=PongProductionModes.AI)
    timer_menu.add_option('Return to Menu', PYGAME_MENU_BACK)
    timer_menu.add_option('Close Menu', PYGAME_MENU_CLOSE)

    # -----------------------------------------------------------------------------
    # About menu
    about_menu = pygameMenu.TextMenu(
        surface,
        dopause=False,
        font=pygameMenu.fonts.FONT_NEVIS,
        font_size_title=30,
        font_title=pygameMenu.fonts.FONT_8BIT,
        menu_color_title=COLOR_BLUE,
        onclose=PYGAME_MENU_DISABLE_CLOSE,  # Disable menu close (ESC button)
        text_fontsize=20,
        title='About',
        window_height=H_SIZE,
        window_width=W_SIZE)
    about_menu.add_option('Return to Menu', PYGAME_MENU_BACK)
    for m in ABOUT:
        about_menu.add_line(m)
    about_menu.add_line(PYGAMEMENU_TEXT_NEWLINE)

    # -----------------------------------------------------------------------------
    # Main menu, pauses execution of the application
    menu = pygameMenu.Menu(surface,
                           bgfun=mainmenu_background,
                           enabled=False,
Esempio n. 17
0
                            option_shadow=False,
                            title='Main menu',
                            window_height=WINDOW_SIZE[1],
                            window_width=WINDOW_SIZE[0])

# About Menu where players can see information about the game
about_menu = pygameMenu.TextMenu(screen,
                                 bgfun=draw_initial_screen,
                                 color_selected=RED,
                                 font=pygameMenu.fonts.FONT_BEBAS,
                                 font_color=BLACK,
                                 font_size_title=30,
                                 font_title=pygameMenu.fonts.FONT_8BIT,
                                 menu_alpha=50,
                                 menu_color=BLACK,
                                 menu_color_title=BLUE,
                                 menu_height=int(WINDOW_SIZE[1] * 0.7),
                                 menu_width=int(WINDOW_SIZE[0] * 0.7),
                                 onclose=PYGAME_MENU_DISABLE_CLOSE,
                                 option_shadow=False,
                                 text_color=BLACK,
                                 text_fontsize=20,
                                 title='About',
                                 window_height=WINDOW_SIZE[1],
                                 window_width=WINDOW_SIZE[0])

# Help Menu where players can see information about game controls
help_menu = pygameMenu.TextMenu(screen,
                                bgfun=draw_initial_screen,
                                color_selected=RED,
                                font=pygameMenu.fonts.FONT_BEBAS,
Esempio n. 18
0
                            option_shadow=False,
                            title='Play menu',
                            window_height=WINDOW_SIZE[1],
                            window_width=WINDOW_SIZE[0]
                            )

about_menu = pygameMenu.TextMenu(surface,
                                 bgfun=main_background,
                                 color_selected=COLOR_WHITE,
                                 font="gothic.ttf",
                                 font_color=COLOR_BLACK,
                                 font_size_title=50,
                                 font_title="gothic.ttf",
                                 menu_color=MENU_BACKGROUND_COLOR,
                                 menu_color_title=COLOR_WHITE,
                                 menu_height=int(WINDOW_SIZE[1] * 0.6),
                                 menu_width=int(WINDOW_SIZE[0] * 0.6),
                                 onclose=PYGAME_MENU_DISABLE_CLOSE,
                                 option_shadow=False,
                                 text_color=COLOR_BLACK,
                                 text_fontsize=16,
                                 title='About',
                                 window_height=WINDOW_SIZE[1],
                                 window_width=WINDOW_SIZE[0]
                                 )
for m in ABOUT:
    about_menu.add_line(m)
about_menu.add_line(PYGAMEMENU_TEXT_NEWLINE)
about_menu.add_option('Return to menu', PYGAME_MENU_BACK)

board_menu = pygameMenu.TextMenu(surface,
Esempio n. 19
0
    # Action when changing element with left/right
    onchange=None,
    # Action when pressing return on a element
    onreturn=change_color_bg,
    # Kwargs, optional parametrs to change_color_bg function
    write_on_console=True)
timer_menu.add_option('Return to Menu', PYGAME_MENU_BACK)
timer_menu.add_option('Close Menu', PYGAME_MENU_CLOSE)

# Help menu
help_menu = pygameMenu.TextMenu(
    surface,
    window_width=W_SIZE,
    window_height=H_SIZE,
    font=pygameMenu.fonts.FONT_FRANCHISE,
    title='Help',
    # Pressing ESC button does nothing on this menu
    onclose=PYGAME_MENU_DISABLE_CLOSE,
    menu_color_title=(120, 45, 30),
    # Background color
    menu_color=(30, 50, 107),
    dopause=False)
help_menu.add_option('Return to Menu', PYGAME_MENU_BACK)
for m in HELP:
    help_menu.add_line(m)

# About menu
about_menu = pygameMenu.TextMenu(
    surface,
    window_width=W_SIZE,
    window_height=H_SIZE,
    font=pygameMenu.fonts.FONT_NEVIS,
Esempio n. 20
0
    def _start_menu(self):
        """
        Draw the main menu. This is the start point of the game.

        :return: bool, Execution OK
        """
        single_player_menu = pygameMenu.Menu(self.__screen,
                                             window_width=self.__width,
                                             window_height=self.__height,
                                             menu_width=self.__width,
                                             menu_height=self.__height,
                                             font=GAME_FONT,
                                             title="Single Player",
                                             menu_color_title=COLOR_BLACK,
                                             menu_color=COLOR_NEV,
                                             dopause=False)

        single_player_menu.add_option("Play", self._keep_playing,
                                      MODE_SINGLE_PLAYER)
        single_player_menu.add_selector("Difficulty",
                                        [("Easy", LEVEL_EASY),
                                         ("Medium", LEVEL_MEDIUM),
                                         ("Hard", LEVEL_HARD),
                                         ("Impossible", LEVEL_IMPOSSIBLE)],
                                        onreturn=None,
                                        onchange=self.set_difficulty)
        single_player_menu.add_option("Return to main menu", PYGAME_MENU_BACK)

        about_menu = pygameMenu.TextMenu(self.__screen,
                                         window_width=self.__width,
                                         window_height=self.__height,
                                         menu_width=self.__width,
                                         menu_height=self.__height,
                                         font=GAME_FONT,
                                         title="About",
                                         menu_color_title=COLOR_BLACK,
                                         menu_color=COLOR_NEV,
                                         dopause=False)

        for line in ABOUT:
            about_menu.add_line(line)
        about_menu.add_line(TEXT_NEWLINE)
        about_menu.add_option("Return to menu", PYGAME_MENU_BACK)

        menu = pygameMenu.Menu(self.__screen,
                               window_width=self.__width,
                               window_height=self.__height,
                               menu_width=self.__width,
                               menu_height=self.__height,
                               font=GAME_FONT,
                               title="Main Menu",
                               menu_color_title=COLOR_BLACK,
                               menu_color=COLOR_NEV,
                               dopause=False)

        menu.add_option("Single Player", single_player_menu)
        menu.add_option("2 Players", self._keep_playing, MODE_2_PLAYERS)
        menu.add_option("2 Players (LAN)", self._lan_menu)
        menu.add_option("About", about_menu)
        menu.add_option("Exit", self._quit)

        while self.__is_running:
            # Application events
            events = pygame.event.get()
            for event in events:
                if event.type == pygame.QUIT:
                    self._quit()
                    return False

            self.__screen.fill(COLOR_LIGHT_GRAY)
            menu.mainloop(events)
            self.__clock.tick(self.__fps)
Esempio n. 21
0
                       onreturn=None,
                       onchange=change_difficulty)
play_menu.add_option('Return to main menu', PYGAME_MENU_BACK)

# About_menu

about_menu = pygameMenu.TextMenu(
    main_window,
    bgfun=mainmenu_background,
    color_selected=(0, 0, 0),
    font=pygameMenu.fonts.FONT_BEBAS,
    font_color=(255, 255, 255),
    # font_size_title=30,
    # font_title=pygameMenu.fonts.FONT_8BIT,
    menu_color=(228, 55, 36),
    menu_color_title=(0, 0, 0),
    menu_height=int(height_window * 0.6),
    menu_width=int(width_window * 0.6),
    onclose=PYGAME_MENU_DISABLE_CLOSE,
    option_shadow=False,
    text_color=(255, 255, 255),
    text_fontsize=20,
    title='About',
    window_height=height_window,
    window_width=width_window)
for m in ABOUT:
    about_menu.add_line(m)
about_menu.add_line(PYGAMEMENU_TEXT_NEWLINE)
about_menu.add_option('Return to menu', PYGAME_MENU_BACK)

# HELP
Esempio n. 22
0
def jeux():

    ABOUT = [
        'AUTHORS: METRANE Abdelmounim , LABZAGUI Nassima , ',
        'ETTAHI Yahya et MANDOR Loubna', 'EMAIL : [email protected]',
        'LIEU : Ecole Mohammedia Des Ingenieurs'
    ]
    INFO = [
        'WAR OF WORDS est un jeu educatif qui a pour but de',
        ' trouver le mot choisit (au hasard) en utilisant la commande',
        ' vocale pour entrer une lettre(e.g: dire :la lettre A) qui va',
        ' se placer automatiquement , si elle figure a son / ses',
        ' emplacements existants.',
        ' En cas de lettre n appartenant pas au mot, une chance va',
        ' etre retranchee des 7 autres offertes (augmentation du niveau ',
        'd eau) . Le jeu se termine lors de l epuisement des 7 chances.', " ",
        '########## A vos lettres , pret ? Partez !##########'
    ]
    score = charger_score()
    Compte = [
        "UTILISATEUR : " + str(nomE),
        PYGAMEMENU_TEXT_NEWLINE,
        "Votre Score est : " + str(score),
        PYGAMEMENU_TEXT_NEWLINE,
    ]
    COLOR_BACKGROUND = (155, 136, 134)
    COLOR_BLACK = (0, 0, 0)
    COLOR_WHITE = (255, 255, 255)
    Font = pygameMenu.fonts.FONT_ROSE
    MENU_BACKGROUND_COLOR = (155, 136, 134)
    WINDOW_SIZE = (700, 600)

    # creation du Menu de jeu#

    surface = pygame.display.set_mode(WINDOW_SIZE)
    pygame.display.set_caption('The War Of Words Menu')

    def initialisation():
        global fenetre, pygame
        pygame.quit()
        init_jeu()
        fenetre.mainloop()

    def main_background():
        fond = pygame.image.load(
            "C:/Users/Hp/Desktop/pyprog/background.jpeg").convert()
        surface.blit(fond, (0, 0))

    # -----------------------------------------------------------------------------
    # PLAY MENU
    play_menu = pygameMenu.Menu(surface,
                                bgfun=main_background,
                                color_selected=COLOR_WHITE,
                                font=Font,
                                font_color=COLOR_BLACK,
                                font_size=30,
                                menu_alpha=100,
                                menu_color=MENU_BACKGROUND_COLOR,
                                menu_height=int(WINDOW_SIZE[1] * 0.6),
                                menu_width=int(WINDOW_SIZE[0] * 0.6),
                                onclose=PYGAME_MENU_DISABLE_CLOSE,
                                option_shadow=False,
                                title='Play menu',
                                window_height=WINDOW_SIZE[1],
                                window_width=WINDOW_SIZE[0])

    play_menu.add_option('Start', initialisation)
    play_menu.add_option('Return to main menu', PYGAME_MENU_BACK)

    # ABOUT MENU
    about_menu = pygameMenu.TextMenu(surface,
                                     bgfun=main_background,
                                     color_selected=COLOR_WHITE,
                                     font=Font,
                                     font_color=COLOR_BLACK,
                                     font_size_title=30,
                                     font_title=pygameMenu.fonts.FONT_LEAD,
                                     menu_color=MENU_BACKGROUND_COLOR,
                                     menu_color_title=COLOR_WHITE,
                                     menu_height=int(WINDOW_SIZE[1] * 0.7),
                                     menu_width=int(WINDOW_SIZE[0] * 0.7),
                                     onclose=PYGAME_MENU_DISABLE_CLOSE,
                                     option_shadow=False,
                                     text_color=COLOR_BLACK,
                                     text_fontsize=15,
                                     title='ABOUT',
                                     window_height=WINDOW_SIZE[1],
                                     window_width=WINDOW_SIZE[0])
    for m in ABOUT:
        about_menu.add_line(m)
        about_menu.add_line(" ")
    about_menu.add_line(PYGAMEMENU_TEXT_NEWLINE)
    about_menu.add_option('Return to menu', PYGAME_MENU_BACK)
    # Info Menu
    info_menu = pygameMenu.TextMenu(surface,
                                    bgfun=main_background,
                                    color_selected=COLOR_WHITE,
                                    font=Font,
                                    font_color=COLOR_BLACK,
                                    font_size_title=30,
                                    font_title=pygameMenu.fonts.FONT_LEAD,
                                    menu_color=MENU_BACKGROUND_COLOR,
                                    menu_color_title=COLOR_WHITE,
                                    menu_height=int(WINDOW_SIZE[1] * 0.8),
                                    menu_width=int(WINDOW_SIZE[0] * 0.9),
                                    onclose=PYGAME_MENU_DISABLE_CLOSE,
                                    option_shadow=False,
                                    text_color=COLOR_BLACK,
                                    text_fontsize=20,
                                    title='Info',
                                    window_height=WINDOW_SIZE[1],
                                    window_width=WINDOW_SIZE[0])
    for m in INFO:
        info_menu.add_line(m)
    info_menu.add_line(PYGAMEMENU_TEXT_NEWLINE)
    info_menu.add_option('Return to menu', PYGAME_MENU_BACK)
    # Profile Menu
    compte_menu = pygameMenu.TextMenu(surface,
                                      bgfun=main_background,
                                      color_selected=COLOR_WHITE,
                                      font=Font,
                                      font_color=COLOR_BLACK,
                                      font_size_title=30,
                                      font_title=pygameMenu.fonts.FONT_LEAD,
                                      menu_color=MENU_BACKGROUND_COLOR,
                                      menu_color_title=COLOR_WHITE,
                                      menu_height=int(WINDOW_SIZE[1] * 0.5),
                                      menu_width=int(WINDOW_SIZE[0] * 0.5),
                                      onclose=PYGAME_MENU_DISABLE_CLOSE,
                                      option_shadow=False,
                                      text_color=COLOR_BLACK,
                                      text_fontsize=20,
                                      title='Votre compte',
                                      window_height=WINDOW_SIZE[1],
                                      window_width=WINDOW_SIZE[0])
    for m in Compte:
        compte_menu.add_line(m)
    compte_menu.add_line(PYGAMEMENU_TEXT_NEWLINE)
    compte_menu.add_option('Return to menu', PYGAME_MENU_BACK)

    # MAIN MENU
    main_menu = pygameMenu.Menu(surface,
                                bgfun=main_background,
                                color_selected=COLOR_WHITE,
                                font=Font,
                                font_color=COLOR_BLACK,
                                font_size=30,
                                menu_alpha=100,
                                menu_color=MENU_BACKGROUND_COLOR,
                                menu_height=int(WINDOW_SIZE[1] * 0.6),
                                menu_width=int(WINDOW_SIZE[0] * 0.6),
                                onclose=PYGAME_MENU_DISABLE_CLOSE,
                                option_shadow=False,
                                title='Main menu',
                                window_height=WINDOW_SIZE[1],
                                window_width=WINDOW_SIZE[0])
    main_menu.add_option('Play', play_menu)
    main_menu.add_option('About', about_menu)
    main_menu.add_option('Quit', PYGAME_MENU_EXIT)
    main_menu.add_option('Info', info_menu)
    main_menu.add_option('Compte', compte_menu)

    # -----------------------------------------------------------------------------
    # Main loop
    def main_loop():
        global fenetre
        while True:
            events = pygame.event.get()
            for event in events:
                if event.type == QUIT:
                    exit()

            main_menu.mainloop(events)

            pygame.display.flip()

    pygame.mixer.music.load("C:/Users/Hp/Desktop/pyprog/son1.wav")
    pygame.mixer.music.play()
    pygame.mixer.music.set_volume(0.2)
    main_loop()
Esempio n. 23
0
def game_play(test=False):

    global clock
    global main_menu
    global window

    # Iniciando Pygame
    pygame.init()

    # Criando tela e objetos do jogo
    window = pygame.display.set_mode(WINDOW_SIZE)
    pygame.display.set_caption("Turtlelorian")
    clock = pygame.time.Clock()

    # Menu sobre o jogo
    about_menu = pygameMenu.TextMenu(window,
                                     text_fontsize=15,
                                     bgfun=main_background,
                                     color_selected=COLOR_WHITE,
                                     font=pygameMenu.font.FONT_BEBAS,
                                     font_color=COLOR_BLACK,
                                     font_size=30,
                                     menu_alpha=100,
                                     menu_height=int(WINDOW_SIZE[1] * 0.9),
                                     menu_width=int(WINDOW_SIZE[0] * 0.9),
                                     onclose=pygameMenu.events.DISABLE_CLOSE,
                                     option_shadow=False,
                                     menu_color=COLOR_BACKGROUND,
                                     title='About the game',
                                     window_height=WINDOW_SIZE[1],
                                     window_width=WINDOW_SIZE[0])
    for l in ABOUT:
        about_menu.add_line(l)
    about_menu.add_line(pygameMenu.locals.TEXT_NEWLINE)
    about_menu.add_option('Return to menu', pygameMenu.events.BACK)

    # Menu de Instruções
    help_menu = pygameMenu.TextMenu(window,
                                    bgfun=main_background,
                                    color_selected=COLOR_WHITE,
                                    font=pygameMenu.font.FONT_BEBAS,
                                    font_color=COLOR_BLACK,
                                    font_size=30,
                                    text_fontsize=23,
                                    menu_alpha=100,
                                    menu_height=int(WINDOW_SIZE[1] * 0.9),
                                    menu_width=int(WINDOW_SIZE[0] * 0.9),
                                    onclose=pygameMenu.events.DISABLE_CLOSE,
                                    option_shadow=False,
                                    menu_color=COLOR_BACKGROUND,
                                    title='Instructions',
                                    window_height=WINDOW_SIZE[1],
                                    window_width=WINDOW_SIZE[0])
    for l in HELP:
        help_menu.add_line(l)
    help_menu.add_line(pygameMenu.locals.TEXT_NEWLINE)
    help_menu.add_option('Return to menu', pygameMenu.events.BACK)

    # Menu de Jogo
    play_menu = pygameMenu.Menu(
        window,
        bgfun=main_background,
        color_selected=COLOR_WHITE,
        font=pygameMenu.font.FONT_BEBAS,
        font_color=COLOR_BLACK,
        font_size=30,
        menu_alpha=100,
        menu_color=COLOR_BACKGROUND,
        menu_height=int(WINDOW_SIZE[1] * 0.9),
        menu_width=int(WINDOW_SIZE[0] * 0.9),
        onclose=pygameMenu.events.DISABLE_CLOSE,
        option_shadow=False,
        title='Turtlelorian',
        window_height=WINDOW_SIZE[1],
        window_width=WINDOW_SIZE[0],
    )

    # Criando as opções do menu
    play_menu.add_option('Start', play_function)
    play_menu.add_option('Help', help_menu)
    play_menu.add_option('About', about_menu)
    play_menu.add_option('Exit', pygameMenu.events.EXIT)

    # Ajustando
    play_menu.set_fps(FPS)

    while True:

        # Frames
        clock.tick(FPS)

        # Background
        main_background()

        # Eventos
        events = pygame.event.get()
        for event in events:
            if event.type == pygame.QUIT:
                exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE and main_menu.is_disabled():
                    main_menu.enable()
                    return

        # Menu Principal
        play_menu.mainloop(events, disable_loop=test)

        # Atualizar tela
        pygame.display.flip()

        if test:
            break
Esempio n. 24
0
def main(test=False):
    global clock
    global main_menu
    global surface
    global WINDOW_SIZE

    def fill_background():
        """Заливка фона"""
        global surface
        surface.fill(COLOR_BACKGROUND)

    os.environ['SDL_VIDEO_CENTERED'] = '1'

    # Создание окна с названием
    surface = pygame.display.set_mode(WINDOW_SIZE, pygame.FULLSCREEN)
    pygame.display.set_caption('Shooter')

    WINDOW_SIZE = surface.get_size()
    clock = pygame.time.Clock()

    cat = pygame.transform.scale(pygame.image.load('Data\\Image\\3.png'),
                                 (1000, 250))

    cat = GameObjects.GameObject((0, 0), cat, animation=(4, 1, 1, 1))
    surface.blit(cat.get_surface(), cat.get_position())

    # Содание меню
    play_menu = pygameMenu.Menu(surface,
                                bgfun=fill_background,
                                color_selected=COLOR_WHITE,
                                font=pygameMenu.font.FONT_BEBAS,
                                font_color=COLOR_BLACK,
                                font_size=30,
                                menu_alpha=100,
                                menu_color=MENU_BACKGROUND_COLOR,
                                menu_height=int(WINDOW_SIZE[1] * 0.7),
                                menu_width=int(WINDOW_SIZE[0] * 0.7),
                                onclose=pygameMenu.events.DISABLE_CLOSE,
                                option_shadow=False,
                                title='Play menu',
                                window_height=WINDOW_SIZE[1],
                                window_width=WINDOW_SIZE[0])

    play_submenu = pygameMenu.Menu(surface,
                                   bgfun=fill_background,
                                   color_selected=COLOR_WHITE,
                                   font=pygameMenu.font.FONT_BEBAS,
                                   font_color=COLOR_BLACK,
                                   font_size=30,
                                   menu_alpha=100,
                                   menu_color=MENU_BACKGROUND_COLOR,
                                   menu_height=int(WINDOW_SIZE[1] * 0.5),
                                   menu_width=int(WINDOW_SIZE[0] * 0.7),
                                   option_shadow=False,
                                   title='Submenu',
                                   window_height=WINDOW_SIZE[1],
                                   window_width=WINDOW_SIZE[0])
    play_submenu.add_option('Back', pygameMenu.events.BACK)
    play_menu.add_option('Start', play_function, DIFFICULTY,
                         pygame.font.Font(pygameMenu.font.FONT_FRANCHISE, 30))
    play_menu.add_selector('Select difficulty', [('1 - Easy', 'EASY'),
                                                 ('2 - Medium', 'MEDIUM'),
                                                 ('3 - Hard', 'HARD')],
                           onchange=change_difficulty,
                           selector_id='select_difficulty')
    play_menu.add_option('Return to main menu', pygameMenu.events.BACK)
    about_menu = pygameMenu.TextMenu(surface,
                                     bgfun=fill_background,
                                     color_selected=COLOR_WHITE,
                                     font=pygameMenu.font.FONT_BEBAS,
                                     font_color=COLOR_BLACK,
                                     font_size_title=30,
                                     font_title=pygameMenu.font.FONT_8BIT,
                                     menu_color=MENU_BACKGROUND_COLOR,
                                     menu_color_title=COLOR_WHITE,
                                     menu_height=int(WINDOW_SIZE[1] * 0.6),
                                     menu_width=int(WINDOW_SIZE[0] * 0.6),
                                     onclose=pygameMenu.events.DISABLE_CLOSE,
                                     option_shadow=False,
                                     text_color=COLOR_BLACK,
                                     text_fontsize=50,
                                     title='About',
                                     window_height=WINDOW_SIZE[1],
                                     window_width=WINDOW_SIZE[0])

    # Добавление информации об авторах
    for m in ABOUT:
        about_menu.add_line(m)

    about_menu.add_line(pygameMenu.locals.TEXT_NEWLINE)
    about_menu.add_option('Return to menu', pygameMenu.events.BACK)
    main_menu = pygameMenu.Menu(surface,
                                bgfun=fill_background,
                                color_selected=COLOR_WHITE,
                                font=pygameMenu.font.FONT_BEBAS,
                                font_color=COLOR_BLACK,
                                font_size=30,
                                menu_alpha=100,
                                menu_color=MENU_BACKGROUND_COLOR,
                                menu_height=int(WINDOW_SIZE[1] * 0.6),
                                menu_width=int(WINDOW_SIZE[0] * 0.6),
                                onclose=pygameMenu.events.DISABLE_CLOSE,
                                option_shadow=False,
                                title='Main menu',
                                window_height=WINDOW_SIZE[1],
                                window_width=WINDOW_SIZE[0])

    # Добавление кнопок в меню
    main_menu.add_option('Play', play_menu)
    main_menu.add_option('About', about_menu)
    main_menu.add_option('Quit', pygameMenu.events.EXIT)

    pygame.mixer.music.load('Data\\Sound\\lolka.ogg')
    pygame.mixer.music.set_volume(0.1)
    pygame.mixer.music.play(True)

    # Игровой цикл
    while True:
        # обработка событий
        cat.update()

        main_menu.mainloop(disable_loop=True)
        surface.blit(cat.get_surface(), cat.get_position())

        # Обновление экрана
        pygame.display.flip()
Esempio n. 25
0
def about_menu():
    """ Function for About Menu """
    clock = pygame.time.Clock()

    # About Menu
    contact_menu = pygameMenu.TextMenu(
        configscreen.screen,
        bgfun=main_background,
        color_selected=constants.WHITE,
        font=pygameMenu.fonts.FONT_NEVIS,
        font_color=constants.DARK_GRASS_GREEN,
        font_size_title=30,
        font_title=pygameMenu.fonts.FONT_8BIT,
        menu_color=constants.LIGHT_BROWN_DIRT,
        menu_color_title=constants.LIGHT_GREEN,
        menu_height=int(constants.SCREEN_HEIGHT * 0.6),
        menu_width=int(constants.SCREEN_WIDTH * 0.6),
        onclose=PYGAME_MENU_DISABLE_CLOSE,
        option_shadow=False,
        text_color=constants.WHITE,
        text_fontsize=15,
        font_size=30,
        title='Contact',
        window_height=constants.SCREEN_HEIGHT,
        window_width=constants.SCREEN_WIDTH)
    for m in constants.CONTACT:
        contact_menu.add_line(m)
        contact_menu.add_line(PYGAMEMENU_TEXT_NEWLINE)
    contact_menu.add_option('Return to Menu', PYGAME_MENU_BACK)

    credits_menu = pygameMenu.TextMenu(
        configscreen.screen,
        bgfun=main_background,
        font=pygameMenu.fonts.FONT_NEVIS,
        font_size_title=30,
        font_title=pygameMenu.fonts.FONT_8BIT,
        menu_color_title=constants.BLUE,
        onclose=PYGAME_MENU_CLOSE,
        text_fontsize=20,
        font_size=30,
        title='Credits',
        menu_height=int(constants.SCREEN_HEIGHT * 0.6),
        menu_width=int(constants.SCREEN_WIDTH * 0.6),
        window_height=constants.SCREEN_HEIGHT,
        window_width=constants.SCREEN_WIDTH)
    for m in constants.CREDITS:
        credits_menu.add_line(m)
        credits_menu.add_line(PYGAMEMENU_TEXT_NEWLINE)
    credits_menu.add_option('Back', PYGAME_MENU_BACK)

    # select about Menu
    select_about_menu = pygameMenu.Menu(
        configscreen.screen,
        bgfun=main_background,
        color_selected=constants.WHITE,
        font=pygameMenu.fonts.FONT_8BIT,
        font_size=25,
        font_size_title=30,
        menu_alpha=100,
        menu_color=constants.DARK_BROWN_DIRT,
        menu_height=int(constants.SCREEN_HEIGHT * 0.6),
        menu_width=int(constants.SCREEN_WIDTH * 0.6),
        onclose=PYGAME_MENU_DISABLE_CLOSE,
        option_shadow=False,
        title='About',
        window_height=constants.SCREEN_HEIGHT,
        window_width=constants.SCREEN_WIDTH)
    select_about_menu.add_option(contact_menu.get_title(), contact_menu)
    select_about_menu.add_option(credits_menu.get_title(), credits_menu)
    select_about_menu.add_option('Back', main_menu)

    while True:

        # Tick
        clock.tick(60)

        # Application events
        events = pygame.event.get()
        for event in events:
            if event.type == QUIT:
                exit()

        # Main menu
        select_about_menu.mainloop(events)

        # Flip surface
        pygame.display.flip()
Esempio n. 26
0
def option_menu():
    """ Function for Option Menu """
    clock = pygame.time.Clock()

    # Display Menu
    display_menu = pygameMenu.Menu(
        configscreen.screen,
        bgfun=main_background,
        color_selected=constants.WHITE,
        font=pygameMenu.fonts.FONT_8BIT,
        font_size=25,
        font_size_title=30,
        menu_alpha=100,
        menu_color=constants.DARK_BROWN_DIRT,
        menu_height=int(constants.SCREEN_HEIGHT * 0.6),
        menu_width=int(constants.SCREEN_WIDTH * 0.6),
        onclose=PYGAME_MENU_DISABLE_CLOSE,
        option_shadow=False,
        title='Display Settings',
        window_height=constants.SCREEN_HEIGHT,
        window_width=constants.SCREEN_WIDTH)
    display_menu.add_option('Windowed', configscreen.windowed_settings)
    display_menu.add_option('Fullscreen', configscreen.fullscreen_settings)
    display_menu.add_option('Return to Option', PYGAME_MENU_BACK)

    control_menu = pygameMenu.TextMenu(
        configscreen.screen,
        bgfun=main_background,
        font=pygameMenu.fonts.FONT_NEVIS,
        font_size_title=30,
        font_title=pygameMenu.fonts.FONT_8BIT,
        menu_color_title=constants.BLUE,
        onclose=PYGAME_MENU_CLOSE,
        text_fontsize=20,
        font_size=30,
        title='Control',
        menu_height=int(constants.SCREEN_HEIGHT * 0.6),
        menu_width=int(constants.SCREEN_WIDTH * 0.6),
        window_height=constants.SCREEN_HEIGHT,
        window_width=constants.SCREEN_WIDTH)
    control_menu.add_option('Back', PYGAME_MENU_BACK)
    for m in constants.HELP:
        control_menu.add_line(m)
    control_menu.add_line(PYGAMEMENU_TEXT_NEWLINE)

    # Option Menu
    option_menu = pygameMenu.Menu(configscreen.screen,
                                  bgfun=main_background,
                                  color_selected=constants.WHITE,
                                  font=pygameMenu.fonts.FONT_8BIT,
                                  font_size=25,
                                  font_size_title=30,
                                  menu_alpha=100,
                                  menu_color=constants.DARK_BROWN_DIRT,
                                  menu_height=int(constants.SCREEN_HEIGHT *
                                                  0.6),
                                  menu_width=int(constants.SCREEN_WIDTH * 0.6),
                                  onclose=PYGAME_MENU_DISABLE_CLOSE,
                                  option_shadow=False,
                                  title="Option",
                                  window_height=constants.SCREEN_HEIGHT,
                                  window_width=constants.SCREEN_WIDTH)
    option_menu.add_option('Display', display_menu)
    option_menu.add_option('Control', control_menu)
    option_menu.add_option('Back', main_menu)

    while True:

        # Tick
        clock.tick(60)

        # Application events
        events = pygame.event.get()
        for event in events:
            if event.type == QUIT:
                exit()

        # Main menu
        option_menu.mainloop(events)

        # Flip surface
        pygame.display.flip()
Esempio n. 27
0
                                             ('Medium', 'MEDIUM'),
                                             ('Hard', 'HARD')],
                       onreturn=None,
                       onchange=change_difficulty)
play_menu.add_option('Return to main menu', PYGAME_MENU_BACK)

# ABOUT MENU
about_menu = pygameMenu.TextMenu(surface,
                                 bgfun=main_background,
                                 color_selected=COLOR_WHITE,
                                 font=pygameMenu.fonts.FONT_BEBAS,
                                 font_color=COLOR_BLACK,
                                 font_size_title=30,
                                 font_title=pygameMenu.fonts.FONT_8BIT,
                                 menu_color=MENU_BACKGROUND_COLOR,
                                 menu_color_title=COLOR_WHITE,
                                 menu_height=int(WINDOW_SIZE[1] * 0.6),
                                 menu_width=int(WINDOW_SIZE[0] * 0.6),
                                 onclose=PYGAME_MENU_DISABLE_CLOSE,
                                 option_shadow=False,
                                 text_color=COLOR_BLACK,
                                 text_fontsize=20,
                                 title='About',
                                 window_height=WINDOW_SIZE[1],
                                 window_width=WINDOW_SIZE[0])
for m in ABOUT:
    about_menu.add_line(m)
about_menu.add_line(PYGAMEMENU_TEXT_NEWLINE)
about_menu.add_option('Return to menu', PYGAME_MENU_BACK)

# MAIN MENU
main_menu = pygameMenu.Menu(surface,
Esempio n. 28
0
                     pygame.font.Font(pygameMenu.fonts.FONT_XEN_GALAXIE, 30))
play_menu.add_selector('Selectionnez le niveau', [('Ville', 'Ville'),
                                                  ('Ruine', 'Ruine')],
                       onreturn=None,
                       onchange=change_niveau)
play_menu.add_option('Retourner au menu', PYGAME_MENU_BACK)
'''Menu controles'''
controls_menu = pygameMenu.TextMenu(
    surface,
    bgfun=main_background,
    color_selected=COLOR_WHITE,
    font=pygameMenu.fonts.FONT_XEN_GALAXIE,
    font_color=COLOR_BLACK,
    font_size_title=30,
    font_title=pygameMenu.fonts.FONT_XEN_GALAXIE,
    menu_color=MENU_BACKGROUND_COLOR,
    menu_height=int(WINDOW_SIZE[1]),
    menu_width=int(WINDOW_SIZE[0]),
    onclose=PYGAME_MENU_DISABLE_CLOSE,
    option_shadow=False,
    text_color=COLOR_BLACK,
    text_fontsize=30,
    title='Controles',
    window_height=WINDOW_SIZE[1],
    window_width=WINDOW_SIZE[0])
for m in CONTROLS:
    controls_menu.add_line(m)
controls_menu.add_line(PYGAMEMENU_TEXT_NEWLINE)
controls_menu.add_option('Retourner au menu', PYGAME_MENU_BACK)
'''Menu crédit'''
credit_menu = pygameMenu.TextMenu(surface,
                                  bgfun=main_background,
Esempio n. 29
0
def gameplay():
    """ Main Program """
    pygame.init()

    # set for title my game
    pygame.display.set_caption("Advanture of Gimo")

    # set icon game
    icon = pygame.image.load("spritesheet/gimo.png")
    pygame.display.set_icon(icon)

    # hide mouse cursor
    pygame.mouse.set_visible(False)

    # Create the player
    player = Player()

    # Create all the levels
    level_list = []
    level_list.append(level_11.Level_11(player))
    level_list.append(level_ending.Level_Ending(player))

    # Set the current level
    current_level_no = 0
    current_level = level_list[current_level_no]

    active_sprite_list = pygame.sprite.Group()
    player.level = current_level

    # player position
    player.rect.x = 70
    player.rect.y = 360
    active_sprite_list.add(player)

    # Loop until the user clicks the close button.
    # variable for game exit of course
    gameExit = False
    # variabel for game over of course
    # gameOver = False

    # play the sound
    configsounds.turn_on_sounds()

    # call BasicSettings class
    settings = fontsettings.BasicSettings()

    # creating a snows
    # create an empty array
    snow_list = []

    for i in range(50):
        x = random.randrange(0, 790)
        y = random.randrange(0, 590)
        # pygame.draw.circle(screen, WHITE, [x, y], 2)
        snow_list.append([x, y])

    # Used to manage how fast the screen updates
    clock = pygame.time.Clock()

    # display in game settings
    option_display_settings = pygameMenu.Menu(
        configscreen.screen,
        bgfun=pause_background,
        enabled=False,
        font=pygameMenu.fonts.FONT_8BIT,
        menu_alpha=90,
        font_size=25,
        font_size_title=30,
        onclose=PYGAME_MENU_CLOSE,
        title='Display',
        title_offsety=5,
        menu_height=int(constants.SCREEN_HEIGHT * 0.6),
        menu_width=int(constants.SCREEN_WIDTH * 0.6),
        window_height=constants.SCREEN_HEIGHT,
        window_width=constants.SCREEN_WIDTH)

    option_display_settings.add_option('Fullscreen',
                                       configscreen.fullscreen_settings)
    option_display_settings.add_option('Windowed',
                                       configscreen.windowed_settings)
    option_display_settings.add_option('Back', PYGAME_MENU_BACK)

    # sounds in game settings
    option_sounds_settings = pygameMenu.Menu(
        configscreen.screen,
        bgfun=pause_background,
        enabled=False,
        font=pygameMenu.fonts.FONT_8BIT,
        font_size=25,
        font_size_title=30,
        menu_alpha=90,
        onclose=PYGAME_MENU_CLOSE,
        title='Sounds',
        title_offsety=5,
        menu_height=int(constants.SCREEN_HEIGHT * 0.6),
        menu_width=int(constants.SCREEN_WIDTH * 0.6),
        window_height=constants.SCREEN_HEIGHT,
        window_width=constants.SCREEN_WIDTH)

    option_sounds_settings.add_option('On Music', configsounds.turn_on_sounds)
    option_sounds_settings.add_option('Off Music',
                                      configsounds.turn_off_sounds)
    option_sounds_settings.add_option('Back', PYGAME_MENU_BACK)

    # help in game setitings
    help_menu = pygameMenu.TextMenu(
        configscreen.screen,
        bgfun=pause_background,
        font=pygameMenu.fonts.FONT_NEVIS,
        font_size_title=30,
        font_title=pygameMenu.fonts.FONT_8BIT,
        menu_color_title=constants.BLUE,
        onclose=PYGAME_MENU_CLOSE,
        text_fontsize=20,
        font_size=30,
        title='Help',
        menu_height=int(constants.SCREEN_HEIGHT * 0.6),
        menu_width=int(constants.SCREEN_WIDTH * 0.6),
        window_height=constants.SCREEN_HEIGHT,
        window_width=constants.SCREEN_WIDTH)
    help_menu.add_option('Back', PYGAME_MENU_BACK)
    for m in constants.HELP:
        help_menu.add_line(m)
    help_menu.add_line(PYGAMEMENU_TEXT_NEWLINE)

    # confirm exit pause and main menu
    confirm_exit_pause = pygameMenu.Menu(
        configscreen.screen,
        bgfun=pause_background,
        enabled=False,
        font=pygameMenu.fonts.FONT_8BIT,
        font_size=25,
        font_size_title=30,
        menu_alpha=90,
        onclose=PYGAME_MENU_CLOSE,
        title='Are You Sure',
        title_offsety=5,
        menu_height=int(constants.SCREEN_HEIGHT * 0.6),
        menu_width=int(constants.SCREEN_WIDTH * 0.6),
        window_height=constants.SCREEN_HEIGHT,
        window_width=constants.SCREEN_WIDTH)

    confirm_exit_pause.add_option('Yes', PYGAME_MENU_EXIT)
    confirm_exit_pause.add_option('No', PYGAME_MENU_BACK)

    confirm_back_tomenu = pygameMenu.Menu(
        configscreen.screen,
        bgfun=pause_background,
        enabled=False,
        font=pygameMenu.fonts.FONT_8BIT,
        font_size=25,
        font_size_title=30,
        menu_alpha=90,
        onclose=PYGAME_MENU_CLOSE,
        title='Are You Sure',
        title_offsety=5,
        menu_height=int(constants.SCREEN_HEIGHT * 0.6),
        menu_width=int(constants.SCREEN_WIDTH * 0.6),
        window_height=constants.SCREEN_HEIGHT,
        window_width=constants.SCREEN_WIDTH)

    confirm_back_tomenu.add_option('Yes', mainmenu.main_menu)
    confirm_back_tomenu.add_option('No', PYGAME_MENU_BACK)

    # pause menu
    menu = pygameMenu.Menu(configscreen.screen,
                           bgfun=pause_background,
                           enabled=False,
                           font=pygameMenu.fonts.FONT_8BIT,
                           font_size=25,
                           font_size_title=30,
                           menu_alpha=90,
                           onclose=PYGAME_MENU_CLOSE,
                           title='Pause Menu',
                           title_offsety=5,
                           menu_height=int(constants.SCREEN_HEIGHT * 0.6),
                           menu_width=int(constants.SCREEN_WIDTH * 0.6),
                           window_height=constants.SCREEN_HEIGHT,
                           window_width=constants.SCREEN_WIDTH)

    menu.add_option('Back to Main Menu', confirm_back_tomenu)
    menu.add_option(option_sounds_settings.get_title(), option_sounds_settings)
    menu.add_option(option_display_settings.get_title(),
                    option_display_settings)
    menu.add_option(help_menu.get_title(), help_menu)
    menu.add_option('Exit', confirm_exit_pause)  # Add exit function

    # -------- Main Program Loop -----------
    while not gameExit:
        # if gameOver:

        # dead_hiragana_level_1.show_game_over_hiragana()

        events = pygame.event.get()
        for event in events:  # User did something
            if event.type == pygame.QUIT:  # If user clicked close
                gameExit = True  # Flag that we are done so we exit this loop

            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    player.go_left()
                elif event.key == pygame.K_RIGHT:
                    player.go_right()
                elif event.key == pygame.K_UP:
                    player.jump()

                # for player skill
                elif event.key == pygame.K_SPACE:

                    bullet = Bullet(player)
                    # play the sounds skill
                    configsounds.magic_sfx.play()
                    configsounds.magic_sfx.set_volume(0.5)

                    # Set the bullet so it is where the player is
                    if player.direction == "R":
                        bullet.rect.x = player.rect.x + 50
                        bullet.rect.y = player.rect.y + 30
                    elif player.direction == "L":
                        bullet.rect.x = player.rect.x
                        bullet.rect.y = player.rect.y + 30

                    # Add the bullet to the lists
                    active_sprite_list.add(bullet)
                    bullet.bullet_list.add(bullet)

                elif event.key == pygame.K_ESCAPE:
                    menu.enable()

            elif event.type == pygame.KEYUP:
                if event.key == pygame.K_LEFT and player.change_x < 0:
                    player.stop()
                elif event.key == pygame.K_RIGHT and player.change_x > 0:
                    player.stop()

        # Update the player.
        active_sprite_list.update()
        # Update items in the level
        current_level.update()

        # If the player gets near the right side, shift the world left (-x)
        if player.rect.right >= 500:
            diff = player.rect.right - 500
            player.rect.right = 500
            current_level.shift_world(-diff)

        # If the player gets near the left side, shift the world right (+x)
        if player.rect.left <= 120:
            diff = 120 - player.rect.left
            player.rect.left = 120
            current_level.shift_world(diff)

        current_position = player.rect.x + current_level.world_shift

        # debugging purpose
        # print(current_position)
        # check the position x and y
        # mouse_pos = pygame.mouse.get_pos()
        # print(mouse_pos)

        if current_position == current_level.level_limit:
            player.rect.x = 120
            if current_level_no < len(level_list) - 1:
                current_level_no += 1
                current_level = level_list[current_level_no]
                player.level = current_level

        # ALL CODE TO DRAW SHOULD GO BELOW THIS COMMENT
        current_level.draw(configscreen.screen)
        active_sprite_list.draw(configscreen.screen)

        # ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT

        # stage advanture for player
        def print_level_info(level_number):
            settings.msg_to_screen(
                # level number
                "Level {}".format(level_number),
                constants.WHITE,
                0,
                0,
                size="small")

            settings.msg_to_screen("Misi Level {} :".format(level_number),
                                   constants.WHITE,
                                   0,
                                   25,
                                   size="small")

            settings.msg_to_screen("Tebak, temukan huruf hiragana",
                                   constants.WHITE,
                                   0,
                                   50,
                                   size="small")

            # for player health
            if player.health_number == 100 or player.health_number == 90 \
                    or player.health_number == 80:
                settings.msg_to_screen("Health : " + str(player.health_number),
                                       constants.GREEN,
                                       90,
                                       0,
                                       size="small")
            elif player.health_number == 70 or player.health_number == 60 \
                    or player.health_number == 50:
                settings.msg_to_screen("Health : " + str(player.health_number),
                                       constants.YELLOW,
                                       90,
                                       0,
                                       size="small")
            elif player.health_number == 40 or player.health_number == 30 \
                    or player.health_number == 20 \
                    or player.health_number == 10:
                settings.msg_to_screen("Health : " + str(player.health_number),
                                       constants.RED,
                                       90,
                                       0,
                                       size="small")

            settings.msg_to_screen("Scores : " + str(player.scores),
                                   constants.WHITE,
                                   600,
                                   0,
                                   size="small")

            settings.msg_to_screen("hiragana :",
                                   constants.WHITE,
                                   300,
                                   0,
                                   size="small")

        # if the player in the level 11
        if current_level == level_list[0]:
            # level number
            print_level_info(11)
            settings.msg_to_screen("WA, WO, dan N",
                                   constants.WHITE,
                                   0,
                                   75,
                                   size="small")
            # for confirm text hiragana
            if player.special_remove_WA \
                    or player.special_remove_WO \
                    or player.special_remove_N == True:
                if bullet.confirm_hiragana == True:
                    settings.msg_to_screen("benar",
                                           constants.GREEN,
                                           400,
                                           0,
                                           size="small")

                elif bullet.confirm_hiragana == False:
                    settings.msg_to_screen("salah",
                                           constants.RED,
                                           400,
                                           0,
                                           size="small")

        # Limit to 60 frames per second
        clock.tick(60)

        menu.mainloop(events)

        # Go ahead and update the screen with what we've drawn.
        pygame.display.flip()

    # Be IDLE friendly. If you forget this line, the program will 'hang'
    # on exit.
    pygame.quit()
    quit()
Esempio n. 30
0
def main(test=False):
    """
    Main program.

    :param test: Indicate function is being tested
    :type test: bool
    :return: None
    """

    # -------------------------------------------------------------------------
    # Init pygame
    # -------------------------------------------------------------------------
    pygame.init()
    os.environ['SDL_VIDEO_CENTERED'] = '1'

    # Write help message on console
    for m in HELP:
        print(m)

    # Create window
    global surface
    surface = pygame.display.set_mode((W_SIZE, H_SIZE))
    pygame.display.set_caption('Example - Timer Clock')

    # Main timer and game clock
    clock = pygame.time.Clock()
    global timer
    timer = [0.0]
    dt = 1.0 / FPS
    timer_font = pygameMenu.font.get_font(pygameMenu.font.FONT_NEVIS, 100)

    # -------------------------------------------------------------------------
    # Create menus
    # -------------------------------------------------------------------------

    # Timer
    timer_menu = pygameMenu.Menu(
        surface,
        dopause=False,
        font=pygameMenu.font.FONT_NEVIS,
        menu_alpha=85,
        menu_color=(0, 0, 0),  # Background color
        menu_color_title=(0, 0, 0),
        menu_height=int(H_SIZE * 0.65),
        menu_width=600,
        onclose=pygameMenu.events.
        RESET,  # If this menu closes (ESC) back to main
        option_shadow=True,
        rect_width=4,
        title='Timer Menu',
        title_offsety=5,  # Adds 5px to title vertical position
        window_height=H_SIZE,
        window_width=W_SIZE)

    # Add options
    timer_menu.add_option('Reset timer', reset_timer)

    # Adds a selector (element that can handle functions)
    timer_menu.add_selector(
        'Change bgcolor',
        # Values of selector, call to change_color_bg
        [('Random', (-1, -1, -1)), ('Default', (128, 0, 128)),
         ('Black', (0, 0, 0)), ('Blue', COLOR_BLUE)],
        # Optional parameter that sets default item of selector
        default=1,
        # Action when changing element with left/right
        onchange=change_color_bg,
        # Action when pressing return on an element
        onreturn=change_color_bg,
        # Optional parameters to change_color_bg function
        write_on_console=True)
    timer_menu.add_option('Update game object',
                          TestCallClassMethod().update_game_settings)
    timer_menu.add_option('Return to Menu', pygameMenu.events.BACK)
    timer_menu.add_option('Close Menu', pygameMenu.events.CLOSE)

    # Help menu
    help_menu = pygameMenu.TextMenu(
        surface,
        dopause=False,
        font=pygameMenu.font.FONT_FRANCHISE,
        menu_color=(30, 50, 107),  # Background color
        menu_color_title=(120, 45, 30),
        # Pressing ESC button does nothing
        onclose=pygameMenu.events.DISABLE_CLOSE,
        option_shadow=True,
        option_shadow_position=pygameMenu.locals.POSITION_SOUTHEAST,
        text_align=pygameMenu.locals.ALIGN_CENTER,
        title='Help',
        window_height=H_SIZE,
        window_width=W_SIZE)
    help_menu.add_option('Return to Menu', pygameMenu.events.BACK)
    for m in HELP:
        help_menu.add_line(m)

    # About menu
    about_menu = pygameMenu.TextMenu(
        surface,
        dopause=False,
        draw_text_region_x=5,  # 5% margin
        font=pygameMenu.font.FONT_NEVIS,
        font_size_title=30,
        font_title=pygameMenu.font.FONT_8BIT,
        menu_color_title=COLOR_BLUE,
        mouse_visible=False,
        # Disable menu close (ESC button)
        onclose=pygameMenu.events.DISABLE_CLOSE,
        option_shadow=True,
        text_fontsize=20,
        title='About',
        window_height=H_SIZE,
        window_width=W_SIZE)
    about_menu.add_option('Return to Menu', pygameMenu.events.BACK)
    for m in ABOUT:
        about_menu.add_line(m)
    about_menu.add_line(pygameMenu.locals.TEXT_NEWLINE)

    # Main menu, pauses execution of the application
    main_menu = pygameMenu.Menu(surface,
                                bgfun=mainmenu_background,
                                enabled=False,
                                font=pygameMenu.font.FONT_NEVIS,
                                menu_alpha=90,
                                fps=FPS,
                                onclose=pygameMenu.events.CLOSE,
                                title='Main Menu',
                                title_offsety=5,
                                window_height=H_SIZE,
                                window_width=W_SIZE)

    main_menu.add_option(timer_menu.get_title(),
                         timer_menu)  # Add timer submenu
    main_menu.add_option(help_menu.get_title(), help_menu)  # Add help submenu
    main_menu.add_option(about_menu.get_title(),
                         about_menu)  # Add about submenu
    main_menu.add_option('Exit', pygameMenu.events.EXIT)  # Add exit function

    # -------------------------------------------------------------------------
    # Main loop
    # -------------------------------------------------------------------------
    while True:

        # Tick clock
        clock.tick(FPS)
        timer[0] += dt

        # Paint background
        surface.fill(COLOR_BACKGROUND)

        # Application events
        events = pygame.event.get()
        for event in events:
            if event.type == pygame.QUIT:
                exit()
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    main_menu.enable()

        # Draw timer
        time_string = str(datetime.timedelta(seconds=int(timer[0])))
        time_blit = timer_font.render(time_string, 1, COLOR_WHITE)
        time_blit_size = time_blit.get_size()
        surface.blit(time_blit, (W_SIZE / 2 - time_blit_size[0] / 2,
                                 H_SIZE / 2 - time_blit_size[1] / 2))

        # Execute main from principal menu if is enabled
        main_menu.mainloop(events, disable_loop=test)

        # Flip surface
        pygame.display.flip()

        # At first loop returns
        if test:
            break