def show_current_map(self): for x in range(game.current_map.map_width): for y in range(game.current_map.map_height): game.current_map.tile[x][y].update({'explored': True}) util.initialize_fov() game.fov_recompute = True game.draw_map = True
def hide_current_map(self): for x in range(game.current_map.map_width): for y in range(game.current_map.map_height): game.current_map.tile[x][y].pop('explored', None) util.initialize_fov() game.fov_recompute = True game.draw_map = True libtcod.console_clear(game.con)
def reset_dungeon_level(self): temp_map = game.current_map game.current_map = mapgen.Map(temp_map.location_name, temp_map.location_abbr, temp_map.location_id, temp_map.location_level, temp_map.threat_level, temp_map.map_width, temp_map.map_height, temp_map.type) game.current_map.overworld_position = temp_map.overworld_position util.initialize_fov() game.fov_recompute = True game.draw_map = True libtcod.console_clear(game.con)
def climb_down_stairs(): location_name = game.current_map.location_name location_abbr = game.current_map.location_abbr location_id = game.current_map.location_id threat_level = game.current_map.threat_level dungeon_type = game.current_map.type map_width = game.DUNGEON_MAP_WIDTH map_height = game.DUNGEON_MAP_HEIGHT op = (0, 0, 0) if game.current_map.tile[game.char.x][game.char.y]['icon'] != '>': game.message.new('You see no stairs going in that direction!', game.turns) else: if game.current_map.location_id > 0: level = game.current_map.location_level + 1 game.message.new('You climb down the stairs.', game.turns) util.store_map(game.current_map) IO.autosave(False) map_width = game.current_map.map_width map_height = game.current_map.map_height dice = util.roll_dice(1, 10) if dice == 10: threat_level += 1 else: level = 1 for (id, name, abbr, x, y, tlevel, dtype) in game.worldmap.dungeons: if y * game.WORLDMAP_WIDTH + x == game.current_map.location_level: location_id = id location_name = name location_abbr = abbr threat_level = tlevel dungeon_type = dtype if dtype == 'Maze': map_width = game.MAP_WIDTH map_height = game.MAP_HEIGHT game.message.new('You enter the ' + location_name + '.', game.turns) util.decombine_maps() op = (game.current_map.location_level, game.char.x, game.char.y) util.store_map(game.current_map) for i in range(len(game.border_maps)): util.store_map(game.border_maps[i]) IO.autosave() util.loadgen_message() game.current_map = util.fetch_map({'name': location_name, 'id': location_id, 'abbr': location_abbr, 'level': level, 'threat': threat_level, 'map_width': map_width, 'map_height': map_height, 'type': dungeon_type}, dir='up') game.current_map.overworld_position = op IO.autosave_current_map() game.current_map.check_player_position() util.initialize_fov() game.fov_recompute = True game.player_move = True
def climb_up_stairs(): combine = False location_name = game.current_map.location_name location_abbr = game.current_map.location_abbr location_id = game.current_map.location_id threat_level = game.current_map.threat_level dungeon_type = game.current_map.type map_width = game.DUNGEON_MAP_WIDTH map_height = game.DUNGEON_MAP_HEIGHT if game.current_map.tile[game.char.x][game.char.y]['icon'] != '<': game.message.new('You see no stairs going in that direction!', game.turns) else: if game.current_map.location_level > 1: level = game.current_map.location_level - 1 game.message.new('You climb up the stairs.', game.turns) else: combine = True (level, game.char.x, game.char.y) = game.current_map.overworld_position location_id = 0 location_name = 'Wilderness' location_abbr = 'WD' game.message.new('You return to the ' + location_name + '.', game.turns) util.store_map(game.current_map) util.loadgen_message() IO.autosave(False) if not combine: game.current_map = util.fetch_map({'name': location_name, 'id': location_id, 'abbr': location_abbr, 'level': level, 'threat': threat_level, 'map_width': map_width, 'map_height': map_height, 'type': dungeon_type}, dir='down') IO.autosave_current_map() else: game.current_map = util.fetch_map({'name': location_name, 'id': location_id, 'abbr': location_abbr, 'level': level, 'map_width': game.current_map.map_width, 'map_height': game.current_map.map_height}) util.fetch_border_maps() IO.autosave_current_map() util.combine_maps() game.current_map.check_player_position() util.initialize_fov() game.fov_recompute = True game.player_move = True
def play_game(self): global wm, player_action, draw_gui, player_move wm = libtcod.console_new(game.WORLDMAP_WIDTH, game.WORLDMAP_HEIGHT) game.worldmap.create_map_legend(wm, 3) libtcod.console_clear(0) util.initialize_fov() player_action = '' while not libtcod.console_is_window_closed(): if draw_gui: util.render_gui(libtcod.Color(70, 80, 90)) util.render_message_panel() util.render_player_stats_panel() draw_gui = False util.render_map() libtcod.console_flush() # player movement if not player.is_disabled() and not ('overburdened' in player.flags and turns % 3 == 0): player_action = commands.keyboard_commands() else: player_move = True if player_action == 'save': IO.save_game() break if player_action == 'quit': death.death_screen(True) break if player_action == 'exit': break # let monsters take their turn if player_move: for obj in reversed(current_map.objects): if game_state != 'death': if obj.item: if obj.item.is_active(): obj.delete() if obj.item.is_expired() or ((turns >= (obj.first_appearance + obj.item.expiration)) and obj.item.expiration > 0): obj.delete() if obj.entity: if not obj.entity.is_disabled(): obj.x, obj.y = obj.entity.take_turn(obj.x, obj.y) if current_map.tile[obj.x][obj.y]['type'] == 'trap' and not obj.entity.is_above_ground() and obj.entity.can_move(obj.x, obj.y): if current_map.tile_is_invisible(obj.x, obj.y): util.trigger_trap(obj.x, obj.y, obj.entity.article.capitalize() + obj.entity.get_name()) elif libtcod.map_is_in_fov(fov_map, obj.x, obj.y): message.new('The ' + obj.entity.get_name() + ' sidestep the ' + current_map.tile[obj.x][obj.y]['name'] + '.', turns) obj.entity.check_condition(obj.x, obj.y) if obj.entity.is_dead(): if libtcod.map_is_in_fov(fov_map, obj.x, obj.y): message.new('The ' + obj.entity.get_name() + ' dies!', turns, libtcod.light_orange) else: message.new('You hear a dying scream.', turns) obj.entity.loot(obj.x, obj.y) obj.delete() if game_state != 'death': monsters.spawn() effects.check_active_effects() util.add_turn() player_move = False # death screen summary if game_state == 'death': key = libtcod.Key() util.render_map() libtcod.console_flush() while not key.vk == libtcod.KEY_SPACE: libtcod.sys_wait_for_event(libtcod.EVENT_KEY_PRESS, key, libtcod.Mouse(), True) death.death_screen() player_action = 'exit' break