示例#1
0
def main():
    # 定数を読み込む
    constants = get_constants()

    # フォントの指定と(libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD)でどのタイプのファイルを読み取るのかを伝える
    libtcod.console_set_custom_font("arial10x10.png", libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD)

    # ここで実際に画面を作成する、画面サイズとタイトルとフルスクリーンとレンダラーと画面の垂直同期を指定している
    libtcod.console_init_root(constants["screen_width"], constants["screen_height"], constants["window_title"], False)

    con = libtcod.console.Console(constants["screen_width"], constants["screen_height"])
    panel = libtcod.console.Console(constants["screen_width"], constants["panel_height"])

    player = None

    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load("menu_background.png")

    main_window = libtcod.console_is_window_closed()

    

    while True:
        if show_main_menu:
            main_menu(con, main_menu_background_image, constants["screen_width"],
                      constants["screen_height"])

            if show_load_error_message:
                message_box(con, "No save game to load", 50, constants["screen_width"], constants["screen_height"])

            libtcod.console_flush()
            for events in libtcod.event.get():
                if events.type == "KEYDOWN":
                    action = handle_main_menu(events)

                    new_game = action.get("new_game")
                    load_saved_game = action.get("load_game")
                    exit_game = action.get("exit")

                    if show_load_error_message and (new_game or load_saved_game or exit_game):
                        show_load_error_message = False
                    elif new_game:
                        player, entities, game_map, message_log, game_state = get_game_variables(constants)
                        game_state = GameStates.PLAYERS_TURN

                        show_main_menu = False
                    elif load_saved_game:
                        try:
                            player, entities, game_map, message_log, game_state = load_game()
                            show_main_menu = False
                        except FileNotFoundError:
                            show_load_error_message = True
                    elif exit_game:
                        return False


        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con, panel, constants)

            show_main_menu = True
def main():
    constants = get_constants()

    libtcod.console_set_custom_font(
        'terminal8x12.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'], False)

    con = libtcod.console_new(constants['screen_width'],
                              constants['screen_height'])
    panel = libtcod.console_new(constants['screen_width'],
                                constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)

            show_main_menu = True
示例#3
0
def main():
    # pull variables
    constants = get_constants()

    # set graphics template (source, type, layout)

    # --- original setup ---
    # libtcod.console_set_custom_font(
    #     'arial10x10.png',
    #     libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD)

    # --- new font file ---
    libtcod.console_set_custom_font(
        'TiledFont.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 10)

    # create screen (width, height, title, fullscreen_boolean)
    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'], False)

    # initialize console
    con = libtcod.console_new(constants['screen_width'],
                              constants['screen_height'])
    panel = libtcod.console_new(constants['screen_width'],
                                constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    libtcod.console_set_fullscreen(True)

    # mixer.music.play(-1)
    # music_loop = mixer.Sound('Cave_Loop.wav')
    # mixer.Sound.play(music_loop)

    mixer.init()
    music_loop = mixer.Sound('Cave_Loop.wav')
    mixer.Sound.play(music_loop, loops=-1)

    while not libtcod.console_is_window_closed():

        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False

            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYER_TURN
                show_main_menu = False

            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True

            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)
            show_main_menu = True
示例#4
0
def main():
    constants = get_constants()

    libtcod.console_set_custom_font(
        'TiledFont.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 10)

    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'], False)

    con = libtcod.console_new(constants['screen_width'],
                              constants['screen_height'])
    panel = libtcod.console_new(constants['screen_width'],
                                constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_character_screen = False
    start_game = None
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')
            choose_fighter = action.get('choose_fighter')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants, 'barbarian')
                game_state = GameStates.PLAYER_TURN

                show_main_menu = False
                start_game = True
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                    start_game = True
                except FileNotFoundError:
                    show_load_error_message = True
            elif choose_fighter:
                show_main_menu = False
                #show_character_screen = True
                new_character_screen(con, main_menu_background_image,
                                     constants['screen_width'],
                                     constants['screen_height'])
                libtcod.console_flush()
                '''TODO: Задать переменную, отвечающую за то, что открыто ли окно choose_fighter или нет'''
                action_character_menu = handle_new_character_menu_keys(key)

                warrior = 'warrior'
                thief = 'thief'
                barbarian = 'barbarian'
                exit_character_menu = 'exit'

                if action_character_menu.get('warrior') == warrior:
                    player, entities, game_map, message_log, game_state = get_game_variables(
                        constants, warrior)

                    game_state = GameStates.PLAYER_TURN
                    #show_character_screen = False
                    #show_main_menu = False
                    #start_game = True
                    #start_game = True
                    choose_fighter = False

                elif action_character_menu.get('thief') == thief:
                    player, entities, game_map, message_log, game_state = get_game_variables(
                        constants, thief)
                    #game_state = GameStates.PLAYER_TURN
                    #show_character_screen = False
                    choose_fighter = False

                elif action_character_menu.get('barbarian') == barbarian:
                    player, entities, game_map, message_log, game_state = get_game_variables(
                        constants, barbarian)
                    game_state = GameStates.PLAYER_TURN
                    #show_character_screen = False
                elif action_character_menu.get('exit') == exit_character_menu:
                    show_character_screen = False
                    show_main_menu = True
                    main_menu(con, main_menu_background_image,
                              constants['screen_width'],
                              constants['screen_height'])
                    libtcod.console_flush()

                show_character_screen = False

            elif choose_fighter == False:
                start_game = True
                game_state.PLAYER_TURN

            elif exit_game:
                break
        elif start_game == True:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)

            show_main_menu = True
示例#5
0
def main():
    constants = get_constants()
    main_menu_background_image = tcod.image_load('menu_background.png')
    tcod.console_set_custom_font(
        'arial10x10.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)

    root_con = tcod.console_init_root(constants["screen_width"],
                                      constants["screen_height"],
                                      constants["window_title"],
                                      order="C",
                                      renderer=tcod.RENDERER_SDL2,
                                      vsync=True)

    con = tcod.console.Console(constants['screen_width'],
                               constants['screen_height'])
    panel = tcod.console.Console(constants['screen_width'],
                                 constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    while show_main_menu:
        main_menu(con, main_menu_background_image, constants['screen_width'],
                  constants['screen_height'], root_con)

        if show_load_error_message:
            message_box(con, 'No save game to load', 50,
                        constants['screen_width'], constants['screen_height'],
                        root_con)

        tcod.console_flush()
        action = {}
        for event in tcod.event.get():
            if isinstance(event, tcod.event.KeyDown):
                action = handle_main_menu(event)

        new_game = action.get('new_game')
        load_saved_game = action.get('load_game')
        exit_game = action.get('exit')

        if show_load_error_message and (new_game or load_saved_game
                                        or exit_game):
            show_load_error_message = False
        elif new_game:
            player, entities, game_map, message_log, game_state = get_game_variables(
                constants)
            game_state = GameStates.PLAYER_TURN
            show_main_menu = False
        elif load_saved_game:
            try:
                player, entities, game_map, message_log, game_state = load_game(
                )
                show_main_menu = False
            except FileNotFoundError:
                show_load_error_message = True
        elif exit_game:
            quit()
    else:
        con.clear()
        play_game(player, entities, game_map, message_log, game_state, con,
                  panel, constants, root_con)
        main()
示例#6
0
def main():
    constants = get_constants()

    tdl.set_font('arial10x10.png', greyscale=True, altLayout=True)

    root_console = tdl.init(constants['screen_width'], constants['screen_height'], constants['window_title'])
    con = tdl.Console(constants['screen_width'], constants['screen_height'])
    panel = tdl.Console(constants['screen_width'], constants['panel_height'])

    player = None
    store = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = image_load('menu_background1.png')

    while not tdl.event.is_window_closed():
        for event in tdl.event.get():
            if event.type == 'KEYDOWN':
                user_input = event
                break
        else:
            user_input = None

        if show_main_menu:
            main_menu(con, root_console, main_menu_background_image, constants['screen_width'], constants['screen_height'], constants['colors'])

            if show_load_error_message:
                message_box(con, root_console, 'No save game to load', 50, constants['screen_width'], constants['screen_height'])

            tdl.flush()

            action = handle_main_menu(user_input)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game()
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            root_console.clear()
            con.clear()
            panel.clear()
            play_game(player, entities, game_map, message_log, game_state, root_console, con, panel, constants)

            show_main_menu = True
示例#7
0
def main():
    constants = get_constants()

    # libtcod.console_set_custom_font('TiledFont.png', libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 10)  # setting 10 to 8 will prove that the bitmaps are loaded
    init_fontmap('sprites1')

    libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False,
                              libtcod.RENDERER_SDL2)
    load_customfont()
    
    con = libtcod.console.Console(constants['screen_width'], constants['screen_height'])
    # con = libtcod.console_new(constants['screen_width'], constants['screen_height'])
    panel = libtcod.console.Console(constants['screen_width'], constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('zombie_splash.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image, constants['screen_width'],
                      constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game()
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            # libtcod.console_clear(con)
            con.clear()
            play_game(player, entities, game_map, message_log, game_state, con, panel, constants)

            show_main_menu = True
示例#8
0
def load_game(mvc):
    world, party = load_game()
    mvc.game.preplay(world, party)
示例#9
0
def main():
    # How cute is a program that says "Hello World!" at the beginning?
    # I'll tell ya, it's 100% cute.
    print('Hello world!')

    constants = get_constants()

    libtcod.console_set_custom_font('Bedstead_12x20.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW)

    libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False)

    con = libtcod.console_new(constants['screen_width'], constants['screen_height'])
    panel = libtcod.console_new(constants['screen_width'], constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game or exit_game):
                show_load_error_message = False

            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(constants)
                game_state = GameStates.PLAYER_TURN
                show_main_menu = False

            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game()
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True

            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con, panel, constants)
            show_main_menu = True
示例#10
0
def main() -> None:

    tcod.console_set_custom_font(
        'potash_10x10.png',
        tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_ASCII_INROW)

    root_console = tcod.console_init_root(w=const.SCREEN_WIDTH,
                                          h=const.SCREEN_HEIGHT,
                                          title=const.WINDOW_TITLE,
                                          fullscreen=False,
                                          order="F",
                                          vsync=False,
                                          renderer=tcod.RENDERER_OPENGL2)

    offscreen_console = tcod.console.Console(const.SCREEN_WIDTH,
                                             const.SCREEN_HEIGHT,
                                             order="F")

    viewport_console = tcod.console.Console(const.VIEWPORT_WIDTH,
                                            const.VIEWPORT_HEIGHT,
                                            order="F")

    status_console = tcod.console.Console(const.STATUS_WIDTH,
                                          const.STATUS_HEIGHT,
                                          order="F")

    entity_console = tcod.console.Console(const.ENTITY_WIDTH,
                                          const.ENTITY_HEIGHT,
                                          order="F")

    log_console = tcod.console.Console(const.LOG_WIDTH,
                                       const.LOG_HEIGHT,
                                       order="F")

    root_console.ch[:] = 0
    root_console.fg[:] = (255, 255, 255)
    root_console.bg[:] = (0, 0, 0)

    offscreen_console.ch[:] = 0
    offscreen_console.fg[:] = (255, 255, 255)
    offscreen_console.bg[:] = (0, 0, 0)

    viewport_console.ch[:] = 0
    viewport_console.fg[:] = (255, 255, 255)
    viewport_console.bg[:] = (0, 0, 0)

    status_console.ch[:] = 0
    status_console.fg[:] = (255, 255, 255)
    status_console.bg[:] = (0, 0, 0)

    entity_console.ch[:] = 0
    entity_console.fg[:] = (255, 255, 255)
    entity_console.bg[:] = (0, 0, 0)

    player = None
    dungeon = None
    message_log = None
    game_state = None
    camera = None

    show_main_menu = True
    show_load_error = False
    show_corrupt_error = False

    current_level = -1

    while True:

        if show_main_menu:
            main_menu(root_console, "heic1104a-edited.png", const.SCREEN_WIDTH,
                      const.SCREEN_HEIGHT)
            if show_load_error:
                message_text = "No save exists."
                message_box(root_console, message_text, len(message_text),
                            const.SCREEN_WIDTH, const.SCREEN_HEIGHT)
            if show_corrupt_error:
                message_text = "Corrupt save."
                message_box(root_console, message_text, len(message_text),
                            const.SCREEN_WIDTH, const.SCREEN_HEIGHT)

            tcod.console_flush()

            action = handle_main_menu(tcod.event.get())

            new_game = action.get("new_game")
            load_save = action.get("load_game")
            exit_game = action.get("exit")

            if show_load_error and (new_game or load_save or exit_game):
                show_load_error = False
            elif show_corrupt_error and (new_game or load_save or exit_game):
                show_corrupt_error = False
            elif new_game:
                player, dungeon, message_log, game_state, current_level, camera = get_game_variables(
                )
                game_state = GameState.PLAYER_TURN

                show_main_menu = False

            elif load_save:
                try:
                    camera = Camera(0, 0, const.VIEWPORT_WIDTH - 1,
                                    const.VIEWPORT_HEIGHT - 1)
                    player, dungeon, message_log, game_state, current_level = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error = True
                except KeyError:
                    show_corrupt_error = True
            elif exit_game:
                break

        else:
            root_console.clear()
            assert current_level != -1
            play_game(player, dungeon, message_log, game_state, root_console,
                      offscreen_console, viewport_console, log_console,
                      status_console, entity_console, current_level, camera)

            show_main_menu = True
示例#11
0
def main():
    """ Main game loop

    Init console + wraps key events

    """

    constants = get_constants()

    tcod.console_set_custom_font(
        "arial10x10.png", tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)
    tcod.console_init_root(
        constants["screen_width"],
        constants["screen_height"],
        constants["window_title"],
        False,
        constants["sdl_renderer"],
    )

    console = tcod.console.Console(constants["screen_width"],
                                   constants["screen_height"])
    panel = tcod.console_new(constants["screen_width"],
                             constants["panel_height"])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = tcod.image_load('menu_background.png')

    key = tcod.Key()
    mouse = tcod.Mouse()

    while not tcod.console_is_window_closed():
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key,
                                 mouse)

        if show_main_menu:
            main_menu(console, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(console, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            tcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN
                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break
        else:
            tcod.console_clear(console)
            play_game(player, entities, game_map, message_log, game_state,
                      console, panel, constants)
            show_main_menu = True
示例#12
0
def main():
    constants = get_constants()

    tcod.console_set_custom_font(
        'consolas12x12_gs_tc.png',
        tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)
    tcod.console_init_root(constants['screen_width'],
                           constants['screen_height'],
                           constants['window_title'], False)
    con = tcod.console_new(constants['screen_width'],
                           constants['screen_height'])
    panel = tcod.console_new(
        constants['screen_width'],
        constants['screen_height'] - constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None
    show_main_menu = True
    show_load_error_message = False
    main_menu_background_image = tcod.image_load('menu_background.png')

    key = tcod.Key()
    mouse = tcod.Mouse()

    while not tcod.console_is_window_closed():
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key,
                                 mouse)
        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])
            if show_load_error_message:
                menu(con, 'Save game unfound', [], 50,
                     constants['screen_width'], constants['screen_height'])
            tcod.console_flush()

            action = handle_main_menu(key)
            new_game = action.get('new_game')
            load_game_bool = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_vars(
                    constants)
                show_main_menu = False
            elif load_game_bool:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break
        else:
            tcod.console_clear(con)
            start_game(player, entities, game_map, message_log, game_state,
                       con, panel, constants)

            show_main_menu = True
示例#13
0
    def main(self):

        # Set font
        libtcod.console_set_custom_font(
            'dejavu_wide16x16_gs_tc.png',
            libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
        # Create game window
        libtcod.console_init_root(self.constants['screen_width'],
                                  self.constants['screen_height'],
                                  self.constants['window_title'], False)

        # Create a console (Drawing Layer?)
        con = libtcod.console_new(self.constants['screen_width'],
                                  self.constants['screen_height'])
        panel = libtcod.console_new(self.constants['screen_width'],
                                    self.constants['panel_height'])

        players = []
        entity = []
        game_map = None
        message_log = None
        self.game_state = None
        self.active_player = 0

        show_main_menu = True
        show_load_error_message = False

        main_menu_background_image = libtcod.image_load('menu_background.png')

        # Holds keyboard and mouse input
        key = libtcod.Key()
        mouse = libtcod.Mouse()

        # Menu loop
        while not libtcod.console_is_window_closed():
            libtcod.sys_check_for_event(
                libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

            if show_main_menu:
                main_menu(con, main_menu_background_image,
                          self.constants['screen_width'],
                          self.constants['screen_height'])

                if show_load_error_message:
                    message_box(con, 'No save game to load', 50,
                                self.constants['screen_width'],
                                self.constants['screen_height'])

                libtcod.console_flush()

                action = handle_main_menu(key)

                new_game = action.get('new_game')
                load_saved_game = action.get('load_game')
                exit_game = action.get('exit')

                if show_load_error_message and (new_game or load_saved_game
                                                or exit_game):
                    show_load_error_message = False
                elif new_game:
                    players, entities, game_map, message_log, self.game_state = get_game_variables(
                        self.constants)
                    self.game_state = GameStates.PLAYERS_TURN

                    show_main_menu = False
                elif load_saved_game:
                    try:
                        players, entities, game_map, message_log, self.game_state, self.active_player = load_game(
                            self.constants['player_count'])
                        self.game_state = GameStates.PLAYERS_TURN

                        show_main_menu = False
                    except FileNotFoundError:
                        show_load_error_message = True
                elif exit_game:
                    break
            else:
                libtcod.console_clear(con)
                self.play_game(players, entities, game_map, message_log,
                               self.game_state, con, panel, self.constants)

                show_main_menu = True
示例#14
0
def main():
    constants = initialize_new_game.get_constants()
    position = 0

    terminal.open()
    terminal.set("window: size=" + str(constants['screen_width']) + "x" +
                 str(constants['screen_height']) + ', title=Space Game')
    terminal.set("font: fonts\courbd.ttf, size=" + constants.get('fontsize'))
    # terminal.set("input.filter={keyboard, mouse}")

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    while True:
        # show the background image, at twice the regular console resolution
        # clear scene especially after quitting game
        terminal.layer(0)
        terminal.clear()
        # show the game's title, and some credits!
        title = 'SPACE GAME'
        titlex = int(constants['screen_width'] / 2 - len(title) / 2)
        titley = int(constants['screen_height'] / 2)

        subtitle = 'Game by Eric Younkin'
        subtitlex = int(constants['screen_width'] / 2 - len(subtitle) / 2)
        subtitley = int(constants['screen_height'] / 2 + 2)

        terminal.color('yellow')
        terminal.print_(titlex, titley, '[align=center]' + title)
        terminal.print_(subtitlex, subtitley,
                        '[align=center][font=0xE000]' + subtitle)

        # show options and wait for the player's choice
        options = ['Play a new game', 'Continue last game', 'Quit']
        menu('',
             options,
             30,
             constants['screen_width'],
             constants['screen_height'],
             position=position,
             type='main')

        key = terminal.read()
        action = input_handlers.handle_menu_keys(key)

        menupos = action.get('menupos')
        select = action.get('select')
        ex = action.get('exit')
        resize = action.get('resize')

        if ex:
            break
        elif menupos:
            position += menupos
            if position < 0:
                position = 0
            if position >= len(options) - 1:
                position = len(options) - 1
        elif select:
            if position == 0:
                player, entities, game_map, message_log, game_state = initialize_new_game.get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN
                play_game(player, entities, game_map, message_log, game_state,
                          constants)
            elif position == 1:  # load last game
                try:
                    player, entities, game_map, message_log, game_state = data_loaders.load_game(
                    )
                    play_game(player, entities, game_map, message_log,
                              game_state, constants)
                except FileNotFoundError:
                    message_box('No save game to load', 50,
                                constants['screen_width'],
                                constants['screen_height'])
                    play_game(player, entities, game_map, message_log,
                              game_state, constants)
            elif position == 2:  # quit
                break
        elif resize:
            print(size)
            if size == '8':
                size = '12'
            elif size == '12:':
                size = '16'
            elif size == '16':
                size = '8'
                terminal.set("font: fonts\courbd.ttf, size=" + size)
示例#15
0
def main():
    constants = get_constants()

    libtcod.console_set_custom_font('tennisOut.png',
                                    libtcod.FONT_LAYOUT_ASCII_INROW, 32, 10)
    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'], False)
    load_customfont()
    con = libtcod.console.Console(constants['screen_width'],
                                  constants['screen_height'])
    panel = libtcod.console.Console(constants['screen_width'],
                                    constants['panel_height'])

    show_main_menu = True
    show_load_error_message = False

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:

            main_menu(con, constants['screen_width'],
                      constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)
            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    play_game(player, entities, game_map, message_log, con,
                              panel, constants)
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)

            character_selection(constants, con, panel)

            show_main_menu = True
示例#16
0
def main():
    # game "constants" / "globals" setup
    debug_f = True
    omnivision = False
    constants = get_constants()

    # initial game state
    game_state = GameStates.MAIN_MENU
    show_load_error_message = False

    # input handling setup
    in_handle = InputHandler()
    mouse_x = 0
    mouse_y = 0

    # set tcod font
    tcod.console_set_custom_font(
            "arial10x10.png",
            tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD
            )

    # set up ui elements
    panel_ui = tcod.console.Console(constants["panel_ui_width"],
                                    constants["panel_ui_height"])
    panel_map = tcod.console.Console(constants["panel_map_width"],
                                     constants["panel_map_height"])
    main_menu_bg = tcod.image_load("menu_background1.png")

    # open tcod console context
    with tcod.console_init_root(
            constants["screen_width"], constants["screen_height"],
            constants["window_title"], fullscreen=False,
            renderer=tcod.RENDERER_SDL2, vsync=False) as root_console:

        while True:
            if game_state == GameStates.MAIN_MENU:
                in_handle.set_game_state(game_state)
                main_menu(root_console, main_menu_bg,
                          constants["screen_width"],
                          constants["screen_height"])

                if show_load_error_message:
                    message_box(root_console, "No save game to load", 50,
                                constants["screen_width"],
                                constants["screen_height"])

                tcod.console_flush()

                for event in tcod.event.get():
                    in_handle.dispatch(event)

                user_in = in_handle.get_user_input()

                want_exit = user_in.get("exit")
                new_game = user_in.get("new_game")
                load_save = user_in.get("load_game")

                if (show_load_error_message
                        and (new_game or load_save or want_exit)):
                    show_load_error_message = False
                elif want_exit:
                    return
                elif new_game:
                    # set up game "runtime global" variables from scratch
                    g_var = get_game_variables(constants, root_console,
                                               panel_map, debug_f)
                    (player, entities, controlled_entity, curr_entity,
                     game_state, prev_state, message_log, game_map, timeq,
                     next_turn, render_update, targeting_item) = g_var
                elif load_save:
                    # load game "runtime global" variables from save file
                    try:
                        g_var = load_game(constants)
                    except FileNotFoundError:
                        show_load_error_message = True

                    if not show_load_error_message:
                        (player, entities, controlled_entity, curr_entity,
                         game_state, prev_state, message_log, game_map, timeq,
                         next_turn, render_update, targeting_item) = g_var
                    else:
                        game_state = GameStates.MAIN_MENU

            else:
                play_game(constants, root_console, panel_ui, panel_map, debug_f,
                          omnivision, in_handle, mouse_x, mouse_y,
                          player, entities, controlled_entity, curr_entity,
                          game_state, prev_state, message_log, game_map, timeq,
                          next_turn, render_update, targeting_item)
                game_state = GameStates.MAIN_MENU
示例#17
0
def main():
    constants = get_constants()
    tc.console_set_custom_font('arial10x10.png',
                               tc.FONT_TYPE_GREYSCALE | tc.FONT_LAYOUT_TCOD)
    tc.console.Console(constants['screen_width'], constants['screen_height'])
    tc.console_init_root(constants['screen_width'], constants['screen_height'],
                         constants['window_title'], False, tc.RENDERER_SDL2,
                         "F", True)

    con = tc.console.Console(constants['screen_width'],
                             constants['screen_height'])
    panel = tc.console.Console(constants['screen_width'],
                               constants['screen_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    # main_menu_background_image = tc.image_load('menu_background.png')
    main_menu_background_image = tc.image_load('')

    key = tc.Key()
    mouse = tc.Mouse()

    event = tc.event.get()

    # for event in tcod.event.wait():
    while event != "QUIT":
        tc.sys_check_for_event(tc.EVENT_KEY_PRESS | tc.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            con.clear()
            clear_all(con, entities)
            tc.console_blit(con, 0, 0, constants['screen_width'],
                            constants['screen_height'], 0, 0, 0, 1.0, 1.0)
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            tc.console_flush()
            action = handle_main_menu(key)
            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False

            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                show_main_menu = False
                #REVERT BEFORE COMMIT
                # game_state = GameStates.SHOW_TUTORIAL
                game_state = GameStates.PLAYERS_TURN

            elif load_saved_game:

                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False

                except FileNotFoundError:
                    show_load_error_message = True

            elif exit_game:
                break

        else:
            con.clear()
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)
            show_main_menu = True
示例#18
0
def main():
    constants = get_constants()

    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GRAYSCALE | libtcod.FONT_LAYOUT_TCOD)
    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'],
                              fullscreen=False,
                              renderer=libtcod.RENDERER_SDL2,
                              vsync=False)

    con = libtcod.console.Console(constants['screen_width'],
                                  constants['screen_height'])
    panel = libtcod.console.Console(constants['screen_width'],
                                    constants['panel_height'])

    player = None
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                # This a terrible hack and doing this the "right" way will require tinkering with the render functions
                message_box(con, 'No save game to load', 20,
                            constants['screen_width'],
                            constants['screen_height'] // 2)

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN
                show_main_menu = False
            elif load_saved_game:
                try:
                    player, game_map, message_log, game_state = load_game()
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            con.clear(fg=(191, 0, 0))
            play_game(player, game_map, message_log, game_state, con, panel,
                      constants)
            show_main_menu = True
示例#19
0
def main():

    arial_font_path = app_path('assets', 'images', 'arial10x10.png')

    libtcod.console_set_custom_font(
        arial_font_path,
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(Constants.screen_width,
                              Constants.screen_height,
                              Constants.window_title,
                              False,
                              libtcod.RENDERER_SDL2,
                              vsync=False)

    con = libtcod.console.Console(Constants.screen_width,
                                  Constants.screen_height)
    panel = libtcod.console.Console(Constants.screen_width,
                                    Constants.panel_height)

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    bg_path = app_path('assets', 'images', 'menu_fire_background.png')
    main_menu_background_image = libtcod.image_load(bg_path)

    while True:
        key_event = None
        for event in libtcod.event.get():
            if event.type in ("QUIT"):
                print("QUIT event: Exiting")
                raise SystemExit()
            if event.type == "KEYDOWN":
                if event.sym == libtcod.event.K_ESCAPE:
                    print(f"{event.type} K_ESCAPE: Exiting")
                    raise SystemExit()
                else:
                    key_event = event
                #print(f"Got Event: {event.type}: {key_event}")

        if show_main_menu:
            main_menu(con, main_menu_background_image, Constants.screen_width,
                      Constants.screen_height)

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            Constants.screen_width, Constants.screen_height)

            libtcod.console_flush()

            action = handle_main_menu(key_event)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')
            fullscreen = action.get('fullscreen')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    Constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

            if fullscreen:
                libtcod.console_set_fullscreen(
                    not libtcod.console_is_fullscreen())

        else:
            con.clear()
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, Constants)

            show_main_menu = True
示例#20
0
def main():
	constants = get_constants()
	libtcod.console_set_custom_font('images/simplerl_12x12.png',
									libtcod.FONT_LAYOUT_ASCII_INROW | libtcod.FONT_TYPE_GREYSCALE)
	libtcod.console_init_root(constants['screen_width'], constants['screen_height'],
							constants['window_title'], False, libtcod.RENDERER_SDL2, 'F', True)

	con = libtcod.console.Console(constants['screen_width'], constants['screen_height'])
	panel = libtcod.console.Console(constants['screen_width'], constants['panel_height'])

	player = None
	entities = []
	game_map = None
	message_log = None
	game_state = None
	show_main_menu = True
	show_load_error_message = False

	main_menu_background_image = libtcod.image_load('images/menu_background1.png')

	in_handle = InputHandler()
# main game loop
	while True:
		if show_main_menu:
			main_menu(con, main_menu_background_image,
					constants['screen_width'], constants['screen_height'])

			if show_load_error_message:
				message_box(con, 'No save game to load', 50,
							constants['screen_width'], constants['screen_height'])

			libtcod.console_flush()
			game_state = GameStates.MAIN_MENU
			in_handle.set_game_state(game_state)
			for event in tcod.event.get():
				in_handle.dispatch(event)
			action = in_handle.get_action()
			new_game = action.get('new_game')
			load_saved_game = action.get('load_game')
			exit_game = action.get('exit')

			if show_load_error_message and (new_game or load_saved_game or exit_game):
				show_load_error_message = False

			elif new_game:
				player, entities, game_map, message_log, game_state = get_game_variables(constants)
				game_state = GameStates.PLAYERS_TURN

				show_main_menu = False
			elif load_saved_game:
				try:
					player, entities, game_map, message_log, game_state = load_game()
					show_main_menu = False
				except FileNotFoundError:
					show_load_error_message = True
			elif exit_game:
				break

		else:
			con.clear(fg=[63, 127, 63])
			play_game(player, entities, game_map, message_log, game_state, con, panel, constants)

			show_main_menu = True
示例#21
0
def main():
    """
    L'une des deux fonctions principales du jeu, elle est appelée une seule et unique fois : au démarrage du jeu.
    Elle a la charge de gérer le choix d'affichage des menus et les réactions aux inputs du joueur.
    Lorsque le joueur quitte un menu pour retourner en jeu, elle appelle la deuxième fonction de ce module : play_game

    Parametres:
    ----------
    Aucun

    Renvoi:
    -------
    Aucun

    """
    # Initialise le jeu en commencant par afficher le menu principal
    constants = get_constants()
    # The font has 32 chars in a row, and there's a total of 10 rows. Increase the "10" when you add new rows to the sample font file
    libtcod.console_set_custom_font('textures.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 10)
    load_customfont()

    libtcod.console_init_root(constants['screen_width'], constants['screen_height'], "Rogue doesn't like", False)

    con = libtcod.console_new(constants['screen_width'], constants['screen_height'])
    panel = libtcod.console_new(constants['screen_width'], constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False
    show_command_menu = False
    show_scores = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    play_bg_music = False
    bg_music = sm.choose_sound(constants.get('sound').get('background_music'))

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    score = (1, 0)

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)
        # Si le menu principal est affiche :
        if show_main_menu:
            main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height'])
            if show_load_error_message:
                message_box(con, 'Rien a charger', 70, constants['screen_width'], constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')
            sound = action.get('sound')
            command = action.get('command')
            back_to_game = action.get('back_to_game')
            scores = action.get('scores')

            if show_load_error_message and (new_game or load_saved_game or exit_game):
                show_load_error_message = False
            # Cree une nouvelle partie
            elif new_game:
                if score != (1, 0):
                    save_score(score)
                player, entities, game_map, message_log, game_state = get_game_variables(constants)
                game_state = GameStates.PLAYERS_TURN
                show_main_menu = False
            # Charge une partie existante, si possible
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state, score = load_game()
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                if score != (1, 0):
                    save_game(player, entities, game_map, message_log, game_state, score)
                sm.close_sound()
                break
            # Lit ou arrete la musique de fond
            elif sound:
                play_bg_music = not play_bg_music
                bg_music.playpause()
            elif command:
                show_command_menu = True
                show_main_menu = False
            elif back_to_game and show_main_menu and game_state != GameStates.PLAYER_DEAD:
                show_main_menu = False
            elif scores:
                show_main_menu = False
                show_scores = True

        # Affiche le menu des commandes
        elif show_command_menu:
            action = handle_main_menu(key)
            command_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height'])
            libtcod.console_flush()
            back_to_game = action.get('back_to_game')
            if back_to_game:
                show_main_menu = True
                show_command_menu = False
                libtcod.console_clear(con)

        # Affiche les trois meilleurs scores et le dernier
        elif show_scores:
            action = handle_main_menu(key)
            scores_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height'])
            libtcod.console_flush()
            back_to_game = action.get('back_to_game')
            if back_to_game:
                show_main_menu = True
                show_scores = False
                libtcod.console_clear(con)

        # Lance une partie
        else:
            libtcod.console_clear(con)
            player, entities, game_map, message_log, game_state, bg_music, play_bg_music, score = play_game(player, entities, game_map, message_log, game_state, con, panel, constants, bg_music, play_bg_music, score)
            if game_state == GameStates.PLAYER_DEAD:
                show_scores = True
            else:
                show_main_menu = True
示例#22
0
def main():
    constants = get_constants()

    libtcod.sys_set_fps(30)

    # Animate
    anim_time = libtcod.sys_elapsed_milli()
    anim_frame = 0

    libtcod.console_set_custom_font(
        'sprite-font.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD, 32, 48)
    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'], False)
    libtcod.console_set_default_background(0, colors.get('dark'))

    load_customfont()

    con = libtcod.console_new(constants['map_width'] * 3,
                              constants['map_height'] * 2)
    panel = libtcod.console_new(constants['panel_width'],
                                constants['screen_height'])
    tooltip = libtcod.console_new(constants['screen_width'], 1)
    messages_pane = libtcod.console_new(constants['message_width'], 1000)
    inventory_pane = libtcod.console_new(constants['message_width'], 40)

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image_0 = libtcod.image_load('menu_background_0.png')
    main_menu_background_image_1 = libtcod.image_load('menu_background_1.png')
    main_menu_background_image_2 = libtcod.image_load('menu_background_2.png')
    main_menu_background_image_3 = libtcod.image_load('menu_background_3.png')

    log_scroll = 0
    inv_scroll = 0

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():

        anim_frame, anim_time = animation(anim_frame, anim_time)

        if anim_frame == 0:
            main_menu_background_image = main_menu_background_image_0
        elif anim_frame == 1:
            main_menu_background_image = main_menu_background_image_1
        elif anim_frame == 2:
            main_menu_background_image = main_menu_background_image_2
        else:
            main_menu_background_image = main_menu_background_image_3

        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'],
                      constants['window_title'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            cam_x, cam_y = update_cam(player, constants)

            log_height, inv_height = update_panels_heights(
                player, constants['panel_height'])
            log_scroll = 0
            inv_scroll = 0
            inv_selected = 0

            play_game(player, entities, game_map, message_log, con, panel,
                      tooltip, messages_pane, inventory_pane, constants, cam_x,
                      cam_y, anim_frame, anim_time, log_scroll, log_height,
                      inv_scroll, inv_height, inv_selected)

            show_main_menu = True
示例#23
0
def main():
    constants = get_constants()

    # tell libtcod which font to use; dictate the file to read from, and the other two arguments tell libtcod which
    # type of file is being read
    libtcod.console_set_custom_font(
        'arial10x10.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    # create the screen with specified width and height; title; boolean value to say full screen or not
    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              'libtcod tutorial revised', False)

    con = libtcod.console_new(constants['screen_width'],
                              constants['screen_height'])

    # create a new console to hold the HP bar and message log
    panel = libtcod.console_new(constants['screen_width'],
                                constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()
            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)

            show_main_menu = True
示例#24
0
def main():
    # Initialises, returns and stores a dictionary of all constant values.
    constants = get_constants()
    # Sets the font.
    libtcod.console_set_custom_font(
        "arial10x10.png",
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
    # Sets up the root console.
    libtcod.console_init_root(constants["screen_width"],
                              constants["screen_height"],
                              constants["window_title"], False)
    # Creates the main off-screen console.
    con = libtcod.console_new(constants["screen_width"],
                              constants["screen_height"])
    # Creates the hp bar/log panel.
    panel = libtcod.console_new(constants["screen_width"],
                                constants["panel_height"])

    # Will store the game variables.
    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    # Grabs an image from the project directory - it will be used for the main menu background.
    main_menu_background_image = libtcod.image_load("menu_background.png")

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        # Creates the main menu and blits it to the console.
        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants["screen_width"], constants["screen_height"])

            if show_load_error_message:
                message_box(con, "No save game found", 50,
                            constants["screen_width"],
                            constants["screen_height"])

            libtcod.console_flush()

            # Handles key presses.
            action = handle_main_menu(key)

            new_game = action.get("new_game")
            load_saved_game = action.get("load_game")
            exit_game = action.get("exit")

            # If the error message is open pressing one of the menu options will close the window.
            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            # If new game is selected get_game_variables() will be called for a the default setup.
            # And the default PLAYERS_TURN gamestate will be set.
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            # Loads the game using load_game().
            elif load_saved_game:
                # Catching the possible FileNotFoundError in load_game().
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    # Shows a message_box if the file cannot be loaded.
                    show_load_error_message = True
            # Exits the game by breaking the while loop.
            elif exit_game:
                break

        # If show_main_menu is False the player_game function will be called using the newly obtained game variables.
        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)

            # This is set back to True when the play_game() is finished (the user presses ESC or exits).
            # Brings the user back to the main menu.
            show_main_menu = True

    # Sets up the game variables using the constants and returns each to a stored variable.
    # E.g. sets up the player entity.
    player, entities, game_map, message_log, game_state = get_game_variables(
        constants)
示例#25
0
文件: engine.py 项目: nebiont/rogue
def main():
	#define main variables
	constants = get_constants()
	
	# Limit FPS to 100 so we dont kill CPUs
	libtcod.sys_set_fps(60)

	# Load font and create root console (what you see)
	libtcod.console_set_custom_font(os.path.join(definitions.ROOT_DIR,'Nice_curses_12x12.png'), libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW)
	libtcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False)

	# Create game area and info area, this will be drawn to our root console so that we can see them
	con = libtcod.console_new(constants['screen_width'], constants['screen_height'])
	panel = libtcod.console_new(constants['screen_width'], constants['panel_height'])

	player = get_dummy_player(Warrior())
	entities = []
	game_map = None
	message_log: MessageLog  = None
	game_state = None

	show_main_menu = True
	show_game = False
	show_load_error_message = False

	main_menu_background_image = libtcod.image_load(os.path.join(definitions.ROOT_DIR,'data','menu_background.png'))

	# Capture keyboard and mouse input
	key = libtcod.Key()
	mouse = libtcod.Mouse()


	mixer.init()
	mixer.music.load(os.path.join(definitions.ROOT_DIR, 'data', 'music', 'title.mp3'))
	#mixer.music.play(loops=-1)
	#Our main loop
	while not libtcod.console_is_window_closed():
		# Check for input
		libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)
		
		
		
		if show_main_menu:

			main_menu(con, main_menu_background_image, constants['screen_width'], constants['screen_height'])

			if show_load_error_message:
				message_box(con, 'No save game to load', 50, constants['screen_width'], constants['screen_height'])

			libtcod.console_flush()

			
			action = handle_main_menu(key)

			new_game = action.get('new_game')
			load_saved_game = action.get('load_game')
			exit_game = action.get('exit')

			if show_load_error_message and (new_game or load_saved_game or exit_game):
				show_load_error_message = False
			elif new_game:
				show_main_menu = False
				show_game = True
			
			elif load_saved_game:
				try:
					player, entities, game_map, message_log, game_state = load_game()
					show_main_menu = False
				except FileNotFoundError:
					show_load_error_message = True
			
			elif exit_game:
				break

		elif show_game == True:
			action = handle_role_select(key)
			warrior = action.get('warrior')
			ranger = action.get('ranger')
			rogue = action.get('rogue')
			paladin = action.get('paladin')
			warlock = action.get('warlock')
			back = action.get('exit')
			accept = action.get('accept')
			libtcod.console_clear(0)
			role_menu(con,constants['screen_width'],constants['screen_height'], player.role)
			libtcod.console_flush()

			if warrior:
				player = get_dummy_player(Warrior())
				role_menu(con,constants['screen_width'],constants['screen_height'], player.role)
				libtcod.console_flush()
			if ranger:
				player = get_dummy_player(Ranger())
				role_menu(con,constants['screen_width'],constants['screen_height'], player.role)
				libtcod.console_flush()
			if rogue:
				player = get_dummy_player(Rogue())
				role_menu(con,constants['screen_width'],constants['screen_height'], player.role)
				libtcod.console_flush()
			if paladin:
				player = get_dummy_player(Paladin())
				role_menu(con,constants['screen_width'],constants['screen_height'], player.role)
				libtcod.console_flush()
			if warlock:
				player = get_dummy_player(Warlock())
				role_menu(con,constants['screen_width'],constants['screen_height'], player.role)
				libtcod.console_flush()
			if accept:
				player, entities, game_map, message_log, game_state = get_game_variables(constants, player)
				show_game = False
			if back:
				show_main_menu = True

		else:
			libtcod.console_clear(con)
			game_state = GameStates.PLAYERS_TURN
			play_game(player, entities, game_map, message_log, game_state, con, panel, constants)

			show_main_menu = True
示例#26
0
def main():
    '''
    Loads and initializes all it needs. Starts game
    '''
    constants = get_constants()

    # uses custom font image
    libtcod.console_set_custom_font("./art/terminal8x8_gs_ro.png",
        libtcod.FONT_LAYOUT_ASCII_INROW)
    libtcod.console_init_root(constants['screen_width'], constants['screen_height'],
        constants['window_title'], False)

    con = libtcod.console_new(constants['screen_width'], constants['screen_height'])
    panel = libtcod.console_new(constants['screen_width'], constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    # uses custom background image
    main_menu_background_image = libtcod.image_load('./art/background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE,
            key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image, constants['screen_width'],
                constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50, constants['screen_width'],
                    constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            rules_menu = action.get('rules_menu')
            exit_game = action.get('exit')
            fullscreen = action.get('fullscreen')

            # toggle fullscreen
            if fullscreen:
                libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())

            if show_load_error_message and (new_game or load_saved_game or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = \
                    get_game_variables(constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game()
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif rules_menu:
                show_rules()
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                panel, constants)

            show_main_menu = True
示例#27
0
def main():
    """Main function of roguelike game engine."""
    constants = get_constants()

    libtcod.console_set_custom_font('arial10x10.png',
                                    libtcod.FONT_TYPE_GREYSCALE |
                                    libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(
        constants['screen_width'], constants['screen_height'],
        constants['window_title'], False)

    con = libtcod.console_new(
        constants['screen_width'], constants['screen_height'])
    panel = libtcod.console_new(
        constants['screen_width'], constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background1.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(
                    con, 'No save game to load', 50,
                    constants['screen_width'], constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or
                                            load_saved_game or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game()
                    # if player dead, resurrect with half max hitpoints
                    if game_state == GameStates.PLAYER_DEAD:
                        player.char = '@'
                        player.color = libtcod.white
                        player.fighter.heal(player.fighter.max_hp // 2)
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants)

            show_main_menu = True
示例#28
0
def main():

    arial_font_path = app_path('assets', 'images', 'arial10x10.png')

    libtcod.console_set_custom_font(
        arial_font_path,
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)

    libtcod.console_init_root(Constants.screen_width, Constants.screen_height,
                              'Rogue Possession', False)

    con = libtcod.console_new(Constants.screen_width, Constants.screen_height)
    panel = libtcod.console_new(Constants.screen_width, Constants.panel_height)

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    bg_path = app_path('assets', 'images', 'menu_fire_background.png')
    main_menu_background_image = libtcod.image_load(bg_path)

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image, Constants.screen_width,
                      Constants.screen_height)

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            Constants.screen_width, Constants.screen_height)

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                player, entities, game_map, message_log, game_state = get_game_variables(
                    Constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True
            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, Constants)

            show_main_menu = True
示例#29
0
def main():
    constants = get_constants()

    player = None
    entities = []
    game_map = None
    message_log = []
    game_state = None
    animator = None

    tcod.console_set_custom_font("Codepage-437.png", tcod.FONT_LAYOUT_CP437)

    tileset = tcod.tileset.load_tilesheet("Codepage-437.png", 16, 16,
                                          tcod.tileset.CHARMAP_CP437)

    panel = tcod.console.Console(constants['screen_width'],
                                 constants['panel_height'])

    show_main_menu = True
    show_load_error_message = False

    with tcod.console_init_root(w=constants['screen_width'],
                                h=constants['screen_height'],
                                title=constants['window_title'],
                                order="F",
                                vsync=True) as root_console:
        while True:
            if show_main_menu:
                main_menu(root_console, constants['screen_width'],
                          constants['screen_height'])
                tcod.console_flush()

                if show_load_error_message:
                    message_box(root_console, 'No save game to load', 50,
                                constants['screen_width'],
                                constants['screen_height'])

                # Handle Events
                for event in tcod.event.wait():
                    if event.type == "KEYDOWN":
                        action: [Action,
                                 None] = handle_keys_main_menu(event.sym)
                        if action:
                            action_type: ActionType = action.action_type

                            show_load_error_message = False

                            if action_type == ActionType.NEW_GAME:
                                player, entities, animator, turn_count, game_map, message_log, game_state = get_game_variables(
                                    constants)
                                show_main_menu = False
                            elif action_type == ActionType.LOAD_GAME:
                                try:
                                    player, entities, animator, turn_count, game_map, message_log, game_state = load_game(
                                    )
                                    show_main_menu = False
                                except FileNotFoundError:
                                    show_load_error_message = True
                                    show_main_menu = True
                            elif action_type == ActionType.ESCAPE:
                                raise SystemExit()
                    if event.type == "QUIT":
                        raise SystemExit()
            else:
                play_game(root_console, player, entities, animator, turn_count,
                          game_map, message_log, game_state, panel, constants)
示例#30
0
def main():

    constants = get_constants()
    names_list = get_unidentified_names()
    colors_list = get_render_colors()
    load_customfont()

    libtcod.console_set_custom_font(
        'fontplus.png',
        libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW, 16, 30)

    libtcod.console_init_root(constants['screen_width'],
                              constants['screen_height'],
                              constants['window_title'], False)

    con = libtcod.console.Console(constants['screen_width'],
                                  constants['screen_height'])
    panel = libtcod.console.Console(constants['screen_width'],
                                    constants['panel_height'])

    player = None
    entities = []
    game_map = None
    message_log = None
    game_state = None

    show_main_menu = True
    show_load_error_message = False

    main_menu_background_image = libtcod.image_load('menu_background.png')

    key = libtcod.Key()
    mouse = libtcod.Mouse()

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(
            libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

        if show_main_menu:
            main_menu(con, main_menu_background_image,
                      constants['screen_width'], constants['screen_height'])

            if show_load_error_message:
                message_box(con, 'No save game to load', 50,
                            constants['screen_width'],
                            constants['screen_height'])

            libtcod.console_flush()

            action = handle_main_menu(key)

            new_game = action.get('new_game')
            load_saved_game = action.get('load_game')
            exit_game = action.get('exit')

            if show_load_error_message and (new_game or load_saved_game
                                            or exit_game):
                show_load_error_message = False
            elif new_game:
                constants = get_constants()
                names_list = get_unidentified_names()
                colors_list = get_render_colors()

                if intro(constants):
                    if not game_options(constants) == "nah":
                        if not origin_options(constants) == "nah":
                            if not character_name(constants) == 'nah':
                                player, entities, game_map, message_log, game_state = get_game_variables(
                                    constants, names_list, colors_list)
                                game_state = GameStates.PLAYERS_TURN

                                show_main_menu = False
            elif load_saved_game:
                try:
                    player, entities, game_map, message_log, game_state, constants = load_game(
                    )
                    show_main_menu = False
                except FileNotFoundError:
                    show_load_error_message = True

            elif exit_game:
                break

        else:
            libtcod.console_clear(con)
            play_game(player, entities, game_map, message_log, game_state, con,
                      panel, constants, names_list, colors_list)

            show_main_menu = True