def teleport_anywhere_manual(self): libtcod.console_print(0, game.MAP_X, 1, 'x, y coordinates: ') libtcod.console_flush() choice = game.messages.input('', 0, game.MAP_X + 18, 1) if choice != '': coord = choice.split(',') if int(coord[0]) in range(game.WORLDMAP_WIDTH) and int(coord[1]) in range(game.WORLDMAP_HEIGHT): game.worldmap.player_positionx = int(coord[0]) game.worldmap.player_positiony = int(coord[1]) if game.current_map.location_id > 0: util.loadgen_message() util.store_map(game.current_map) IO.autosave(False) else: util.change_maps((game.worldmap.player_positiony * game.WORLDMAP_WIDTH + game.worldmap.player_positionx)) game.draw_map = True libtcod.console_clear(game.con)
def player_move(dx, dy): #the coordinates the player is moving to/attacking x = game.char.x + dx y = game.char.y + dy #try to find an attackable object there target = None for object in game.current_map.objects: if object.y == y and object.x == x and object.entity: target = object break #attack if target found, move otherwise if target is not None: game.player.attack(target) elif not game.player.can_move(): game.message.new("You can't move!", game.turns) game.player_move = True else: if game.current_map.tile[game.char.x + dx][game.char.y + dy]['name'] == 'door': open_door(dx, dy) elif game.current_map.tile[game.char.x + dx][game.char.y + dy]['name'] == 'locked door': game.message.new('The door is locked!', game.turns) else: game.char.move(dx, dy, game.current_map) if game.current_map.tile[game.char.x][game.char.y]['type'] == 'trap' and not game.player.is_above_ground(): if game.current_map.tile_is_invisible(game.char.x, game.char.y): util.trigger_trap(game.char.x, game.char.y) else: game.message.new('You sidestep the ' + game.current_map.tile[game.char.x][game.char.y]['name'] + '.', game.turns) if game.current_map.tile[game.char.x][game.char.y]['name'] in ['deep water', 'very deep water']: if 'swimming' not in game.player.flags: game.player.flags.append('swimming') stamina_loss = (100 - game.player.skills[game.player.find_skill('Swimming')].level) / 2 if stamina_loss == 0: stamina_loss = 1 game.player.lose_stamina(stamina_loss) if game.player.no_stamina(): game.message.new('You drown!', game.turns, libtcod.light_orange) game.message.new('*** Press space ***', game.turns) game.killer = 'drowning' game.game_state = 'death' else: game.player.skills[game.player.find_skill('Swimming')].gain_xp(2) elif 'swimming' in game.player.flags: game.player.flags.remove('swimming') if game.current_map.location_id == 0: px = game.current_map.map_width / 3 py = game.current_map.map_height / 3 if (game.char.y / py) == 0 or (game.char.x / px) == 0 or (game.char.y / py) == 2 or (game.char.x / px) == 2: game.worldmap.player_positionx += dx game.worldmap.player_positiony += dy if game.worldmap.player_positionx not in range(game.WORLDMAP_WIDTH): game.worldmap.player_positionx = game.WORLDMAP_WIDTH - abs(game.worldmap.player_positionx) if game.worldmap.player_positiony not in range(game.WORLDMAP_HEIGHT): game.worldmap.player_positiony = game.WORLDMAP_HEIGHT - abs(game.worldmap.player_positiony) level = (game.worldmap.player_positiony * game.WORLDMAP_WIDTH) + game.worldmap.player_positionx util.change_maps(level) util.items_at_feet() game.fov_recompute = True