Exemple #1
0
def main():
    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_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_game = 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_variables(
                    constants)
                game_state = GameStates.PLAYERS_TURN

                show_main_menu = False
            elif load_game:
                try:
                    player, entities, game_map, message_log, game_state = load_existing_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
Exemple #2
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
def main():
    tdl.set_font('terminal.png',
                 columns=16,
                 rows=16,
                 columnFirst=False,
                 greyscale=True)
    constants = get_constants()

    root_console = tdl.init(constants['screen_width'],
                            constants['screen_height'],
                            title=constants['window_title'],
                            renderer="OPENGL")
    con = tdl.Console(constants['map_width'], constants['map_height'])
    panel = tdl.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 = image_load('menu_background.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
Exemple #4
0
def main():
    constants = get_constants()

    '''
    If we want to change "tileset" we can use this, hopefully it works without tho
    # tcod.console_set_custom_font('symbols.png', tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD)
    Or this might be more current:
    # tileset = tcod.tileset.load_tilesheet(
    #    "whatever.png", 32, 8, tcod.tileset.CHARMAP_TCOD,
    # )
    

    tcod.console_init_root(constants['screen_width'], constants['screen_height'], constants['window_title'], False,
                              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'])
    
    while not tcod.console_is_window_closed():
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS | tcod.EVENT_MOUSE, key, mouse)

        render_all(con, panel, entities, player, game_map, message_log,
                   constants['screen_width'],
                   constants['screen_height'], constants['bar_width'], constants['panel_height'],
                   constants['panel_y'], mouse, constants['colors'])

        tcod.console_flush()

        clear_all(con, entities)

        # Input handling block goes here
        action = handle_keys(key)
        mouse_action = handle_mouse(mouse)

        fullscreen = action.get('fullscreen')

        if fullscreen:
            tcod.console_set_fullscreen(not tcod.console_is_fullscreen())
    '''

    # old stuff   ^
    # new attempt v

    entities, game_map, message_log = get_game_variables(constants)

    place_animals(constants, entities, game_map)

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

    tileset = tcod.tileset.load_tilesheet("symbols.png", 32, 8, tcod.tileset.CHARMAP_TCOD)

    console = tcod.Console(constants['screen_width'], constants['screen_height'])
    panel = tcod.Console(constants['panel_height'], constants['panel_y'])
    with tcod.context.new_terminal(constants['screen_width'], constants['screen_height'], tileset=tileset) as context:
        # Main game loop
        while True:
            console.clear(fg=(159, 159, 159))

            render_all(console, panel, entities, game_map, message_log,
                       constants['screen_width'],
                       constants['screen_height'], constants['panel_height'],
                       constants['panel_y'], mouse, constants['colors'])

            context.present(console)

            for event in tcod.event.get():
                context.convert_event(event)  # Sets tile coordinates for mouse events.
                # print(event)  # Print event information to stdout.
                if event.type == "QUIT":
                    raise SystemExit()
            time.sleep(constants["turn_length"])
            for entity in entities:
                if entity.ai:
                    entity.ai.take_turn(game_map, entities)