Example #1
0
def get_input():
    """ Grab the mouse and all the key events from libtcod and {events.post} them. """
    key, mouse = tcod.check_for_event(tcod.event.KEY_PRESS | tcod.event.MOUSE)
    events.post(events.MOUSE, mouse)
    while key.vk != tcod.key.NONE:
        events.post(events.KEY, key)
        key, mouse = tcod.check_for_event(tcod.event.KEY_PRESS)
Example #2
0
def get_input():
    """ Grab the mouse and all the key events from libtcod and {events.post} them. """
    key, mouse = tcod.check_for_event(tcod.event.KEY_PRESS | tcod.event.MOUSE)
    events.post(events.MOUSE, mouse)
    while key.vk != tcod.key.NONE:
        events.post(events.KEY, key)
        key, mouse = tcod.check_for_event(tcod.event.KEY_PRESS)
Example #3
0
def target_tile(player, max_range=None):
    while True:
        tcod.flush()
        key, mouse = tcod.check_for_event()
        render_all(player)

        x, y = (mouse.cx, mouse.cy)
        if mouse.rbutton_pressed or key.vk == tcod.KEY_ESCAPE:
            panel.add_message('Cancelled.', tcod.COLOR_RED)
            return (None, None)
        elif(mouse.lbutton_pressed and player.map.is_visible(x, y) and
             (max_range is None or player.distance(x, y) <= max_range)):
            return (x, y)
Example #4
0
def slow_print(widget, text, y=1):
    label = widgets.Label(parent=widget, y=y, text=text)
    label.center_in_parent(vertical=False)
    label.text = ""

    for char in text:
        label.text = label.text + char

        widget.render()
        tcod.flush() # Relying on the tcod.set_fps_limit() from earlier to limit our render rate
        key, mouse = tcod.check_for_event(tcod.event.KEY_PRESS | tcod.event.MOUSE_PRESS)
        if key.vk != tcod.key.NONE or mouse.lbutton or mouse.rbutton:
            label.text = text
            widget.render()
            return
Example #5
0
def slow_print(widget, text, y=1):
    label = widgets.Label(parent=widget, y=y, text=text)
    label.center_in_parent(vertical=False)
    label.text = ""

    for char in text:
        label.text = label.text + char

        widget.render()
        tcod.flush(
        )  # Relying on the tcod.set_fps_limit() from earlier to limit our render rate
        key, mouse = tcod.check_for_event(tcod.event.KEY_PRESS
                                          | tcod.event.MOUSE_PRESS)
        if key.vk != tcod.key.NONE or mouse.lbutton or mouse.rbutton:
            label.text = text
            widget.render()
            return
Example #6
0
def handle_events(player):
    key, mouse = tcod.check_for_event(libtcod.EVENT_KEY_PRESS|libtcod.EVENT_MOUSE)

    if key.vk == libtcod.KEY_ENTER and key.lalt:
        tcod.set_fullscreen(not tcod.is_fullscreen())
    elif key.vk == libtcod.KEY_ESCAPE or key.c == ord('q'):
        return const.ACTION_EXIT
    elif key.c == ord('N'):
        player.blocks = not player.blocks
        panel.add_message("Noclip set to " + str(not player.blocks), tcod.COLOR_LIGHT_FLAME)
    elif key.c == ord('X'):
        player.map.fullbright = not player.map.fullbright
    elif key.c == ord('D'):
        print panel.messages

    if player.fighter.hp > 0:
        if key.vk == libtcod.KEY_UP or key.vk == libtcod.KEY_KP8:
            player.move(0, -1)
            return const.ACTION_MOVE
        elif key.vk == libtcod.KEY_KP9:
            player.move(1, -1)
            return const.ACTION_MOVE
        elif key.vk == libtcod.KEY_DOWN or key.vk == libtcod.KEY_KP2:
            player.move(0, 1)
            return const.ACTION_MOVE
        elif key.vk == libtcod.KEY_KP1:
            player.move(-1, 1)
            return const.ACTION_MOVE
        elif key.vk == libtcod.KEY_LEFT or key.vk == libtcod.KEY_KP4:
            player.move(-1, 0)
            return const.ACTION_MOVE
        elif key.vk == libtcod.KEY_KP7:
            player.move(-1, -1)
            return const.ACTION_MOVE
        elif key.vk == libtcod.KEY_RIGHT or key.vk == libtcod.KEY_KP6:
            player.move(1, 0)
            return const.ACTION_MOVE
        elif key.vk == libtcod.KEY_KP3:
            player.move(1, 1)
            return const.ACTION_MOVE
        elif key.vk == libtcod.KEY_KP5 or key.c == ord('.'):
            # Wait
            return const.ACTION_MOVE
        elif key.c == ord('g'):
            for e in player.map.entities_at(player.x, player.y):
                if hasattr(e, 'item') and e.item is not None:
                    e.item.pick_up(player)
        elif key.c == ord('u'):
            item = utils.inventory_menu(player)
            if item:
                item.use(player)
        elif key.c == ord('d'):
            item = utils.inventory_menu(player)
            if item:
                item.drop(player)
        elif key.c == ord('<') or key.c == ord('>'):
            if player.map.stairs.x == player.x and player.map.stairs.y == player.y:
                return const.ACTION_DESCEND_STAIRS
        elif key.c == ord('c'):
            utils.character_sheet(player)

    ents = player.map.entities_at(mouse.cx, mouse.cy, only_visible=True)
    if len(ents) > 0:
        names = ', '.join([e.name for e in ents])
        panel.status(names.capitalize(), tcod.COLOR_LIGHT_GRAY)
    else:
        panel.status('')

    return const.ACTION_NONE