def handle_playing_keys(key, state): if key.vk == libtcod.KEY_CHAR: if key.c == ord('k'): Util.player_move_or_attack(state, 0, -1) elif key.c == ord('j'): Util.player_move_or_attack(state, 0, 1) elif key.c == ord('h'): Util.player_move_or_attack(state, -1, 0) elif key.c == ord('l'): Util.player_move_or_attack(state, 1, 0) elif key.c == ord('y'): Util.player_move_or_attack(state, -1, -1) elif key.c == ord('u'): Util.player_move_or_attack(state, 1, -1) elif key.c == ord('b'): Util.player_move_or_attack(state, -1, 1) elif key.c == ord('n'): Util.player_move_or_attack(state, 1, 1) elif key.c == ord('.'): pass elif key.c == ord('v'): Input.look(state) state.set_player_action(Constants.NOT_VALID_KEY) elif key.c == ord('i'): chosen_item = state.player_inventory.inventory_menu( 'Press the key next to an item to use it, or any other to cancel.\n', state) if chosen_item is not None: chosen_item.use(state) # else: # state.set_player_action(Constants.NOT_VALID_KEY) elif key.c == ord('I'): chosen_spell = state.player_spell_inventory.spell_menu( 'Press the key next to a spell to use it, or any other to cancel.\n', state) if chosen_spell is not None: chosen_spell.cast(state, state.player) elif key.c == ord('d'): chosen_item = state.player_inventory.inventory_menu( 'Press the key next to an item to drop it, or any other to cancel.\n', state) if chosen_item is not None: chosen_item.drop(state) elif key.c == ord('g'): # pick up an item for object in state.objects: # look for an item in the player's tile if object.x == state.player.x and object.y == state.player.y and object.item: object.item.pick_up(state) break elif key.c == ord('>'): padded_player_coords = Util.get_padded_coords(state.player.x, state.player.y) if padded_player_coords in state.stairs[state.dungeon_level][MapConstants.DOWN_STAIRS_OBJECT].keys(): state.set_player_action(Constants.NEXT_LEVEL) elif key.c == ord('<'): padded_player_coords = Util.get_padded_coords(state.player.x, state.player.y) if padded_player_coords in state.stairs[state.dungeon_level][MapConstants.UP_STAIRS_OBJECT].keys(): state.set_player_action(Constants.PREVIOUS_LEVEL) elif key.c == ord('c'): # show character information level_up_xp = Constants.LEVEL_UP_BASE + state.player.level * Constants.LEVEL_UP_FACTOR Util.show_character_screen(state, level_up_xp) Util.refresh(state) else: state.set_player_action(Constants.NOT_VALID_KEY)