def new_game(): """ Starts a new game, with a default player on level 1 of the dungeon. Returns the player object. """ # Must initialize the log before we do anything that might emit a message. log.init() fighter_component = Fighter(hp=100, defense=1, power=2, xp=0, death_function=player_death) player = Object(algebra.Location(0, 0), '@', 'player', libtcod.white, blocks=True, fighter=fighter_component) player.inventory = [] player.level = 1 player.game_state = 'playing' # True if there's a (hostile) fighter in FOV player.endangered = False obj = miscellany.dagger() player.inventory.append(obj) actions.equip(player, obj.equipment, False) obj.always_visible = True cartographer.make_map(player, 1) renderer.clear_console() renderer.update_camera(player) log.message('Welcome stranger! Prepare to perish in the Tombs of the Ancient Kings.', libtcod.red) log.message('Press ? or F1 for help.') return player
def next_level(player, portal): """ Advance to the next level (changing player.current_map). Heals the player 50%. Returns the Map of the new level. """ actions.heal(player.fighter, player.fighter.max_hp / 2) old_map = player.current_map generator = portal.generator need_stairs = generator(player, player.current_map.dungeon_level + 1) renderer.clear_console() renderer.update_camera(player) if need_stairs: stairs = Object(player.pos, '>', 'stairs up', libtcod.white, always_visible=True) stairs.destination = old_map stairs.dest_position = portal.pos player.current_map.objects.insert(0, stairs) player.current_map.portals.insert(0, stairs) return player.current_map
def revisit_level(player, portal): """ Return to a level the player has previously visited (changing player.current_map). Does *not* heal the player. """ player.current_map = portal.destination player.pos = portal.dest_position # Call to initialize_fov() should be redundant but in practice seems to have # worked around an intermittent bug. player.current_map.initialize_fov() player.current_map.fov_needs_recompute = True renderer.update_camera(player) renderer.clear_console()
def new_game(): fighter_component = components.Fighter(hp=30, defence=2, power=5, death_function=player_death) player = components.Entity(0, 0, 'player', config.TILE_PLAYER, libtcodpy.white, is_walkable=False, fighter=fighter_component) player.inventory = [] player.inventory_size = 26 player.game_state = 'playing' log.init() log.add_message("You awaken in a vault.") player.current_map = mapmaker.make_map(player) renderer.clear_console() return player
def next_level(player, portal): """ Advance to the next level (changing player.current_map). Heals the player 50%. Returns the Map of the new level. """ log.message('You take a moment to rest, and recover your strength.', libtcod.light_violet) actions.heal(player.fighter, player.fighter.max_hp / 2) log.message('After a rare moment of peace, you descend deeper into the heart of the dungeon...', libtcod.red) old_map = player.current_map cartographer.make_map(player, player.current_map.dungeon_level + 1) renderer.clear_console() renderer.update_camera(player) # Create the up stairs at the current position. stairs = Object(player.pos, '>', 'stairs up', libtcod.white, always_visible=True) stairs.destination = old_map stairs.dest_position = portal.pos player.current_map.objects.insert(0, stairs) player.current_map.portals.insert(0, stairs) return player.current_map