Пример #1
0
 def connect_stairs(state, previous_player_coords):
   down_stairs_ids = state.stairs[state.dungeon_level - 1][MapConstants.DOWN_STAIRS_OBJECT].keys()
   up_stairs_ids = state.stairs[state.dungeon_level][MapConstants.UP_STAIRS_OBJECT].keys()
   old_down_stair_id = Util.get_padded_coords(previous_player_coords[0], previous_player_coords[1])
   new_up_stair_id = Util.get_padded_coords(state.player.x, state.player.y)
   MapCreation.connect_two_stairs(state, new_up_stair_id, old_down_stair_id)
   down_stairs_ids.remove(old_down_stair_id)
   up_stairs_ids.remove(new_up_stair_id)
   for down_stair_id in down_stairs_ids:
     up_stairs_id = up_stairs_ids.pop()
     MapCreation.connect_two_stairs(state, up_stairs_id, down_stair_id)
Пример #2
0
 def create_stairs_of_type(state, stairs_coords, type):
   for stair_coords in stairs_coords:
     stairs = Object(stair_coords[0], stair_coords[1], type, MapConstants.STAIRS_NAME, MapConstants.STAIRS_COLOR,
                     always_visible=True)
     state.objects_map[state.dungeon_level].append(stairs)
     stairs.send_to_back(state.objects_map[state.dungeon_level])
     stairs_id = Util.get_padded_coords(stairs.x, stairs.y)
     state.stairs[state.dungeon_level][type][stairs_id] = None
Пример #3
0
 def previous_level(self):
   up_stairs_id = Util.get_padded_coords(self.state.player.x, self.state.player.y)
   down_stairs_id = self.follow_stairs(MapConstants.UP_STAIRS_OBJECT, up_stairs_id, self.state.dungeon_level)
   self.state.dijkstra_map_update = True
   self.state.player.x, self.state.player.y = Util.get_coords_from_padded_coords(down_stairs_id)
   if self.state.dungeon_level == 0:
     self.state.set_player_action(Constants.EXIT)
     return
   else:
     self.state.dungeon_level -= 1
   self.state.objects = self.state.objects_map[self.state.dungeon_level]
   self.state.game_map.set_game_map(self.state.dungeon_level)
   # TODO Make fov_map container class
   self.state.fov_map = self.state.fov_map_map[self.state.dungeon_level]
   self.initialize_fov(self.state.dungeon_level)
   self.state.set_player_action(None)
   self.state.fov_recompute = True
Пример #4
0
 def next_level(self):
   self.state.dijkstra_map_update = True
   self.state.dungeon_level += 1
   self.state.status_panel.message('You take a moment to rest and recover 50% health', libtcod.violet)
   self.state.player.fighter.heal(self.state.player.fighter.max_hp(self.state) / 2, self.state)
   self.state.status_panel.message('and now you descend into the depths of the dungeon', libtcod.red)
   if self.state.dungeon_level in self.state.game_map.complete_game_map:
     self.state.game_map.set_game_map(self.state.dungeon_level)
     down_stairs_id = Util.get_padded_coords(self.state.player.x, self.state.player.y)
     up_stairs_id = self.follow_stairs(MapConstants.DOWN_STAIRS_OBJECT, down_stairs_id, self.state.dungeon_level - 1)
     self.state.player.x, self.state.player.y = Util.get_coords_from_padded_coords(up_stairs_id)
   else:
     self.state.objects_map[self.state.dungeon_level] = [self.state.player]
     self.state.game_map.generate_map(self.state, self.state.dungeon_level)
     self.state.score += self.state.dungeon_level * 10
   self.state.objects = self.state.objects_map[self.state.dungeon_level]
   self.initialize_fov(self.state.dungeon_level)
   self.state.set_player_action(None)
   self.state.fov_recompute = True
   Util.render_all(self.state)
Пример #5
0
 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)