コード例 #1
0
def main():
    # Sets font to file path, this specifies the chars we are able to use
    libtcod.console_set_custom_font('../font_custom.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW)

    # create the screen
    libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'Map Creator', False, vsync=False)

    # create a console
    con = libtcod.console.Console(SCREEN_WIDTH, SCREEN_HEIGHT)

    # limit fps so the game doesn't take up 100% cpu
    libtcod.sys_set_fps(60)

    # don't show mouse
    libtcod.mouse_show_cursor(False)

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

    # game loop
    while not libtcod.console_is_window_closed():
        # update key and mouse variables for event
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        # draws the JSON map that's defined already
        draw_all_map_objects(con)

        # also draws borders, handles JSON map drawing
        handle_mouse(con, mouse)

        libtcod.console_flush()

        # check for keyboard input
        action = handle_keys(con, key)

        exit_game = action.get('exit')
        fullscreen = action.get('fullscreen')

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

        if exit_game:
            return True
コード例 #2
0
def main():
    tcod.console_set_custom_font(
        DEFAULT_TEXTURES, tcod.FONT_TYPE_GRAYSCALE | tcod.FONT_LAYOUT_TCOD, 16,
        16)
    tcod.console_init_root(WIDTH, HEIGHT, TITLE, fullscreen=FULLSCREEN)

    tcod.console_set_default_foreground(0, DEFAULT_FOREGROUND)
    # game window
    game_window = tcod.console_new(WIDTH, HEIGHT)
    # mouse and key event handlers
    mouse = tcod.Mouse()
    tcod.mouse_show_cursor(True)
    key = tcod.Key()
    tcod.sys_set_fps(30)
    game_map = world_generation.generate_global_map((50, 50))
    render_world(game_window, game_map)
    ENTITIES.append(PLAYER)
    while not tcod.console_is_window_closed():
        tcod.sys_check_for_event(tcod.EVENT_KEY_PRESS, key, mouse)
        tcod.console_set_default_foreground(game_window, DEFAULT_FOREGROUND)

        # start

        render_entities(game_window)
        tcod.console_blit(game_window, 0, 0, WIDTH, HEIGHT, 0, 0, 0)
        tcod.console_flush()
        # clear
        clear_entities(game_window, game_map)
        # key_handling
        mouse_action = mouse_handler(mouse)
        key_action = key_handler(key)
        move = key_action.get("move")
        exit = key_action.get("exit")
        path = mouse_action.get("path")
        wait = key_action.get("wait")

        if move:
            PLAYER.move(move, game_map)
        elif exit:
            return True
        elif path:
            new_path = path_finder.find_path(PLAYER.position, path, game_map)
            PLAYER.set_path(new_path)
        elif wait:
            PLAYER.make_decision(game_map)
コード例 #3
0
def test_mouse(console):
    libtcodpy.mouse_show_cursor(True)
    libtcodpy.mouse_is_cursor_visible()
    mouse = libtcodpy.mouse_get_status()
    repr(mouse)
    libtcodpy.mouse_move(0, 0)
コード例 #4
0
def test_mouse(console):
    libtcodpy.mouse_show_cursor(True)
    libtcodpy.mouse_is_cursor_visible()
    mouse = libtcodpy.mouse_get_status()
    repr(mouse)
    libtcodpy.mouse_move(0, 0)