How to use the tcod.event function in tcod

To help you get started, we’ve selected a few tcod examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github libtcod / python-tcod / examples / eventget.py View on Github external
WIDTH, HEIGHT, sdl_window_flags=FLAGS
    ) as context:
        console = tcod.Console(*context.recommended_console_size())
        while True:
            # Display all event items.
            console.clear()
            console.print(0, console.height - 1, motion_desc)
            for i, item in enumerate(event_log[::-1]):
                y = console.height - 3 - i
                if y < 0:
                    break
                console.print(0, y, item)
            context.present(console, integer_scaling=True)

            # Handle events.
            for event in tcod.event.wait():
                context.convert_event(event)  # Set tile coordinates for event.
                print(repr(event))
                if event.type == "QUIT":
                    raise SystemExit()
                if event.type == "WINDOWRESIZED":
                    console = tcod.Console(
                        *context.recommended_console_size()
                    )
                if event.type == "MOUSEMOTION":
                    motion_desc = str(event)
                else:
                    event_log.append(str(event))
github theoldestnoob / 2019-roguelike-tutorial / input_handlers.py View on Github external
self.state = state


normal_keymap_nomod = {
        tcod.event.K_UP: {"move": (0, -1)},
        tcod.event.K_DOWN: {"move": (0, 1)},
        tcod.event.K_LEFT: {"move": (-1, 0)},
        tcod.event.K_RIGHT: {"move": (1, 0)},
        tcod.event.K_k: {"move": (0, -1)},
        tcod.event.K_j: {"move": (0, 1)},
        tcod.event.K_h: {"move": (-1, 0)},
        tcod.event.K_l: {"move": (1, 0)},
        tcod.event.K_y: {"move": (-1, -1)},
        tcod.event.K_u: {"move": (1, -1)},
        tcod.event.K_b: {"move": (-1, 1)},
        tcod.event.K_n: {"move": (1, 1)},
        tcod.event.K_KP_8: {"move": (0, -1)},
        tcod.event.K_KP_2: {"move": (0, 1)},
        tcod.event.K_KP_4: {"move": (-1, 0)},
        tcod.event.K_KP_6: {"move": (1, 0)},
        tcod.event.K_KP_7: {"move": (-1, -1)},
        tcod.event.K_KP_9: {"move": (1, -1)},
        tcod.event.K_KP_1: {"move": (-1, 1)},
        tcod.event.K_KP_3: {"move": (1, 1)},
        tcod.event.K_KP_5: {"wait": True},
        tcod.event.K_PERIOD: {"wait": True},
        tcod.event.K_p: {"possess": True},
        tcod.event.K_g: {"pickup": True},
        tcod.event.K_i: {"show_inventory": True},
        tcod.event.K_d: {"drop_inventory": True},
        tcod.event.K_q: {"msg_up": True},
        tcod.event.K_a: {"msg_down": True},
github theoldestnoob / 2019-roguelike-tutorial / input_handlers.py View on Github external
tcod.event.K_DOWN: {"move": (0, 1)},
        tcod.event.K_LEFT: {"move": (-1, 0)},
        tcod.event.K_RIGHT: {"move": (1, 0)},
        tcod.event.K_k: {"move": (0, -1)},
        tcod.event.K_j: {"move": (0, 1)},
        tcod.event.K_h: {"move": (-1, 0)},
        tcod.event.K_l: {"move": (1, 0)},
        tcod.event.K_y: {"move": (-1, -1)},
        tcod.event.K_u: {"move": (1, -1)},
        tcod.event.K_b: {"move": (-1, 1)},
        tcod.event.K_n: {"move": (1, 1)},
        tcod.event.K_KP_8: {"move": (0, -1)},
        tcod.event.K_KP_2: {"move": (0, 1)},
        tcod.event.K_KP_4: {"move": (-1, 0)},
        tcod.event.K_KP_6: {"move": (1, 0)},
        tcod.event.K_KP_7: {"move": (-1, -1)},
        tcod.event.K_KP_9: {"move": (1, -1)},
        tcod.event.K_KP_1: {"move": (-1, 1)},
        tcod.event.K_KP_3: {"move": (1, 1)},
        tcod.event.K_KP_5: {"wait": True},
        tcod.event.K_PERIOD: {"wait": True},
        tcod.event.K_p: {"possess": True},
        tcod.event.K_g: {"pickup": True},
        tcod.event.K_i: {"show_inventory": True},
        tcod.event.K_d: {"drop_inventory": True},
        tcod.event.K_q: {"msg_up": True},
        tcod.event.K_a: {"msg_down": True},
        tcod.event.K_ESCAPE: {"exit": True},
        tcod.event.K_BACKSPACE: {"test": True}
        }

normal_keymap_lalt = {
github theoldestnoob / 2019-roguelike-tutorial / input_handlers.py View on Github external
tcod.event.K_k: {"move": (0, -1)},
        tcod.event.K_j: {"move": (0, 1)},
        tcod.event.K_h: {"move": (-1, 0)},
        tcod.event.K_l: {"move": (1, 0)},
        tcod.event.K_y: {"move": (-1, -1)},
        tcod.event.K_u: {"move": (1, -1)},
        tcod.event.K_b: {"move": (-1, 1)},
        tcod.event.K_n: {"move": (1, 1)},
        tcod.event.K_KP_8: {"move": (0, -1)},
        tcod.event.K_KP_2: {"move": (0, 1)},
        tcod.event.K_KP_4: {"move": (-1, 0)},
        tcod.event.K_KP_6: {"move": (1, 0)},
        tcod.event.K_KP_7: {"move": (-1, -1)},
        tcod.event.K_KP_9: {"move": (1, -1)},
        tcod.event.K_KP_1: {"move": (-1, 1)},
        tcod.event.K_KP_3: {"move": (1, 1)},
        tcod.event.K_KP_5: {"wait": True},
        tcod.event.K_PERIOD: {"wait": True},
        tcod.event.K_p: {"possess": True},
        tcod.event.K_g: {"pickup": True},
        tcod.event.K_i: {"show_inventory": True},
        tcod.event.K_d: {"drop_inventory": True},
        tcod.event.K_q: {"msg_up": True},
        tcod.event.K_a: {"msg_down": True},
        tcod.event.K_ESCAPE: {"exit": True},
        tcod.event.K_BACKSPACE: {"test": True}
        }

normal_keymap_lalt = {
        tcod.event.K_RETURN: {"fullscreen": True},
        tcod.event.K_v: {"omnivis": True},
        tcod.event.K_c: {"switch_char": True},
github theoldestnoob / 2019-roguelike-tutorial / input_handlers.py View on Github external
def clear_user_input_q(self):
        self._user_in_q.clear()

    def set_game_state(self, state):
        self.state = state


normal_keymap_nomod = {
        tcod.event.K_UP: {"move": (0, -1)},
        tcod.event.K_DOWN: {"move": (0, 1)},
        tcod.event.K_LEFT: {"move": (-1, 0)},
        tcod.event.K_RIGHT: {"move": (1, 0)},
        tcod.event.K_k: {"move": (0, -1)},
        tcod.event.K_j: {"move": (0, 1)},
        tcod.event.K_h: {"move": (-1, 0)},
        tcod.event.K_l: {"move": (1, 0)},
        tcod.event.K_y: {"move": (-1, -1)},
        tcod.event.K_u: {"move": (1, -1)},
        tcod.event.K_b: {"move": (-1, 1)},
        tcod.event.K_n: {"move": (1, 1)},
        tcod.event.K_KP_8: {"move": (0, -1)},
        tcod.event.K_KP_2: {"move": (0, 1)},
        tcod.event.K_KP_4: {"move": (-1, 0)},
        tcod.event.K_KP_6: {"move": (1, 0)},
        tcod.event.K_KP_7: {"move": (-1, -1)},
        tcod.event.K_KP_9: {"move": (1, -1)},
        tcod.event.K_KP_1: {"move": (-1, 1)},
        tcod.event.K_KP_3: {"move": (1, 1)},
        tcod.event.K_KP_5: {"wait": True},
        tcod.event.K_PERIOD: {"wait": True},
        tcod.event.K_p: {"possess": True},
        tcod.event.K_g: {"pickup": True},
github theoldestnoob / 2019-roguelike-tutorial / input_handlers.py View on Github external
return {}

    def clear_user_input_q(self):
        self._user_in_q.clear()

    def set_game_state(self, state):
        self.state = state


normal_keymap_nomod = {
        tcod.event.K_UP: {"move": (0, -1)},
        tcod.event.K_DOWN: {"move": (0, 1)},
        tcod.event.K_LEFT: {"move": (-1, 0)},
        tcod.event.K_RIGHT: {"move": (1, 0)},
        tcod.event.K_k: {"move": (0, -1)},
        tcod.event.K_j: {"move": (0, 1)},
        tcod.event.K_h: {"move": (-1, 0)},
        tcod.event.K_l: {"move": (1, 0)},
        tcod.event.K_y: {"move": (-1, -1)},
        tcod.event.K_u: {"move": (1, -1)},
        tcod.event.K_b: {"move": (-1, 1)},
        tcod.event.K_n: {"move": (1, 1)},
        tcod.event.K_KP_8: {"move": (0, -1)},
        tcod.event.K_KP_2: {"move": (0, 1)},
        tcod.event.K_KP_4: {"move": (-1, 0)},
        tcod.event.K_KP_6: {"move": (1, 0)},
        tcod.event.K_KP_7: {"move": (-1, -1)},
        tcod.event.K_KP_9: {"move": (1, -1)},
        tcod.event.K_KP_1: {"move": (-1, 1)},
        tcod.event.K_KP_3: {"move": (1, 1)},
        tcod.event.K_KP_5: {"wait": True},
        tcod.event.K_PERIOD: {"wait": True},
github hufflazon / roguelikedev2019 / gamemode.py View on Github external
self.player_move(0, 1)
            elif event.sym == tcod.event.K_LEFT or event.sym == tcod.event.K_h:
                self.player_move(-1, 0)
            elif event.sym == tcod.event.K_RIGHT or event.sym == tcod.event.K_l:
                self.player_move(1, 0)
            elif event.sym == tcod.event.K_y:
                self.player_move(-1, -1)
            elif event.sym == tcod.event.K_u:
                self.player_move(1, -1)
            elif event.sym == tcod.event.K_b:
                self.player_move(-1, 1)
            elif event.sym == tcod.event.K_n:
                self.player_move(1, 1)
            
            # Handle player interact
            elif event.sym == tcod.event.K_f:
                self.player_interact()

            # Handle player look
            elif event.sym == tcod.event.K_v:
                self.player_look()
        
            else:
                super().ev_keydown(event)
github hufflazon / roguelikedev2019 / gamemode.py View on Github external
def ev_keydown(self, event):
        if self.state == GameState.PLAYER_TURN:
            # Handle Player Movement
            if event.sym == tcod.event.K_UP or event.sym == tcod.event.K_k:
                self.player_move(0, -1)
            elif event.sym == tcod.event.K_DOWN or event.sym == tcod.event.K_j:
                self.player_move(0, 1)
            elif event.sym == tcod.event.K_LEFT or event.sym == tcod.event.K_h:
                self.player_move(-1, 0)
            elif event.sym == tcod.event.K_RIGHT or event.sym == tcod.event.K_l:
                self.player_move(1, 0)
            elif event.sym == tcod.event.K_y:
                self.player_move(-1, -1)
            elif event.sym == tcod.event.K_u:
                self.player_move(1, -1)
            elif event.sym == tcod.event.K_b:
                self.player_move(-1, 1)
            elif event.sym == tcod.event.K_n:
                self.player_move(1, 1)
            
            # Handle player interact
            elif event.sym == tcod.event.K_f:
                self.player_interact()

            # Handle player look
            elif event.sym == tcod.event.K_v:
                self.player_look()
        
            else:
                super().ev_keydown(event)
github theoldestnoob / 2019-roguelike-tutorial / input_handlers.py View on Github external
inv_show_keymap_lalt = {
        tcod.event.K_RETURN: {"fullscreen": True}
        }

target_keymap_nomod = {
        tcod.event.K_ESCAPE: {"cancel_target": True}
        }

target_keymap_lalt = {
        tcod.event.K_RETURN: {"fullscreen": True}
        }

fail_keymap_nomod = {
        tcod.event.K_q: {"msg_up": True},
        tcod.event.K_a: {"msg_down": True},
        tcod.event.K_i: {"show_inventory": True},
        tcod.event.K_ESCAPE: {"exit": True}
        }

fail_keymap_lalt = {
        tcod.event.K_v: {"omnivis": True},
        tcod.event.K_c: {"switch_char": True},
        tcod.event.K_RETURN: {"fullscreen": True}
        }

menu_keymap_nomod = {
        tcod.event.K_ESCAPE: {"exit": True},
        tcod.event.K_a: {"new_game": True},
        tcod.event.K_b: {"load_game": True},
        tcod.event.K_c: {"exit": True}
        }
github libtcod / python-tcod / examples / samples_tcod.py View on Github external
def handle_events():
    for event in tcod.event.get():
        SAMPLES[cur_sample].dispatch(event)