Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
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},
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 = {
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},
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},
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},
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)
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)
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}
}
def handle_events():
for event in tcod.event.get():
SAMPLES[cur_sample].dispatch(event)